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);
Related
I have installed Pinterest SDK using pinterst developer site in my android studio project and register app in developers account.I can't find out sources that can share the images in developer console.how can I share image just like facebook and twitter using sdk?
I have shared image using below code.
private void shareOnPinterest() {
String sharingText = "Sharing Text";
String imageUrl = "Image Url";
String description = "Description";
String url = String.format(
"https://www.pinterest.com/pin/create/button/?url=%s&media=%s&description=%s",
urlEncode(sharingText), urlEncode(imageUrl), description);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
filterByPackageName(getActivity(), intent, getString("com.pinterest"));
startActivity(intent);
} else {
Utils.displayDialog(getActivity(), getResources().getString(R.string.error_somthing_went_wrong));
}
}
Hope this will help you!
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 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 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.
I'm attempting to add a shared intent to post to Google Plus and can't seem to resolve the issue of passing the new ShareCompat.IntentBuilder (Android support library class) to the startActivity method. I'm started out using this example. My app is compiled using Android 2.2 platform. Is it possible that there is another supporting way to start the Activity to launch the shared intent.
IntentBuilder shareIntent = ShareCompat.IntentBuilder.from(MyActivity.this);
shareIntent.setText(message);
shareIntent.setSubject(subject);
if (mFullFileName != null) {
File imageFile = new File(mFullFileName);
if (imageFile.exists()) {
shareIntent.setStream(Uri.fromFile(imageFile));
shareIntent.setType("image/jpeg");
}
} else {
shareIntent.setType("*.*");
}
shareIntent.getIntent();
// doesn't compile only accepts Intent and not the Intentbuilder
startActivity(shareIntent);
Thats an example from my code, but if you want some reference material tap on the hyperlink for an article.
public void shareText(String text) {
String mimeType = "text/plain";
String title = "Example title";
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
.setType(mimeType)
.setText(text)
.getIntent();
if (shareIntent.resolveActivity(getPackageManager()) != null){
startActivity(shareIntent);
}
}
Blog post on ShareCompat.IntentBuilder and sharing intents
ShareCompat.IntentBuilder.from(ActivityName.this) is deprecated, use the constructor of IntentBuilder like this:
Kotlin:
ShareCompat
.IntentBuilder(this#YourActivity)
.setType("text/plain")
.setChooserTitle("Share text with: ")
.setText("Desired text to share")
.startChooser()
Java:
new ShareCompat
.IntentBuilder(YourActivity.this)
.setType("text/plain")
.setChooserTitle("Share text with: ")
.setText("Desired text to share")
.startChooser();
Funny, I just figured it out... the example given was suppose create an Intent and not an IntentBuilder object.. had to change my code to chain the object creation.
Intent i = ShareCompat.IntentBuilder.from(MyActivity.this)
.setText(message)
.setSubject(subject)
.setStream(Uri.fromFile(imageFile))
.setType("image/jpeg")
.getIntent()
.setPackage("com.google.android.apps.plus");