在查询前调用,若未出来,再进一次即可
//发出广播让系统更新媒体库
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Intent mediaScanIntent = new Intent( Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri contentUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory().getAbsolutePath()));
mediaScanIntent.setData(contentUri);
getActivity().sendBroadcast(mediaScanIntent);
} else {
getActivity(). sendBroadcast(new Intent(
Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory())));
}
若提示没有权限加上
<protected-broadcast android:name="android.intent.action.MEDIA_MOUNTED" />