2014-02-11 12 views
0

我正在刷新SDCard。爲此,我正在使用如何刷新SDCard?

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

但它給錯誤。這是我的日誌。

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 

我必須添加什麼權限?我嘗試了很多來自堆棧溢出的答案,但對我無效。

回答

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這可以幫助您斷開該設備的日誌。

+0

謝謝你jitesh,讓我試試你的建議 – saa

+0

驚訝的是即使USB連接,這段代碼工作沒有失敗...... :) – saa

+0

我還有一個問題..我對SD卡進行了更改,那麼我的應用程序不會識別更改。我重新啓動了我的應用程序,它正在識別更改。我該如何解決這個問題。 – saa