I receive an error when I press a Button.
InputStream y11 = getResources().openRawResource(R.drawable.step_000);
Bitmap b11 = BitmapFactory.decodeStream(y11);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/png");
intent.setPackage("com.whats app.android");
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, b11);
startActivity(Intent.createChooser(intent, "Share with"));
You can try like this;
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/png");
Uri uri = Uri.parse("android.resource://your package name/"+R.drawable.ic_launcher);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello, This is test Sharing");
startActivity(Intent.createChooser(shareIntent, "Send your image"));
Also look into this: Returning an Image to whatsapp
Related
I am looking to add a text message under an image (not printed on the image) so when I click a share button, the image, and text message to be shared as one message that looks like this:
My code to share an image looks like this:
public void shareImage(View view) {
Intent shareIntent = new Intent();
Uri photoURI = FileProvider.getUriForFile(this, "com.abcd.myapp", theImage);
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, photoURI);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share Image with ..."));
}
How can I add the text Image created by: abcd.com under the image, (as a text not printed on the image) in the same text message or email etc.
Try this
Uri imgUri = Uri.fromFile(new File(DIRECTORY + "/" + fileName));
//Add this code if you get SecurityException error
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, imgUri);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Text you want to attach with image.");
startActivity(Intent.createChooser(shareIntent, "Share Image"));
The following snippet of code should work. We add the image to MediaStore.
public void shareImage(View view) {
Intent shareIntent = new Intent();
shareIntent.putExtra(Intent.EXTRA_TEXT, Constant.SHARE_MESSAGE
+ Constant.SHARE_URL);
Uri photoURI = FileProvider.getUriForFile(this, "com.abcd.myapp", theImage);
Bitmap bm = BitmapFactory.decodeFile(photoURI);
String url= MediaStore.Images.Media.insertImage(this.getContentResolver(), bm, "title", "description");
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share Image with ..."));
}
A simple case of sharing a bitmap to Twitter/Whatsapp/Facebook Messenger was resolved thanks to #Aniruddh Chandratre solution. MediaStore.Images.Media.insertImage returns a String in content://media format i.e. content://media/external/images/media/610
val savedImageURI = MediaStore.Images.Media.insertImage(
activity.contentResolver, bitmap, "title", "decription")
val shareIntent = Intent(Intent.ACTION_SEND)
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(savedImageURI))
shareIntent.type = "image/*"
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
activity.startActivity(Intent.createChooser(shareIntent, "Share Image"))
I want to share image from my app to Whatsapp but it's giving me the error "sharing failed , please try again" this is my code:
String text = "Look at my awesome picture";
Uri pictureUri = Uri.parse("file://www.punjabidharti.com/wp-content/uploads/2018/05/baap-600x600.jpg");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, text);
shareIntent.putExtra(Intent.EXTRA_STREAM, pictureUri);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share images..."));
and I am using image url from my website.
You are passing a http url not a file url. Make your uri like this and it will work
Uri pictureUri = Uri.parse("http://www.punjabidharti.com/wp-content/uploads/2018/05/baap-600x600.jpg");
I am developing an app in which I want to click Image and automatically after capturing image, the app should send the picture to mail.
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(imgSaved));
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share Image"));
You need to create an intent which will be fired on selection of the image
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("application/image");
intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{strEmail});
intent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Any subject you want to give");
intent.putExtra(android.content.Intent.EXTRA_TEXT, "text you want");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/imageYouSelected.jpeg"));
startActivity(Intent.createChooser(emailIntent, "sending youer email"));
OR
You can use the JAVA API approach like here
try like this may help you,
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_EMAIL,
new String[] { "aa#gmail.com" });
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "text of email");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(imgSaved));
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share Image"));
I want to share image and text like:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri u = Uri.parse(url);
i.setData(u);
startActivity(intent);
Kindly find the below code.
Uri path= Uri.parse("android.resource://" + this.getPackageName()
+ "/drawable/" + "image_name");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Testing");
shareIntent.putExtra(Intent.EXTRA_STREAM, path);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share Using"));
Here i am sharing images from my app to whatsapp.but this code is working here only for mylist1[i] and not for mylist2[i] and mylist3[i]. As in my activity file there are 15 images in every list. what to do?
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/*");
Uri uri = Uri.parse("android.resource://com.example.drawcelebrities/"+mylist1[i]+mylist2[i]+mylist3[i]);
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Share via"));
Take image array in mylist[] and use below code, then share image via whatsapp.
Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+mylist[i]);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(shareIntent, "Share via"));
If I'm not wrong then for that you should use android.content.Intent.ACTION_SEND_MULTIPLE..Refer this link it will help you..
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND_MULTIPLE);
intent.putExtra(Intent.EXTRA_SUBJECT, "Here are some files.");
intent.setType("image/jpeg");
ArrayList<Uri> files = new ArrayList<Uri>();
for(String path : filesToSend /* List of the files you want to send */) {
File file = new File(path);
Uri uri = Uri.fromFile(file);
files.add(uri);
}
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
startActivity(intent);