简体   繁体   English

权限拒绝:不允许在android中发送广播

[英]Permission Denial: not allowed to send broadcast in android

I have created a simple camera app. 我创建了一个简单的相机应用程序。 It works fine in all the versions of Android except Android 4.4. 除了Android 4.4之外,它在Android的所有版本中都能正常运行。 I get the following error when I take a picture from my camera App. 当我从相机应用程序拍照时,我收到以下错误。

java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED from pid=26089, uid=10120

Error comes up: 出现错误:

In the following place: 在以下地方:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));

How to fix this issue for KITKAT? 如何为KITKAT解决这个问题?

Let me know! 让我知道!

Thanks! 谢谢!

How to fix this issue for KITKAT? 如何为KITKAT解决这个问题?

That code has never been appropriate. 该代码从未适用。 Fortunately, Android is (finally) taking steps to prevent apps from spoofing more system broadcasts like this. 幸运的是,Android(最终)采取措施阻止应用程序欺骗更多这样的系统广播。

If you want to tell Android to index a file you put on external storage, either use MediaScannerConnection or ACTION_MEDIA_SCANNER_SCAN_FILE . 如果您想告诉Android索引您放在外部存储上的文件,请使用MediaScannerConnectionACTION_MEDIA_SCANNER_SCAN_FILE

I resolved this problem, you can use this: 我解决了这个问题,你可以用这个:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, mediaMountUri));

hope this can help you ! 希望这可以帮到你 !

Android prevents apps from sending broadcast like ACTION_MEDIA_SCANNER_SCAN_FILE or ACTION_MEDIA_MOUNTED. Android会阻止应​​用发送广播,如ACTION_MEDIA_SCANNER_SCAN_FILE或ACTION_MEDIA_MOUNTED。 Use static method scanFile of MediaScannerConnection instead. 请改用MediaScannerConnection的静态方法scanFile。

MediaScannerConnection.scanFile(getApplicationContext(), new String[] { file.getAbsolutePath() }, null, new OnScanCompletedListener() {

                @Override
                public void onScanCompleted(String path, Uri uri) {
                    // TODO Auto-generated method stub

                }
            });

Short answer: You can't, at least not easily. 简短的回答:你不能,至少不容易。

A lot of apps used to use this intent to rescan the entire filesystem after changing only one file, which drained battery life considerably. 许多应用程序在更改一个文件后使用此意图重新扫描整个文件系统,这大大耗尽了电池寿命。 Starting from Android 4.4, only System apps can now use it. 从Android 4.4开始,只有系统应用程序现在可以使用它。 You'll likely have to find a workaround that doesn't use this intent. 您可能必须找到不使用此意图的解决方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 权限拒绝:不允许发送广播android - Permission Denial: not allowed to send broadcast android 嘿,我才刚开始在android中进行编码并收到错误Permission Denial:不允许在android中发送广播 - Hey , I am just started to code in android and getting error Permission Denial: not allowed to send broadcast in android 拒绝权限:不允许发送广播android.bluetooth.device.action.FOUND - Permission Denial: not allowed to send broadcast android.bluetooth.device.action.FOUND Permission Denial:不允许发送广播 android.intent.action.AIRPLANE_MODE - Permission Denial: not allowed to send broadcast android.intent.action.AIRPLANE_MODE SecurityException:权限被拒绝:不允许发送广播android.intent.action.BATTERY_CHANGED - SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.BATTERY_CHANGED java.lang.SecurityException:权限拒绝:不允许发送广播android.hardware.usb.action.USB_STATE - java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.hardware.usb.action.USB_STATE 权限拒绝:不允许发送广播android.intent.action.HEADSET_PLUG - Permission Denial: not allowed to send broadcast android.intent.action.HEADSET_PLUG CSipSimple-java.lang.SecurityException:权限拒绝:不允许发送广播android.intent.action.Phone_State - CSipSimple - java.lang.SecurityException : Permission Denial: not allowed to send broadcast android.intent.action.Phone_State 应用程序因 Permission Denial 崩溃:不允许发送广播 android.intent.action.SCREEN_ON - App crashes with Permission Denial: not allowed to send broadcast android.intent.action.SCREEN_ON java.lang.SecurityException:权限拒绝:不允许在android 7(N OS)上发送广播android.intent.action.NEW_OUTGOING_CALL - java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.NEW_OUTGOING_CALL on android 7 (N OS)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM