Я хочу выбрать видео из телефонной галереи и отправить в социальные сети, например, WhatsApp, используя намерение. но в моем случае видео выбирается из галереи успешно, но когда я нажимаю кнопку отправки i go в WhatsApp, когда я выбираю конкретный c контакт, чтобы отправить это видео и отправить его / ее, оно будет отправлено в формате unknonw, а не в видео. я также использую fileprovider в моем проекте ... это мой код.
функция обмена видео:
private void videoShareFunction()
{
Toast.makeText(this, "share video...", Toast.LENGTH_SHORT).show();
Intent intent=new Intent(Intent.ACTION_SEND);
Uri uri= FileProvider.getUriForFile(getApplicationContext(),
getPackageName()+".fileprovider",saveVideoBitmap(bitmaps, getString(R.string.app_name)));
intent.setDataAndType(uri,"image/*");
intent.putExtra(Intent.EXTRA_STREAM,uri);
startActivity(intent);
}
функция сохранения видео:
private File saveVideoBitmap (Bitmap bitmap, String videoName)
{
File myDir = new File(Environment.getExternalStorageDirectory().
getAbsoluteFile()+ File.separator + "."+getString(R.string.app_name));
if (!myDir.exists())
{
myDir.mkdirs();
}
String fname = "Video";
file = new File(myDir, fname);
if (file.exists()) {
file.delete();
}
try {
file.createNewFile();
FileOutputStream out = new FileOutputStream(file);
// bitmap.compress(Bitmap.CompressFormat.valueOf(fname), 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(this, "Bitmap sy kam ni ho ga", Toast.LENGTH_SHORT).show();
}
MediaScannerConnection.scanFile(this, new String[]{file.toString()}, new String[]{file.getName()}, null);
return file;
}
OnActivityResult:
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK)
{
try {
if (requestCode == CODE_ONE_VIDEO && resultCode == RESULT_OK)
{
videoUri = data.getData();
if (videoUri != null)
{
videoView.setVideoURI(videoUri);
videoView.start();
videoControler();
}
}
else {
Toast.makeText(this, "You haven't picked Image", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(VideoPickActivity.this, "Something went wrong", Toast.LENGTH_LONG).show();
}
}else {
Toast.makeText(VideoPickActivity.this, "You haven't get Image",Toast.LENGTH_LONG).show();
}
}