Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

SecurityException crash in picking image #134

Open
raghavkuk25 opened this issue Jun 26, 2015 · 8 comments
Open

SecurityException crash in picking image #134

raghavkuk25 opened this issue Jun 26, 2015 · 8 comments
Labels

Comments

@raghavkuk25
Copy link

Caused by: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.media.MediaDocumentsProvider from ProcessRecord{11ac9422 20472:com.testbook.tbapp/u0a576} (pid=20472, uid=10576) requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS
            at android.os.Parcel.readException(Parcel.java:1540)
            at android.os.Parcel.readException(Parcel.java:1493)
            at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:3283)
            at android.app.ActivityThread.acquireProvider(ActivityThread.java:4621)
            at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2506)
            at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1442)
            at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1064)
            at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:921)
            at android.content.ContentResolver.openInputStream(ContentResolver.java:646)
            at com.soundcloud.android.crop.CropImageActivity.calculateBitmapSampleSize(CropImageActivity.java:147)
            at com.soundcloud.android.crop.CropImageActivity.setupFromIntent(CropImageActivity.java:125)
            at com.soundcloud.android.crop.CropImageActivity.onCreate(CropImageActivity.java:74)
            at android.app.Activity.performCreate(Activity.java:5975)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2376)
            at android.app.ActivityThread.access$800(ActivityThread.java:147)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5253)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
@liemlyquan
Copy link

Did you include the permission in AndroidManifest ? :D

@raghavkuk25
Copy link
Author

I know including the permission will fix this but that is not the point. This used to work earlier. Neither is this mentioned that this permission is required :)

@liemlyquan
Copy link

Yeah, I did not have this permission so far, and it still works fine. Maybe they are some changes in your code ? : D

@raghavkuk25
Copy link
Author

No changes in the code. I just used a different phone. Even in this phone, this happens randomly and not all the time.. It looks like this is the same as #9 but it must not crash.

@clemp6r
Copy link
Contributor

clemp6r commented Jul 17, 2015

I have a similar problem with a different missing permission: READ_EXTERNAL_STORAGE

Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/7429 from pid=13330, uid=10215 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
       at android.os.Parcel.readException(Parcel.java:1465)

Crash seems to happen on Samsung devices only (4.4, 5.0)

@jdamcd jdamcd added the crash label Sep 7, 2015
@ghost
Copy link

ghost commented Sep 25, 2015

Same error

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dlazaridis.photo.shoot.android/com.soundcloud.android.crop.CropImageActivity}: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.media.MediaDocumentsProvider from ProcessRecord{42a332e8 8339:com.dlazaridis.photo.shoot.android/u0a212} (pid=8339, uid=10212) requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
        at android.app.ActivityThread.access$800(ActivityThread.java:139)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5086)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.media.MediaDocumentsProvider from ProcessRecord{42a332e8 8339:com.dlazaridis.photo.shoot.android/u0a212} (pid=8339, uid=10212) requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS
        at android.os.Parcel.readException(Parcel.java:1465)
        at android.os.Parcel.readException(Parcel.java:1419)
        at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:2887)
        at android.app.ActivityThread.acquireProvider(ActivityThread.java:4480)
        at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2323)
        at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1425)
        at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1047)
        at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:904)
        at android.content.ContentResolver.openInputStream(ContentResolver.java:629)
        at com.soundcloud.android.crop.CropImageActivity.calculateBitmapSampleSize(CropImageActivity.java:159)
        at com.soundcloud.android.crop.CropImageActivity.loadInput(CropImageActivity.java:137)
        at com.soundcloud.android.crop.CropImageActivity.onCreate(CropImageActivity.java:76)
        at android.app.Activity.performCreate(Activity.java:5248)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)

While in manifest I had:
uses-permission android:name="android.permission.MANAGE_DOCUMENTS"

Device: Moto G (4.4.4)

@IlyaEremin
Copy link

I have same crash on Samsung only devices without READ_EXTERNAL_STORAGE permission.

crash

@grocco
Copy link

grocco commented Mar 4, 2016

Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app.

To deal with this problem, at least when caused by the new runtime permission check required from API 23, you can add something like this in CropImageActivity:

`
@OverRide
public void onCreate(Bundle icicle) {

super.onCreate(icicle);

setupWindowFlags();

setupViews();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ContextCompat.checkSelfPermission(this,
            Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ) {

        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.READ_EXTERNAL_STORAGE)) {
            Toast.makeText(this,"should show explanation", Toast.LENGTH_LONG).show();
        }
        ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
    } else {
        loadInput();


        if (rotateBitmap == null) {
            finish();
            return;
        }
        startCrop();
    }

}

`

and then something like

`
@OverRide

public void onRequestPermissionsResult(int requestCode,

                                       String permissions[], int[] grantResults) {

    switch (requestCode) {

        case MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE: {
            // If request is cancelled, the result arrays are empty.
            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                // permission was granted, yay! Do the
                // contacts-related task you need to do.
                loadInput();


                if (rotateBitmap == null) {
                    finish();
                    return;
                }
                startCrop();

            } else {

                // permission denied, boo! Disable the
                // functionality that depends on this permission.
            }
            return;
        }

        // other 'case' lines to check for other
        // permissions this app might request
    }
}

`

In general, have a look here: http://developer.android.com/training/permissions/requesting.html

ApoorvKhatreja pushed a commit to ApoorvKhatreja/android-crop that referenced this issue Mar 28, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants