我总是为我的问题找到以下答案:
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"
+ Environment.getExternalStorageDirectory())));
Run Code Online (Sandbox Code Playgroud)
但它不适用于我的系统(Nexus4 Android 4. ...)
我可以创建一个文件并将其添加到Media-DB中
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri contentUri = Uri.fromFile(file);
mediaScanIntent.setData(contentUri);
context.sendBroadcast(mediaScanIntent);
Run Code Online (Sandbox Code Playgroud)
"file"是我要添加的新图像文件.
删除文件后,我尝试刷新库
Intent intent = new Intent(Intent.ACTION_MEDIA_MOUNTED);
Uri contentUri = Uri.parse("file://" + Environment.getExternalStorageDirectory());
intent.setData(contentUri);
context.sendBroadcast(intent);
Run Code Online (Sandbox Code Playgroud)
要么
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"
+ Environment.getExternalStorageDirectory())));
Run Code Online (Sandbox Code Playgroud)
但是Galery仍有空占位符.
我不知道为什么?...
为了安全起见,我在AndroidManifest.xml中添加了我的Activity
<intent-filter>
<action android:name="android.intent.action.MEDIA_MOUNTED" />
<data android:scheme="file" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
但结果是一样的.有什么想法解决这个问题吗?