2013-02-12 39 views
1

工作,這是我從庫抓取圖像庫的目的不是在Android 4.0.3

intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
intent.setType("image/*"); 
intent.setAction(Intent.ACTION_GET_CONTENT); 
startActivityForResult(intent, GALLERY_INTENT); 

代碼,這是onActivityResult()方法

if(requestCode==2 && resultCode == RESULT_OK){ 

      Uri _uri = data.getData(); 
      if (_uri != null) { 

      //User had pick an image. 
      Cursor cursor = getContentResolver().query(_uri, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null); 
      cursor.moveToFirst(); 

      //Link to the image 
      final String imageFilePath = cursor.getString(0); 
      cursor.close(); 

      Intent intent = new Intent(HomeActivity.this,ConfirmPicture.class); 
      intent.putExtra(INTENT_KEY_FINISH_ACTIVITY_ON_SAVE_COMPLETED, true); 
      intent.putExtra("IMAGE_PATH", imageFilePath); 
      intent.putExtra("OUTLET_ID", 0); 
      intent.putExtra("OUTLET_NAME", "name"); 
      startActivity(intent); 
      } 

該代碼是工作的罰款上的Android 2.3 .4版本,但當我在4.0.3設備上測試此代碼時,它不起作用,可能是什麼問題?

+0

當你說: 「它不工作」 究竟是什麼意思?你能更具體地說明它做了什麼,不做什麼?即拋出異常了嗎?或者它只是不開放畫廊?當您試圖發射意圖時,Logcat中是否有任何消息? – FoamyGuy 2013-02-12 14:23:17

+0

該方法中的imageFilePath通過畫廊意圖爲我提供了正確的圖像路徑,但它並未顯示在ImageView中。在4.0.3版本中。 – 2013-02-13 05:15:52

+0

你有沒有答案,如果是的話請分享我也有同樣的問題 – 2013-03-23 06:35:34

回答

0

我已經解決了這個問題

  Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
      ZootOutObject.objectUri = getImagePath(); 
      intent.putExtra(MediaStore.EXTRA_OUTPUT, ZootOutObject.objectUri); 
      startActivityForResult(intent, CAMERA_INTENT); 

如果(requestCode == 1 & & resultCode爲== RESULT_OK){

   String pathName=Environment.getExternalStorageDirectory()+"/folder_name/image_zootout.jpg"; 

      Intent intent = new Intent(getApplicationContext(),PhotoEditorActivity.class); 
      intent.putExtra("IMAGE_PATH", pathName); 
      intent.putExtra("OUTLET_ID", 0); 
      intent.putExtra("OUTLET_NAME", ""); 
      startActivity(intent); 

     } 


private Uri getImagePath() { 
    // If sd card is available 
     if(android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)){ 
      String path = Environment.getExternalStorageDirectory() .getAbsolutePath(); 
      filename = "image_zootout.jpg"; 
      path += "/folder_name"; 
      File file = new File(path); 
      if (!file.isDirectory()) { 
       file.mkdirs(); 
      } 
      path += "/" + filename; 
      File imageFile = new File(path); 
      if (!imageFile.exists()) { 
       try { 
        imageFile.createNewFile(); 
       } catch (IOException e) { 
        e.printStackTrace(); 
        return null; 
       } 
      } 
      return Uri.fromFile(imageFile); 
     }else{ // If sd card is not available 
      return null; 
     } 
    } 
相關問題