Currently i am working on an app where there is an option to share text from the app to different Social network like Google, Instagram,Facebook etc. All are working fine except facebook where it picks up wrong random thumbnails. The code for sharing is like below:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
if (Preferences.getBoolean(getString(R.string.pref_copyWithShareUrl_key), getResources().getBoolean(R.bool.pref_copyWithShareUrl_default)))
{
shareIntent.putExtra(Intent.EXTRA_TEXT, verse.getText() + "\n\n" + "http://play.google.com/store/apps/details?id=" + getPackageName());
//shareIntent.putExtra(Intent.EXTRA_TEXT, verse.getText() + "\n\n" + " https://market.android.com/search?q=pname:" + getPackageName());
}
else
{
shareIntent.putExtra(Intent.EXTRA_TEXT, verse.getText());
}
Currently the sharing look like this:
But what i want is to include my app launchers image icon to be shared only. How can i achieve that without affecting the other share option.
Thanks
Use ShareLinkContent provided by facebook to share
Related
I am creating an application where I can share a link to the applications available in the android devices and increase the share count but I am unable to get any response or onActivityResult for that intent.
For now I have just increased the counter when ever the button is clicked for sharing the link but that's not a correct way to do it.
I am using the below code to share the link
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "\n" + text + "\n\n" + "www.google.com");
shareIntent.setType("text/plain");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
mContext.startActivity(Intent.createChooser(shareIntent, "Share Link using ?"));
Any help is appreciable thank you.
Quoting #CommonsWare in #ndsmyter answer comments
The decision of what happens as part of an ACTION_SEND operation is up
to the other app (and the user), not you. ACTION_SEND is not designed
for use with startActivityForResult(), which is why you are not
getting results, and startActivityForResult() has no bearing on the
behavior of the other app.
So as you see, is not possible :(
Hope this helps!!
I am using the below mention code to share on GPLUS. It is sharing successfully on emulator and on several other devices.
Intent shareIntent = new PlusShare.Builder(ActivityDetail.this)
.setType("text/plain")
.setText(
offer.title + " - "
+ J.Funcs.decode(offer.description_detailed))
.setContentUrl(Uri.parse(offer.image)).getIntent();
startActivityForResult(shareIntent, 1);
But the problem is, it is crashing on sharing. Any idea what I have done wrong?
I am trying to post a link on facebook with the native android sharing function. I found out that i can't set the message for the link. But now i want to set the title, message and the url.
I want to set the items in the red square. I already found out I couldnt set the Test, because of the user policies.
Some code:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TITLE, title);
shareIntent.putExtra(Intent.EXTRA_TEXT, title + "\n\n" + contentLink);
shareIntent.setType("text/plain");
return shareIntent;
This is the code I have at this moment, but this doesnt set the items in the red square.
Text Sharing :
Using Android Intent Share for Facebook you can't share pre-populated text. This is blocked by facebook itself due to platform policy. Checkout section 2.3 in the below linl
https://developers.facebook.com/policy
Link Sharing :
You can share a link. Facebook will automatically fetch the link metadata. i.e a image, meta title and meta description.
Image Sharing :
User images can be shared. Which means you can share images stored on your device. You cannot share images from your app directly without saving them. As a hack, you can save the image on device, share and delete the image (if you don't want image to appear in user's gallery).
Use this code to share only link. Facebook will automatically fetch the link metadata. i.e, image, meta title and meta description.
String urlToShare = "--------URL-------";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, urlToShare);
// See if official Facebook app is found
boolean facebookAppFound = false;
List<ResolveInfo> matches = getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo info : matches)
{
if (info.activityInfo.packageName.toLowerCase().startsWith("com.facebook"))
{
intent.setPackage(info.activityInfo.packageName);
facebookAppFound = true;
break;
}
}
if (!facebookAppFound)
{
String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare;
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
}
startActivity(intent);
I can easily share a text in Google+ but when i want to add a picture with the text, i got this message ;
You can only post media items stored in your device.
Here is my code:
Uri uri = Uri.parse("android.resource://com.smurf.fapiao/" + R.drawable.myimage);
// Launch the Google+ share dialog with attribution to your app.
Intent shareIntent = new PlusShare.Builder(getActivity())
.setType("image/png").setStream(uri)
.setText(getString(R.string.social_googleplus_text) + " http://www.wangwanglotto.com")
.getIntent();
startActivityForResult(shareIntent, 0);
Do you have any idea ? I tried to put the file in raw or assets folder, but i still get the message.
Thanks in advance
I want to add a feature in an android app to share url via email & facebook , I am using following piece of code ,
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, title);
shareIntent.putExtra(Intent.EXTRA_TEXT, content );
shareIntent.setType("text/plain");
startActivity(Intent.createChooser(shareIntent,"Share article"));
While sharing it via email I want content string to contain
content = someurl + ( Shared via MyApp )
whereas while sharing via Facebook I want to use
content = someurl
as Facebook refuses to recognize the url if I add anything to it .
can anyone help me with problem as how I can achieve both ?