i want to share something with my friends. so i preferred android share intent.
i used,
Intent i=new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_TEXT, "my share text");
startActivity(Intent.createChooser(i, "share via"));
this showing a list of available apps like Facebook, Twitter, Gmail, Message, Skype.. e.t.c..
If i pressed a Twitter in the sense, the above text "my share text" showing in the tweet text box.
But if i select Facebook, the status message not showing.
i want to set the status message programatically.
how can i achieve this?
Facebook SDK has this bug, it's pretty annoying, I know. But if you set a link (and only a link) as "my share text", it will appear in the facebook share box.
I just built this code and it's working for me:
private void shareAppLinkViaFacebook() {
String urlToShare = "YOUR_URL";
try {
Intent intent1 = new Intent();
intent1.setClassName("com.facebook.katana", "com.facebook.katana.activity.composer.ImplicitShareIntentHandler");
intent1.setAction("android.intent.action.SEND");
intent1.setType("text/plain");
intent1.putExtra("android.intent.extra.TEXT", urlToShare);
startActivity(intent1);
} catch (Exception e) {
// If we failed (not native FB app installed), try share through SEND
Intent intent = new Intent(Intent.ACTION_SEND);
String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare;
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
startActivity(intent);
}
}
Facebook does not allow the pre populating of text in the status box like as twitter. But we can pass the text with url to the Facebook. And it appears below the status box. check below code.
NOTE : Use Facebook SDK to share [ Recommended ].
Native share through intent
Intent shareIntent= new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "http://www.google.com");
shareIntent.setType("text/plain");
shareIntent.setPackage("com.facebook.katana");
startActivity(shareIntent);
Share through Facebook SDK
ShareDialog shareDialog;
// Sharing in Facebook using the SDK
FacebookSdk.sdkInitialize(this);
shareDialog = new ShareDialog(this);
String title = "Demo Title";
String URL = "http://www.google.com";
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle(title).setContentDescription(URL)
.setContentUrl(Uri.parse(URL)).build();
shareDialog.show(linkContent);
Check the link below for reference.
Link 1
Let me know for queries or clarification.
Related
I want to share an image from android activity to facebook messenger app which is already opened in my device and reside in recent tasks of the android device.
I am using the below code to share the image but it is opening a new activity in messenger 'share seperately' but I want to share it to the already opened chat.
String mimeType = "image/*";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setPackage("com.facebook.orca");
intent.setType(mimeType);
intent.putExtra(Intent.EXTRA_STREAM, contentUri);
intent.putExtra(EXTRA_PROTOCOL_VERSION, PROTOCOL_VERSION);
intent.putExtra(EXTRA_APP_ID, YOUR_APP_ID);
activity.startActivityForResult(shareIntent, SHARE_TO_MESSENGER_REQUEST_CODE);
Facebook has restricted the text sharing over the post. It will either support a valid URL link sharing or Image Sharing. So I've posted the code which is referenced from https://stackoverflow.com/a/22994833/8331006
private void shareAppLinkViaFacebook(String urlToShare) {
try {
Intent intent1 = new Intent();
intent1.setClassName("com.facebook.katana", "com.facebook.katana.activity.composer.ImplicitShareIntentHandler");
intent1.setAction("android.intent.action.SEND");
intent1.setType("text/plain");
intent1.putExtra("android.intent.extra.TEXT", urlToShare);
startActivity(intent1);
} catch (Exception e) {
// If we failed (not native FB app installed), try share through SEND
String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
startActivity(intent);
}
}
Here is the code I'm using to share a tweet :
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.setPackage("com.twitter.android");
intent.putExtra(Intent.EXTRA_TEXT, "My text");
startActivity(intent);
This opens a popup enabling the user to share it by Tweet or by Direct Message, when I only want it to be shared by tweet. How can I do that?
Thank you very much.
Try this :
Intent tweet = new Intent(Intent.ACTION_VIEW);
tweet.setData(Uri.parse("http://twitter.com/?status=" + Uri.encode(message)));// replace message by your string message
startActivity(tweet);
Why I can't set a text when I'm sharing on facebook?
I have this code:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
String str = "My Text\n" + "http://play.google.com/store/apps/details?id=com.google.android.apps.maps";
shareIntent.putExtra(Intent.EXTRA_TEXT, str);
List<ResolveInfo> matches = getPackageManager().queryIntentActivities(shareIntent, 0);
for (ResolveInfo info : matches) {
if (info.activityInfo.packageName.toLowerCase().contains("com.facebook.katana")) {
shareIntent.setPackage(info.activityInfo.packageName);
startActivity(shareIntent);
break;
}
}
And it works, but only the link appears. Anyone Knows what is wrong?
(I don't want to use Facebook SDK.)
Thanks
Bad facebook! :-(
This is impossible, Because of you don't want use Facebook SDK.
You have to use the actual official separate Facebook Android SDK in your project to get the full sharing functionality. Which is extra work.
Change your decision, then see this:
https://developers.facebook.com/docs/sharing/android
ShareDialog shareDialog;
FacebookSdk.sdkInitialize(getApplicationContext());
shareDialog = new ShareDialog(UserProfileActivity.this);
ShareLinkContent content1 = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse("https://Your url"))
.setContentTitle("name of content")
.setContentDescription("description")
.setImageUrl(Uri.parse("img url"))
.build();
shareDialog.show(content1);
I am trying to use the shareintent in my app but I ran into a problem when sharing a link to facebook, no images is shown with the preview. So tried customizing the android shareintent so that it uses the share functionality from facebooksdk when facebook is selected but I can't seem to get it working. Below is the code that I tried for customizing the shareintent,
Intent share = new Intent(android.content.Intent.ACTION_SEND);
PackageManager pm = getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(share, 0);
for (final ResolveInfo app : activityList) {
if (app.activityInfo.packageName.toLowerCase().startsWith("com.facebook.katana")) {
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentTitle(property.PropertyName)
.setImageUrl(Uri.parse(property.ImagePath))
.setContentUrl(Uri.parse(property.PropertyPermaLink))
.build();
ShareDialog shareDialog = new ShareDialog(this);
shareDialog.canShow(content);
break;
} else {
share.setType("text/plain");
share.addFlags(share.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
share.putExtra(Intent.EXTRA_SUBJECT, "");
share.putExtra(Intent.EXTRA_TEXT, property.PropertyPermaLink);
startActivity(Intent.createChooser(share, "Share property!"));
}
}
After debugging the above code I found that the activitylist only consists of a single element. So how can I resolve this issue?
You need to add the Mime data type that the send intent is handling to get the appropriate activities returned:
share.setType("text/plain");
Just try SharePhotoContent instead of ShareLinkContent.
If you want using ShareLinkContent, please be sure that property.ImagePath pointed to real http image link. If link contain https check that is working in default android browser app.
I'm developing an android application and I want to can share in a tweet a picture. I search for tutorials and all of them have to authentificate the user before can post a tweet. Is there any way to use the account that's stored on your phone instead of authenticating the user again?
I don't want to have a share button, I want that like in iPhone can post a tweet.
If anyone know of other toturial that works and it's better please tell me, I don't want a share button, only I want to tweet.
Thanks
Use shareIntent, as described here:
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, theObject.getName());
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://mobile.twitter.com/"));
startActivity(i);
}
}