How to send video to a specific number in whatsApp in Android? - android

I want to send a video that is stored in my raw folder in the Android Studio project to WhatsApp. How can I do it?
public void shareVideoWhatsApp() {
String path = "android.resource://" + getPackageName() + "/" + R.raw.file_1;
Uri uri = Uri.parse(path);
Intent intent = new Intent(Intent.ACTION_MEDIA_SHARED);
intent.setType("text/plain");
// intent.putExtra(Intent.EXTRA_STREAM,uri);
intent.putExtra( Intent.EXTRA_TEXT, "Hello");
intent.setData(Uri.parse("http://api.whatsapp.com/send?phone="+"++9112345443423"));
startActivity(intent);
}

Related

android studio share CSV file request contain no data

I want to share my csv file to any action like Bluetooth, send to email ,etc
final String filename = Environment.getExternalStorageDirectory() + "/Folder" + "/" + "mycsv.csv";
Intent sharingIntent = new Intent();
sharingIntent.setAction(Intent.ACTION_SEND);
sharingIntent.putExtra(Intent.EXTRA_STREAM, filename);
sharingIntent.setType("text/comma_separated_values/csv");
startActivity(Intent.createChooser(sharingIntent, "share file with"));
the output will be no request containt no data
I think that the filename requires a file:// prefix. Android, for sharing any types of file requires a universal identifier or a Uri.
final String fileUriString = "file://" + Environment.getExternalStorageDirectory() + "/Folder" + "/" + "mycsv.csv";
Also, change the type to text/csv.
Intent sharingIntent = new Intent();
sharingIntent.setAction(Intent.ACTION_SEND);
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse( fileUriString ) ) ;
sharingIntent.setType("text/csv");
startActivity(Intent.createChooser(sharingIntent, "share file with"));
See this answer for more.

Video sent to whatsapp not playing

