解决query不到本地视频方法

在查询前调用,若未出来,再进一次即可

 //发出广播让系统更新媒体库
        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" />

你可能感兴趣的:(新媒体)