I have developed one wallpaper application in which I want to add share button to share a photo on whatsapp. Here is my code( but that code is only for any text msg) I want to share a photo.
Please respond with the code where in I can select a wallpaper from my application and send to whatsapp's particular contact.
case R.id.save:
InputStream y11 = getResources().openRawResource(to);
Bitmap b11 = BitmapFactory.decodeStream(y11);
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("image/*");
waIntent.setPackage("com.whatsapp.android");
waIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, to);
startActivity(Intent.createChooser(waIntent, "Share with"));
Replace
waIntent.setType("text/plain");
with
waIntent.setType("image/png");
the package name is wrong. try: com.whatsapp
and this code is to share image via whatsapp
private void shareIt(Uri uri) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/*");
sharingIntent.setPackage("com.whatsapp");
sharingIntent.putExtra(Intent.EXTRA_TEXT,"Shared via my app");
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(sharingIntent, "share with"));
}
Related
I would to share a picture to other app.I am viewing the image now through get it by intent from other activity.
by this code I get image:
final String imageurl = i.getStringExtra("Image");
And I viewing by Picasso:
Picasso.get().load(imageurl).into(prImg);
Now the question is how to share the displayed image to different applications through the following code:
// Share image
private void shareImage( ) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
sharingIntent.setType("image/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(sharingIntent, "Share Image Using"));
Or I have to use other code to do it?
I want share my application's content (Text and Image) and for this issue, I wrote below codes:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("*/*");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(content) + "" +"\n\n" + "download us app from this link" + "\n\n" +"https://play.google.com/app/com.example.example");
startActivity(Intent.createChooser(sharingIntent, "select app ..."));
But in this code, I can just share text not sharing image! I want to share Text and Image.
For show Text and Image, I use Webview. I show image into text in webview.
How can I share Text and Image?
Below code is useful to share both text and images with other apps.
String imageToShare = "http://s1.dmcdn.net/hxdt6/x720-qef.jpg"; //Image You wants to share
String title = "Title to share"; //Title you wants to share
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, title);
shareIntent.setType("*/*");
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.putExtra(Intent.EXTRA_TEXT, imageToShare);
startActivity(Intent.createChooser(shareIntent, "Select App to Share Text and Image"));
See below Code,
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/png");
intent.putExtra(Intent.EXTRA_TEXT,"http://lorempixel.com/400/200/sports/1/");//your Image Url
startActivity(Intent.createChooser(intent, "Share Image"));
Add the URI of your image to the bundle (e.g. http://some.server.com/your_image.png), this will allow the same image to be found & used when the data is pulled out of the bundle.
I wanted to share my image to social site along with textlink and image , I am using below code , it does share Image but no text , Also I tried to set setype to "text/html" , it does not does what i need.
protected void onPostExecute(String args) {
// TODO Auto-generated method stub
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
share.putExtra(Intent.EXTRA_TITLE, "http://www.google.com");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.getAbsolutePath()));
startActivity(Intent.createChooser(share, "Share Image"));
pDialog.dismiss();
}
Give this a try
Uri imageUri = Uri.parse(Filepath);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setPackage("com.whatsapp");
shareIntent.putExtra(Intent.EXTRA_TEXT, "My sample image text");
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
startActivity(shareIntent);
} catch (android.content.ActivityNotFoundException ex) {
ToastHelper.MakeShortText("Kindly install whatsapp first");
}
PS: For sharing in multiple apps just create an alert dialogue and add
whtsapp,fb and other sharing option and while clicking on them you
have to call specific intent for this.As per my knowledge for sharing
in facebook you must impliment it's sdk, though facebook is able to
share simple image and hyperlink without integrating sdk.
I use the code below for sharing images but unfortunately it works only for Line, not for Facebook and Viber
Code:
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/png");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse(G.DIR_APP + "/sample_image.png"));
startActivity(Intent.createChooser(share, "Share image"));
Share directly to Facebook and Viber...
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/png");
share.setPackage("com.facebook.katana");
//for viber package is "com.viber.voip".
share.putExtra(Intent.EXTRA_STREAM, ImageUri);
startActivity(p_intent.createChooser(share, "Share With"));
I want to upload image to facebook or/and other services, and with , for example, what's up works fine, my picture is send to any contact i choose, but when i pick Facebook on dialog chooser it opens my Facebook App, but says "One or more media items could not be added"
Here is my code how i do it:
String file_path = Environment.getExternalStorageDirectory().getAbsolutePath()+"/image.jpg";
Uri imageUri = Uri.parse(file_path);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpg");
share.putExtra(Intent.EXTRA_STREAM, imageUri);
share.putExtra(Intent.EXTRA_TEXT, "My Image");
startActivity(Intent.createChooser(share, "Share Image"));