我正在使用DownloadManager
从我们的服务器下载图片,并将文件放置在externalFilesDir
中。
我发送广播意图,因为我不希望这些下载的图片出现在相册中。
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + context.getExternalFilesDir(null))));
我只在我的Galaxy S3上测试过这个应用程序,之前它可以正常运行在Jelly Bean 4.3上,但是当我在KitKat 4.4上测试时,它会导致应用程序崩溃。
是否有更好的方法使从DownloadManager下载的文件不出现在手机相册中?
堆栈跟踪
06-05 17:34:41.940: E/AndroidRuntime(15410): FATAL EXCEPTION: main
06-05 17:34:41.940: E/AndroidRuntime(15410): Process: com.walintukai.lfdate, PID: 15410
06-05 17:34:41.940: E/AndroidRuntime(15410): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.DOWNLOAD_COMPLETE flg=0x10 pkg=com.walintukai.lfdate (has extras) } in com.walintukai.lfdate.SocketIOService$1@42359f40
06-05 17:34:41.940: E/AndroidRuntime(15410): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:778)
06-05 17:34:41.940: E/AndroidRuntime(15410): at android.os.Handler.handleCallback(Handler.java:733)
06-05 17:34:41.940: E/AndroidRuntime(15410): at android.os.Handler.dispatchMessage(Handler.java:95)
06-05 17:34:41.940: E/AndroidRuntime(15410): at android.os.Looper.loop(Looper.java:136)
06-05 17:34:41.940: E/AndroidRuntime(15410): at android.app.ActivityThread.main(ActivityThread.java:5057)
06-05 17:34:41.940: E/AndroidRuntime(15410): at java.lang.reflect.Method.invokeNative(Native Method)
06-05 17:34:41.940: E/AndroidRuntime(15410): at java.lang.reflect.Method.invoke(Method.java:515)
06-05 17:34:41.940: E/AndroidRuntime(15410): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
06-05 17:34:41.940: E/AndroidRuntime(15410): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
06-05 17:34:41.940: E/AndroidRuntime(15410): at dalvik.system.NativeStart.main(Native Method)
06-05 17:34:41.940: E/AndroidRuntime(15410): Caused by: java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED from pid=15410, uid=10135
06-05 17:34:41.940: E/AndroidRuntime(15410): at android.os.Parcel.readException(Parcel.java:1465)
06-05 17:34:41.940: E/AndroidRuntime(15410): at android.os.Parcel.readException(Parcel.java:1419)
06-05 17:34:41.940: E/AndroidRuntime(15410): at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:2390)
06-05 17:34:41.940: E/AndroidRuntime(15410): at android.app.ContextImpl.sendBroadcast(ContextImpl.java:1127)
06-05 17:34:41.940: E/AndroidRuntime(15410): at android.content.ContextWrapper.sendBroadcast(ContextWrapper.java:365)
06-05 17:34:41.940: E/AndroidRuntime(15410): at com.walintukai.lfdate.SocketIOService$1.onReceive(SocketIOService.java:111)
06-05 17:34:41.940: E/AndroidRuntime(15410): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:768)
06-05 17:34:41.940: E/AndroidRuntime(15410): ... 9 more
.nomedia
的文件。要立即让文件出现,请按照下面答案中所述运行媒体扫描。 - user149408