i want to get share text and image, i find application package wise search then share application wise share functionality.
please help.
NOTE: i just want to share text with links nothing more.
thanx
Intent intentIN = getPackageManager().getLaunchIntentForPackage("PACKAGE NAME");
if (intentIN != null) {
Intent shareIntentIN = new Intent();
shareIntentIN.setAction(Intent.ACTION_SEND);
shareIntentIN.setPackage("com.instagram.android");
try {
shareIntentIN.putExtra(Intent.EXTRA_STREAM, Uri.parse(MediaStore.Images.Media.insertImage(getContentResolver(), "", "I am Happy", "Share happy !")));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
shareIntentIN.setType("image/jpeg");
startActivity(shareIntentIN);
} else {
// bring user to the market to download the app.
// or let them choose an app?
intentIN = new Intent(Intent.ACTION_VIEW);
intentIN.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intentIN.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.instagram.android&hl=en"));
startActivity(intentIN);
}
please try this.change package name as per your need.
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, mUrl);
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, mTitle);
startActivity(Intent.createChooser(shareIntent, "Share XXX"));
Related
I am trying to share a text in LinkedIn using the Intent,and i searched a lot and used many codes,but not working..I saw many discussions also but cant find a proper answer for that.
How can i open the LinkedIn to share something through a button click.
I already used the following codes,
if(Utils.doesPackageExist(getSherlockActivity(), "com.linkedin.android"))
{
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setClassName("com.linkedin.android",
"com.linkedin.android.home.UpdateStatusActivity");
shareIntent.setType("text/*");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareText);
startActivity(shareIntent);
}
else
{
Toast.makeText(getSherlockActivity(), "Please install the LinkedIn app to share your result", Toast.LENGTH_LONG).show();
}
then
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setClassName("com.linkedin.android",
"com.linkedin.android.infra.deeplink.DeepLinkHelperActivity");
shareIntent.setType("text/*");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareText);
startActivity(shareIntent);
and some more,but not working.
Thanks in advance.
Use this to share your text to linkedin
Intent linkedinIntent = new Intent(Intent.ACTION_SEND);
linkedinIntent.setType("text/plain");
linkedinIntent.putExtra(Intent.EXTRA_TEXT, text1);
boolean linkedinAppFound = false;
List<ResolveInfo> matches2 = getPackageManager()
.queryIntentActivities(linkedinIntent, 0);
for (ResolveInfo info : matches2) {
if (info.activityInfo.packageName.toLowerCase().startsWith(
"com.linkedin")) {
linkedinIntent.setPackage(info.activityInfo.packageName);
linkedinAppFound = true;
break;
}
}
if (linkedinAppFound) {
startActivity(linkedinIntent);
}
else
{
Toast.makeText(MainActivity.this,"LinkedIn app not Insatlled in your mobile", 4).show();
}
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 am building an android app. My app needs to send the customer's(who is giving purchase order) phone number to a specific mobile number via either whatsapp or sms. But I also want to restrict all other apps from my share via list other than these two.
I know how to use sharing Intent but don't know how to restrict all other apps from that drop down list.
To restric all the other app you need to provide the package name of the app you wanted to open e.g.
Intent i = new Intent(Intent.ACTION_SEND);
i.setPackage("com.whatsapp");
this is the package name for whats app.
you can easily get the packege name from setting->apps-> your App
For more information click here
Try this for whatsapp
public void shareViaWhatsapp() {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setPackage("com.whatsapp");
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
}
For SMS
public void sendSMS(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) // At least KitKat
{
String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(getActivity()); // Need to change the build to API 19
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
if (defaultSmsPackageName != null)// Can be null in case that there is no default, then the user would be able to choose
// any app that support this intent.
{
sendIntent.setPackage(defaultSmsPackageName);
}
startActivity(sendIntent);
}
else // For early versions, do what worked for you before.
{
Intent smsIntent = new Intent(android.content.Intent.ACTION_VIEW);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("sms_body","This is my text to send.");
startActivity(smsIntent);
}
}
Above answer is sufficient for your question.But for other coders this may help :)
For whatsapp :
try {
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
waIntent.setPackage("com.whatsapp");
if (waIntent != null) {
waIntent.putExtra(Intent.EXTRA_TEXT, textToSend);//
startActivity(Intent.createChooser(waIntent, "Share with"));
} else {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
} catch (Exception e) {
Toast.makeText(ShareActivity.this,"Could not launch WhatsApp.",Toast.LENGTH_SHORT).show();
}
For Message :
try {
Intent sendIntentmsg = new Intent(Intent.ACTION_VIEW);
sendIntentmsg.setData(Uri.parse("sms:"));
sendIntentmsg.putExtra("sms_body", textToSend);
startActivity(sendIntentmsg);
} catch (Exception e) {
Toast.makeText(ShareActivity.this,"Could not launch Messaging App now.",Toast.LENGTH_SHORT).show();
}
In my application i need to share image/text to whatsapp. Sharing images or text is working fine. But my requirement is sharing images/text to specific recipant. For that i have mobile number. So before sharing, first of all that number is having whatsapp or not?. Then if the number having whatsapp, then bydefault select that specific number. If the number is not having whatsapp then simply redirect to whatspp. then they select the recipant and share to that recipant.
For sharing i am using the following code. This code is working fine for sharing.
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
if (images.size() > 0) {
Log.e("count==", "val## " + images.size());
shareIntent
.putParcelableArrayListExtra(Intent.EXTRA_STREAM, images);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_TEXT, title);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else {
shareIntent.putExtra(Intent.EXTRA_TEXT, title);
shareIntent.setType("text/plain");
}
shareIntent.setPackage("com.whatsapp");
try {
startActivity(shareIntent);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(ManageOnlineBuyLeadActivity.this,
"Whatsapp have not been installed.", Toast.LENGTH_SHORT)
.show();
}
And for sharing particular recipant i have changed the follwing lines
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
to
Uri mUri = Uri.parse("smsto:+number");
Intent shareIntent = new Intent(Intent.ACTION_SENDTO, mUri);
But it is not working. For this i googled alot. So please guide me how to do this. Is it possible to share particular recipant or not?
Thank you all..
The easiest way I know is by calling the following method (Use the String variable message to input the text you want to send via WhatAapp):
private void sendWhatsapp(String message){
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, message);
sendIntent.setType("text/plain");
sendIntent.setPackage("com.whatsapp");
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(sendIntent);
}
}
I have a solution to send text only to a specific recipient. For sending an image to a specific recipient I am also using this.
String smsNumber = "Your specific contact No. here! ";
String msg = "Your message here!";
Uri uri = Uri.parse("http://api.whatsapp.com/send?phone="+smsNumber +"&text="+msg);
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
startActivity(intent);
} catch(Exception e) {
Toast.makeText(this, "Error/n" + e.toString(), Toast.LENGTH_SHORT).show();
}
I like share intent, it is perfect to open sharing apps with image and text parameters.
But now i'm researching the way to force share intent to open a specific app from the list, with the paramters given to the share intent.
This is my actual code, it shows the list of sharing apps installed on the phone. Please, can somedone tell me what i should add to the code to force for example official twitter app? and official faccebok app?
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse("file:///sdcard/test.jpg");
sharingIntent.setType("image/*");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "body text");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
Thanks
For Facebook
public void shareFacebook() {
String fullUrl = "https://m.facebook.com/sharer.php?u=..";
try {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setClassName("com.facebook.katana",
"com.facebook.katana.ShareLinkActivity");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "your title text");
startActivity(sharingIntent);
} catch (Exception e) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(fullUrl));
startActivity(i);
}
}
For Twitter.
public void shareTwitter() {
String message = "Your message to post";
try {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setClassName("com.twitter.android","com.twitter.android.PostActivity");
sharingIntent.putExtra(Intent.EXTRA_TEXT, message);
startActivity(sharingIntent);
} catch (Exception e) {
Log.e("In Exception", "Comes here");
Intent i = new Intent();
i.putExtra(Intent.EXTRA_TEXT, message);
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://mobile.twitter.com/compose/tweet"));
startActivity(i);
}
}
There is a way more generic to do that, and is not necessary to know the full package name of the application intent.
See this post:
How to customize share intent in Android?
100% Working solution
if you want to share something in any app you want or open a url via every action, just use this method:
private void shareOrViewUrlViaThisApp(String appPackageName, String url) {
boolean found = false;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(intent, 0);
if (!resInfo.isEmpty()){
for (ResolveInfo info : resInfo) {
if (info.activityInfo.packageName.toLowerCase().contains(appPackageName) ||
info.activityInfo.name.toLowerCase().contains(appPackageName) ) {
intent.setPackage(info.activityInfo.packageName);
found = true;
break;
}
}
if (!found)
return;
startActivity(Intent.createChooser(intent, "Select"));
}
}
and simply call:
shareOrViewUrlViaThisApp(<your package name>,<your url>);
This answer was inspired from this.