我要移动视频并使用:
File video = new File(url);
InputStream inputStream = null;
OutputStream stream = null;
try {
inputStream = new FileInputStream(url);
stream = new FileOutputStream("/storage/emulated/0/MyGallery/"+video.getName());
byte[] buf =new byte[1024];
int len;
while ((len=inputStream.read(buf))!=-1){
stream.write(buf,0,len);
}
inputStream.close();
stream.flush();
stream.close();
video.delete();
}
然后我要使用以下命令获取所有视频文件路径:
Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
String[] projection = {MediaStore.Video.VideoColumns.DATA};
Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
ArrayList<String> pathArrList = new ArrayList<>();
if (cursor != null) {
while (cursor.moveToNext()) {
pathArrList.add(cursor.getString(0));
}
cursor.close();
}
Log.e("all path",pathArrList.toString());
return pathArrList;
pathArrList 获取旧文件路径,而不获取新文件路径。 重新启动手机时,删除旧文件路径。
我要获取新的文件路径以在应用中显示如何解决此问题?
答案 0 :(得分:0)
您是否将这些权限添加到清单了?
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />