gpt4 book ai didi

java - 即使在manifest.xml中声明,Android权限错误

转载 作者:太空宇宙 更新时间:2023-11-04 12:55:18 27 4
gpt4 key购买 nike

我正在尝试打开一个 Intent ,从 Android 图库中选择一张照片,然后在父 Activity 中使用所选图像设置 ImageView 。我可以打开图库并选择图像,但随后父 Activity 在 onActivityResult() 方法中崩溃。崩溃发生在 Cursor 实例化行中。

    <!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<!--<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />

结果方法上的父 Activity

        Uri selectedImage = data.getData();
if(!isExternalStorageReadable()) {
Log.d("NAMSD", "SS");
} else {
Log.d("hey", selectedImage.toString());

String[] filePathColumn = {MediaStore.Images.Media.DATA};


Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);

cursor.moveToFirst();

int columnIndex = cursor.getColumnIndex(filePathColumn[0]);

String picturePath = cursor.getString(columnIndex);

cursor.close();

Bitmap imageBitmap = BitmapFactory.decodeFile(picturePath);

photo.setImageBitmap(imageBitmap);
}

Stach 跟踪:

02-16 16:09:54.108 1803-1815/? E/DatabaseUtils: Writing exception to parcel java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/37 from pid=8382, uid=10057 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission() at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:605) at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:480) at android.content.ContentProvider$Transport.query(ContentProvider.java:211) at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112) at android.os.Binder.execTransact(Binder.java:453) 02-16 16:09:54.108 8382-8382/? D/AndroidRuntime: Shutting down VM 02-16 16:09:54.109 8382-8382/? E/AndroidRuntime: FATAL EXCEPTION: main Process: io.github.getExposure, PID: 8382 java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=3, result=-1, data=Intent { dat=content://media/external/images/media/37 }} to activity {io.github.getExposure/io.github.getExposure.PostViewActivity}: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/37 from pid=8382, uid=10057 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission() at android.app.ActivityThread.deliverResults(ActivityThread.java:3699) at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742) at android.app.ActivityThread.-wrap16(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/37 from pid=8382, uid=10057 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission() at android.os.Parcel.readException(Parcel.java:1599) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135) at android.content.ContentProviderProxy.query(ContentProviderNative.java:421) at android.content.ContentResolver.query(ContentResolver.java:491) at android.content.ContentResolver.query(ContentResolver.java:434) at io.github.getExposure.PostViewActivity.onActivityResult(PostViewActivity.java:135) at android.app.Activity.dispatchActivityResult(Activity.java:6428) at android.app.ActivityThread.deliverResults(ActivityThread.java:3695) at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)  at android.app.ActivityThread.-wrap16(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5417)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

最佳答案

问题不清楚,但我怀疑你正在使用 android-23 API (Marshmallow) 进行编译,并且它引入了在使用时询问用户许可的新方式,因此有两种选择

  1. (推荐)在使用前询问用户该权限。更多信息 here .
  2. (不推荐)将您的目标 API 更改为 Marshmallow 之前的版本,这将恢复为询问应用程序安装的所有权限的旧方式。

关于java - 即使在manifest.xml中声明,Android权限错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35445733/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com