我的應用程序背後的概念可能沒有意義,但我只是需要它來演示一些東西。
我想要做的是:從庫中導入視頻,然後將其保存到另一個文件夾中
1 - 從Android圖庫導入視頻
2 - 將其重命名(XYZ爲例)
3 - 保存不同的文件夾下(ABC)
完整路徑將是,例如:
"/storage/emulated/0/Pictures/ABC/XYZ.mp4"
我設法打電話的意圖來顯示的畫廊,我會挑預期視頻,但我不知道我應該怎麼寫在onActivityResult?
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
Intent intent = new Intent();
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Video"),TAKE_Video);
}
}
添加此代碼以下@CommonsWare步驟,但沒有任何反應:(
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == TAKE_Video) {
File root = new File(Environment.getExternalStorageDirectory(), "/Pictures/Targets/"); ///storage/emulated/0/Directory Name
if (!root.exists()) {
root.mkdirs();
}
try {
FileInputStream fis = (FileInputStream) getContentResolver().openInputStream(data.getData());
File file;
String newname="newname.mp4";
file = new File(root,newname);
FileOutputStream fos = new FileOutputStream(file);
byte[] buf = new byte[1024];
int len;
while ((len = fis.read(buf)) > 0) {
fos.write(buf, 0, len);
}
fos.flush();
fos.getFD().sync();
fos.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
「我設法調用意圖顯示畫廊,我將選擇預期的視頻」 - 請編輯您的問題並提供[mcve],展示您正在爲此做什麼,因爲這將有助於引導如何使用結果。 – CommonsWare
對不起,我添加了意向代碼 – NuhaAbd