In my app there is a feature where the user can share a video with the app of their choice. The code is fairly straightforward (where mediaPath is a variable of type String which is a path to a valid video):
File media = new File(mediaPath);
Uri uri = FileProvider.getUriForFile(context, getString(R.string.file_provider_authority), media);
Intent share = new Intent(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_STREAM, uri);
share.setType("video/*");
String title = getString(R.string.share_video_title);
Intent chooser = Intent.createChooser(share, title);
if (share.resolveActivity(context.getPackageManager()) != null) {
startActivity(chooser);
}
Sharing works perfectly on gmail (for example) and seems to work fine on whatsapp as well. It compresses the video and uploads it. The recipient gets the video and is able to see a thumbnail and download it. However they cannot play the video.
I finally found the solution is here
public void shareVideoWhatsApp() {
Uri uri = Uri.fromFile(v);
Intent videoshare = new Intent(Intent.ACTION_SEND);
videoshare.setType("*/*");
videoshare.setPackage("com.whatsapp");
videoshare.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
videoshare.putExtra(Intent.EXTRA_STREAM,uri);
startActivity(videoshare);
}
Refrence
Are you try this:
String path = ""; //should be local path of downloaded video
ContentValues content = new ContentValues(4);
content.put(MediaStore.Video.VideoColumns.DATE_ADDED,
System.currentTimeMillis() / 1000);
content.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
content.put(MediaStore.Video.Media.DATA, path);
ContentResolver resolver = getApplicationContext().getContentResolver();
Uri uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, content);
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("video/*");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "Hey this is the video subject");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Hey this is the video text");
sharingIntent.putExtra(Intent.EXTRA_STREAM,uri);
startActivity(Intent.createChooser(sharingIntent,"Share Video");

how to share text+video in single intent in android?

Below this code i try to share text with video but it only share video,text not share with video.
please help if any one have solution of my issue.
String path="android.resource://" + "com.avani.videoviewdemo" + "/" + R.raw.ae_kaash_kahi;
//Intent a = getIntent();
file=new File(path);
str=arrayList.get(position).getVideoName();
Log.e("video_name", ""+arrayList.get(position).getVideoName()); Log.e("video_name",""+ str);
id = context.getResources().getIdentifier(str, "raw", context.getPackageName()); Uri uri = Uri.parse("android.resource://" + context.getPackageName() + "/" + id);
DownloadFile();
Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri screenshotUri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", file); sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri); sharingIntent.putExtra(Intent.EXTRA_TEXT, "From FullScreenVideoStatus"); sharingIntent.setType("video/*"); context.startActivity(Intent.createChooser(sharingIntent, "Share video using"));
For set caption in video/image in share intent, just set text in:
sharingIntent.putExtra(Intent.EXTRA_TITLE, "Your text caption");
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("video/mp4"); //If it is a 3gp video use ("video/3gp")
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/raw/ae_kaash_kahi";
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Video Title");
startActivity(Intent.createChooser(sharingIntent, "Share Video!"));
intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "TEMPORARY"); // for text share
intent.putExtra(Intent.EXTRA_STREAM, uri); // for media share
intent.setType("image/*"); // this line is use to filter which app support specified media formate to share
startActivity(intent);
you can use video/* for video file here i have used image/* for image share

Attach txt file and send to bluetooth

How i can send the txt file that i created with the FileOutputStream trought of screemShare
i can also not found the file path
//x = "/data/data/" + getPackageName() +"/pec.txt";
this is my code:
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
Uri uri = Uri.parse(x);
intent.putExtra(android.content.Intent.EXTRA_STREAM, uri);
intent.putExtra(android.content.Intent.EXTRA_TEXT, "PEC");
startActivity(Intent.createChooser(intent,"Imprimir"));
Check this example that work for me HERE

Share image with Android intent

I'm trying to share an image trough a share intent like this:
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("image/png");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, application.getString(R.string.app_name));
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,application.getString(R.string.app_share_message));
File image = new File(Uri.parse("android.resource://" + C.PROJECT_PATH + "/drawable/" + R.drawable.icon_to_share).toString());
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(image));
shareMe(sharingIntent);
The share intent fires correctly and I choose Gmail, everything runs as expected until I press send. I receive a notification "Unable to show attach", and the e-mail is sent without it...
Why?
Thanks for your time.
First, there is no guarantee that any given other app will be able to support an android:resource// Uri. You will have greater compatibility sharing a file on external storage or using a ContentProvider.
That being said, replace:
File image = new File(Uri.parse("android.resource://" + C.PROJECT_PATH + "/drawable/" + R.drawable.icon_to_share).toString());
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(image));
with:
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://" + C.PROJECT_PATH + "/drawable/" + R.drawable.icon_to_share);
An android:resource:// is not a File, and probably you are messing up your Uri by converting to a File and then back to a Uri.
BitmapDrawable bitmapDrawable = (BitmapDrawable)ImageView.getDrawable();
Bitmap bitmap = bitmapDrawable.getBitmap();
// Save this bitmap to a file.
File cache = getApplicationContext().getExternalCacheDir();
File sharefile = new File(cache, "toshare.png");
Log.d("share file type is", sharefile.getAbsolutePath());
try {
FileOutputStream out = new FileOutputStream(sharefile);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
} catch (IOException e) {
Log.e("ERROR", String.valueOf(e.getMessage()));
}
// Now send it out to share
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/*");
share.putExtra(Intent.EXTRA_STREAM,
Uri.parse("file://" + sharefile));
startActivity(Intent.createChooser(share,
"Share Image"));
In my case I used:
Uri imageUri = Uri.parse("android.resource://com.examle.tarea/" + R.drawable.tienda_musica);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/jpeg");
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(intent, getString(R.string.action_share)));
//open a share intent chooser (Will show installed app from which i can share //images)
private void shareImage(String imagePath, String quoteByPerson, String quoteToShare)
{
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
// String imagePath = Environment.getExternalStorageDirectory() +
// "/myImage.png";
File imageFileToShare = new File(imagePath);
Uri uri = Uri.fromFile(imageFileToShare);
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
share.putExtra(Intent.EXTRA_TEXT, "Quote of the day-:" + "\n" + quoteToShare + "\n" + quoteByPerson);
share.putExtra(android.content.Intent.EXTRA_TITLE, "Quote of the day-:");
if (imagePath.contains("android.resource://"))
{
Uri imageUri = Uri.parse(imagePath);
share.putExtra(Intent.EXTRA_STREAM, imageUri);
} else
{
share.putExtra(Intent.EXTRA_STREAM, uri);
}
startActivity(Intent.createChooser(share, "Share inspiration via..."));
}

Categories

Resources