gpt4 book ai didi

android - 撤销权限 android.permission.CAMERA

转载 作者:IT老高 更新时间:2023-10-28 23:27:47 30 4
gpt4 key购买 nike

我得到错误 revoked permission android.permission.CAMERA

我在 list 上使用了相机权限

private void dispatchTakePictureIntent(int actionCode) {

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

switch (actionCode) {
case ACTION_TAKE_PHOTO_B:
File f = null;

try {
f = setUpPhotoFile();
mCurrentPhotoPath = f.getAbsolutePath();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
} catch (IOException e) {
e.printStackTrace();
f = null;
mCurrentPhotoPath = null;
}
break;

default:
break;
} // switch

startActivityForResult(takePictureIntent, actionCode);
}

和这样的错误:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mobile.lunatique.photo, PID: 3590
java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=com.android.camera2/com.android.camera.CaptureActivity clip={text/uri-list U:file:///KTP_42342.jpg} (has extras) } from ProcessRecord{2fbbd91 3590:com.mobile.lunatique.photo/u0a60} (pid=3590, uid=10060) with revoked permission android.permission.CAMERA
at android.os.Parcel.readException(Parcel.java:1599)
at android.os.Parcel.readException(Parcel.java:1552)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2658)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1507)
at android.app.Activity.startActivityForResult(Activity.java:3917)
at android.app.Activity.startActivityForResult(Activity.java:3877)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:842)
at com.mobile.lunatique.photo.MainActivity.dispatchTakePictureIntent(MainActivity.java:254)
at com.mobile.lunatique.photo.MainActivity.access$000(MainActivity.java:33)
at com.mobile.lunatique.photo.MainActivity$1.onClick(MainActivity.java:321)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
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)
I/Process: Sending signal. PID: 3590 SIG: 9

谁能帮帮我??

最佳答案

我是这样解决这个问题的。

与大多数答案所说的相反,从您的 list 文件中删除它。

 <uses-permission android:name="android.permission.CAMERA"/>

为什么?

从 Android M (API 23) 开始,如果您的应用在 list 中声明了 CAMERA 权限,那么,它需要 CAMERA 权限是GRANTED 以访问 ACTION_IMAGE_CAPTURE等等...(通常不需要自己的 CAMERA 权限)。如果没有,那么它会自动引发 SecurityException

╔═════════════════════════════════════════════════╦════════════════════╗
║ Usage ║ Permissions needed ║
╠═════════════════════════════════════════════════╬════════════════════╣
║ ACTION_IMAGE_CAPTURE ║ none ║
║ ACTION_VIDEO_CAPTURE ║ none ║
║ INTENT_ACTION_STILL_IMAGE_CAMERA ║ none ║
║ android.hardware.camera2 ║ CAMERA ║
║ android.hardware.camera2 + ACTION_IMAGE_CAPTURE ║ CAMERA ║
║ android.hardware.camera2 + ACTION_VIDEO_CAPTURE ║ CAMERA ║
║ ... ║ ... ║
╚═════════════════════════════════════════════════╩════════════════════╝

上表仅适用于 API 23+

tl;dr 怎么办?

选项 1- 如果您只使用 ACTION_IMAGE_CAPTURE 等...
从 list 中删除 CAMERA 权限就可以了

选项2-如果您使用其他CAMERA功能:
在运行时检查 CAMERA 权限,只有在权限可用时才启动 Intent

关于android - 撤销权限 android.permission.CAMERA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43042725/

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