如何刷新SDCard?

时间:2014-02-11 09:28:44

标签: android android-broadcast

我正在尝试刷新SDCard。为此,我正在使用

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

但它给出了错误。这是我的LOG。

02-11 04:19:11.060: E/AndroidRuntime(5093): FATAL EXCEPTION: main
02-11 04:19:11.060: E/AndroidRuntime(5093): java.lang.RuntimeException: Unable to start activity ComponentInfo{amiTechnologies.products.amidesignerforvideo/amiTechnologies.products.amidesignerforvideo.AMIDesignerForVideoActivity}: java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED from pid=5093, uid=10156
02-11 04:19:11.060: E/AndroidRuntime(5093):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
02-11 04:19:11.060: E/AndroidRuntime(5093):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-11 04:19:11.060: E/AndroidRuntime(5093):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-11 04:19:11.060: E/AndroidRuntime(5093):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-11 04:19:11.060: E/AndroidRuntime(5093):     at android.os.Handler.dispatchMessage(Handler.java:102)
02-11 04:19:11.060: E/AndroidRuntime(5093):     at android.os.Looper.loop(Looper.java:136)
02-11 04:19:11.060: E/AndroidRuntime(5093):     at android.app.ActivityThread.main(ActivityThread.java:5017)
02-11 04:19:11.060: E/AndroidRuntime(5093):     at java.lang.reflect.Method.invokeNative(Native Method)
02-11 04:19:11.060: E/AndroidRuntime(5093):     at java.lang.reflect.Method.invoke(Method.java:515)
02-11 04:19:11.060: E/AndroidRuntime(5093):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-11 04:19:11.060: E/AndroidRuntime(5093):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-11 04:19:11.060: E/AndroidRuntime(5093):     at dalvik.system.NativeStart.main(Native Method)
02-11 04:19:11.060: E/AndroidRuntime(5093): Caused by: java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED from pid=5093, uid=10156
02-11 04:19:11.060: E/AndroidRuntime(5093):     at android.os.Parcel.readException(Parcel.java:1465)
02-11 04:19:11.060: E/AndroidRuntime(5093):     at android.os.Parcel.readException(Parcel.java:1419)
02-11 04:19:11.060: E/AndroidRuntime(5093):     at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:2373)
02-11 04:19:11.060: E/AndroidRuntime(5093):     at android.app.ContextImpl.sendBroadcast(ContextImpl.java:1127)
02-11 04:19:11.060: E/AndroidRuntime(5093):     at android.content.ContextWrapper.sendBroadcast(ContextWrapper.java:365)
02-11 04:19:11.060: E/AndroidRuntime(5093):     at amiTechnologies.products.amidesignerforvideo.AMIDesignerForVideoActivity.onCreate(AMIDesignerForVideoActivity.java:329)
02-11 04:19:11.060: E/AndroidRuntime(5093):     at android.app.Activity.performCreate(Activity.java:5231)
02-11 04:19:11.060: E/AndroidRuntime(5093):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-11 04:19:11.060: E/AndroidRuntime(5093):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
02-11 04:19:11.060: E/AndroidRuntime(5093):     ... 11 more

我必须添加哪些权限?我从堆栈溢出中尝试了很多答案,但对我没用。

1 个答案:

答案 0 :(得分:0)

当您使用代码时

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

看起来不错但设备必须与USB断开连接,不应连接。否则,您可能需要重新拔下并重新插入设备,以查看您尝试进行的所有更改。

你看到它说明的日志

java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED

请在使用以下代码段时将设备断开连接

也可以访问I try scan media file in sdcard and refresh it,这可能对您有帮助。