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
Related
I have implemented the following code to share video:
// Copy video file to Fileprovider directory.
final String destFile = …
// Build FileProvider uri.
final Uri uri = FileProvider.getUriForFile(activity, AUTHORITY, destFile)
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
sendIntent.setType("video/*");
Log.d(TAG, "Sharing " + sendIntent.getType() + " for " + uri);
String title = "Share this content with";
Intent chooser = Intent.createChooser(sendIntent, title);
if (null != sendIntent.resolveActivity(activity.getPackageManager())) {
activity.startActivity(chooser);
}
This code works and shows the chooser. When I select a messaging app like Telegram, I get to pick the destination conversation, but the video is sent as a file attachment, meaning that users only see a document icon and need to download it and open externally. However, the same video, using the OS system gallery, will open Telegram into their video editor where they can cut/edit the media and when sent will be visible inline in the conversation.
What am I missing to get the same behaviour? Looking through Android git repositories I don't see anything different from this to share content, so I don't know what I'm missing. The log I get with this code looks like
Sharing video/* for content://com.app.android.fileprovider/share/video-a.mp4
So not only does it have the mime type but also the file extension could help. When I change the code to use a different mime type for images then I get the same behaviour, where the images get inlined into Telegram's chat.
For some reason the culprit was the FileProvider. Once I removed the FileProvider and passed in directly file:// URIs everything works.
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
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);
In my app, I have an option to share photos using standard Android sharing mechanism. When I choose gmail or yahoo mail, the sharing works, the images are displayed in the body of an email and are sent to the destination. When I choose Facebook, the images are displayed inside the Facebook activity where you can add a message, but when I hit the Done button, the upload process starts, but always fails.
The title of the message box is: "Facebook Upload Failed" and the message itself is: "Your upload could not be completed because we could not access your photo(s)."
Here is the code snippet for sharing:
mShareIntent = new Intent();
mShareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
mShareIntent.setType("image/jpeg");
mShareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
ArrayList<Uri> uris = new ArrayList<Uri>();
for(int i = 0; i < mImageUrls.size(); i++) {
uris.add(Uri.parse("file://"+mShareFiles[i].getAbsolutePath()));
}
mShareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(Intent.createChooser(mShareIntent, "Share Images To..."))
The photos are obviously accessible, since they are successfully processed by gmail and yahoo mail. And Facebook, itself, can access them, but not sent them.
As an experiment, I shared photos from the Android Gallery, in the Chooser, I chose Facebook, and the photos were successfully uploaded.
Does anyone have any idea what might be going on?
Thank You,
Gary
If the file is in your app's private directory (or even in its sd card directory in KitKat) then you might run into sharing issues. And FileProvider has its problems too.
The only reliable way I've found to share image files is to copy them to the external storage directory for pictures and sharing from there (you can create a .nomedia subdirectory to avoid them appearing in the Gallery app).
For example:
Bitmap bitmapToShare = ...
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
File pictureStorage = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File noMedia = new File(pictureStorage, ".nomedia");
if (!noMedia.exists())
noMedia.mkdirs();
File file = new File(noMedia, "shared_image.png");
saveBitmapAsFile(bitmapToShare, file);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
shareIntent.setType("image/png");
startActivity(shareIntent);
}
I have the following code in Android that programmatically adds a set of photos to a post that will be shared on Google+:
private void shareToGooglePlus() {
// Launch the Google+ share dialog with attribution to your app.
PlusShare.Builder share = new PlusShare.Builder(this);
for (String imageFilename : imageList) {
Uri imageUri = Uri.fromFile(new File(imageFilename));
share.addStream(imageUri);
}
share.setText("My images");
share.setType("image/jpeg");
startActivityForResult(share.getIntent(), 0);
}
Since I have a bunch of different images, I would like to add captions to each to describe what is in each picture. However, I can't seem to find a way to do that in with PlusShare.Builder. Does anyone know if it is possible and how to do it?
Thanx in advance.
That can't be done with PlusShare - the text refers to the primary post only.