权限拒绝:广播意图未导出

时间:2013-07-20 05:32:48

标签: android

我有以下代码:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory().getAbsolutePath()))); 在我的清单中,我补充道:

           <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
            <action android:name="android.intent.ACTION_MEDIA_MOUNTED"/>
            <action android:name="android.intent.action.MEDIA_EJECT" />
            <action android:name="android.intent.ACTION_MEDIA_SCANNER_SCAN_FILE"/>
            <data android:scheme="file"/>
        </intent-filter>
    </activity>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

我收到以下错误

07-20 13:16:31.203: WARN/BroadcastQueue(395): Permission Denial: broadcasting Intent { act=android.intent.action.MEDIA_MOUNTED dat=file:///storage/sdcard0 flg=0x10 } from com.example.Music_Exchanger (pid=11797, uid=10080) is not exported from uid 10016 due to receiver com.android.providers.downloads/com.android.providers.downloads.DownloadReceiver

我不知道为什么会拒绝。我怎么解决呢???

如果您知道,请帮助我,请写出更详细的信息。我只是个初学者。

非常感谢!

3 个答案:

答案 0 :(得分:2)

实施广播接收器并将其定义添加到清单文件中:

<application
    android:icon="@drawable/icon"
    android:label="@string/app_name" >
    <!--...-->

    <receiver
        android:name=".CustomReceiver"
        android:exported="true" >
    </receiver>
</application>

CustomReciever扩展BroadcastReceiver。

答案 1 :(得分:1)

添加

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

另一个注意事项:隐式写入外部存储已读取外部存储权限。

答案 2 :(得分:0)

使用MediaScannerConnection而不是SendBroadcast ..

conn = new MediaScannerConnection( * * your context * * ,
     new MediaScannerConnection.MediaScannerConnectionClient() {@
         Override
         public void onScanCompleted(String path, Uri uri) {

             if (path.equals( * * your filename * * .getAbsolutePath())) {
                 Log.i("Scan Status", "Completed");
                 Log.i("uri: ", uri.toString());

                 conn.disconnect();
             }
         }@
         Override
         public void onMediaScannerConnected() {
             // TODO Auto-generated method stub
             conn.scanFile( * * your file name * * .getAbsolutePath(), null);

         }
     });
 conn.connect();