کدی که گفتید رو به شکل زیر استفاده کردم ولی متاسفانه موقعی که میخوام فایل رو به اشتراک بزارم میگه فایل نامعلوم ارسال نشد !
لطفا ببینید کجای کدم اشکال داره :
لطفا ببینید کجای کدم اشکال داره :
کد پیاچپی:
File root = android.os.Environment.getExternalStorageDirectory();
String folderName = "/my_film";
File dir = new File (root.getAbsolutePath() + folderName);
if(!dir.exists()) {
dir.mkdirs(); // build directory
}
InputStream in = getResources().openRawResource(R.raw.film1);
String filename = "film1.mp4";
File f = new File(filename);
if(!f.exists()){
try {
OutputStream out = new FileOutputStream(new File(root + folderName , filename));
byte[] buffer = new byte[1024];
int len;
while((len = in.read(buffer, 0, buffer.length)) != -1){
out.write(buffer, 0, len);
}
in.close();
out.close();
} catch (FileNotFoundException e) {
//
} catch (IOException e) {
//
}
}
Uri outputFileUri = Uri.fromFile(f);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setType("video/mp4");
intent.putExtra(Intent.EXTRA_STREAM, outputFileUri);
startActivity(Intent.createChooser(intent, "انتخاب روش ارسال"));