我正在测试code of ScreenRecorder并希望将视频文件存储在Movies文件夹中(未模拟)。但是,当我尝试使用getExternalStoragePublicDirectory(DIRECTORY_MOVIES) + "/video.mp4"
获取此文件夹时,会返回: / storage / emulated / 0 / Movies ,我没有访问Android UI的文件夹。
PS:
然后,如何正确检索此文件夹?
答案 0 :(得分:0)
您是否拥有外部存储空间?
看起来应该是这样的:
public class PermissionUtils {
public static final int REQUEST_EXTERNAL_STORAGE = 2000;
public static void requestExternal(Activity context) {
if (!checkExternal(context)) {
ActivityCompat.requestPermissions(context, new String[]{
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE},
REQUEST_EXTERNAL_STORAGE);
}
}
public static boolean checkExternal(Context context) {
return !(ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED);
}
}
然后在你的onCreate()中添加它;方法:
PermissionUtils.requestExternal(this);