2013-02-12 54 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; 
     } 
    }