1

my application run correctly in all device except nexus 5 ! why? in nexus 5 has error

Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/DCIM/IMG_20160215_061354.jpg: open failed: EACCES (Permission denied)

my code :

 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            mImageCaptureUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
            intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageCaptureUri); // set the image file name
            startActivityForResult(intent, PICK_FROM_CAMERA);

my permisions in manifest file :

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
<!--<uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE"/>-->
<uses-permission android:name="android.permission.READ_MEDIA_STORAGE"/>
<uses-permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE"
    android:maxSdkVersion="18" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<uses-feature
    android:name="android.hardware.camera"
    android:required="true" />

on activity result just show picture in imageview that in nexus 5 is empty

 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
       if (requestCode == PICK_FROM_CAMERA) {
            img.setImageURI(mImageCaptureUri);              
        }
    }
}

copy two function from developer.google

    private static Uri getOutputMediaFileUri(int type) {
    return Uri.fromFile(getOutputMediaFile(type));
}

/**
 * Create a File for saving an image or video
 */
private static File getOutputMediaFile(int type) {
    File mediaStorageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            return null;
        }
    }
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    File mediaFile;
    if (type == MEDIA_TYPE_IMAGE) {
        mediaFile = new File(mediaStorageDir.getPath() + File.separator +
                "IMG_" + timeStamp + ".jpg");
    } else if (type == MEDIA_TYPE_VIDEO) {
        mediaFile = new File(mediaStorageDir.getPath() + File.separator +
                "VID_" + timeStamp + ".mp4");
    } else {
        return null;
    }

    return mediaFile;
}
  • If you are getting image from Google photos check this for doing it http://stackoverflow.com/questions/30527045/choosing-photo-using-new-google-photos-app-is-broken – Wasim K. Memon Feb 15 '16 at 03:17
  • First, you can try with absolute image path (to DCIM folder, can use file explorer app to get path or Root explorer if phone rooted). If try with true (image not null) then you need check your code about get path to read file – GiapLee Feb 15 '16 at 03:19

0 Answers0