I have programmatically added Google+ sharing to my app. I have a set of photos that I include with my posts and share with the following code:
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);
}
When this code gets executed, the Google+ app on my phone is started and I get a preview that has the images and text as expected.
However, if I run this more than once and include different images on subsequent runs, the original images show up in the Google+ post preview instead of the new ones. If I submit the post, the correct images show up in the post--the new ones, not the original ones.
I presume the Google+ app has some kind of caching mechanism. Is there a way to programmatically clear that cache so that the correct images show up in the Google+ app post preview?
Thanx in advance.
Try assigning different random names to your source files (by renaming or copying) on each run
Related
I am working with a project where the user will be able to share a product from my app to facebook. In this action, the user will edit the following data:
The quote/description of the product.
Set a place for the post.
Share an image from my app gallery.
When the user shares my product it generates a standard hashtag, and the user may select a place for check in.
Here is the image of the desired action.
Sharing product on Facebook
So i followed several tutorials on youtube and the documentation from facebook so i managed to use SharePhoto and Share Link with success. In my share button im using share link and setting the following properties :
String url_link_loja = "www.centauro.com.br";
ShareHashtag.Builder hashtag = new ShareHashtag.Builder();
hashtag.setHashtag("#Olympikus");
String url_imagem = "https://static.olympikus.com.br/produtos/tenis-olympikus-thin-2-feminino/91/D22-0304-791/D22-0304-791_zoom1.jpg?resize=1200:*";
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse(url_imagem_test))
.setQuote(url_link_loja)
.setImageUrl(Uri.parse(url_imagem))
.setShareHashtag(hashtag.build())
.setPlaceId("Avenida Paulista")
.build();
shareDialog.show(linkContent);
Then, when i share with my app i get just a thumbnail of the image instead of a full sized image.
Share Dialog on Nexus xl
When i use Share Photo instead, i get the full image on the dialog window just the way i want, however it seems its not possible to add hashtag and quote on this object. I tried to fix this using open graph, so i used the book example from the documentation and tried do add image, but when i do, i get a callback error message that dos not specifies the problem( i already checked, its not the commom namespace error).
So, i need some advice on the matter, any insight will be helpful.
As the title suggests, i'm having an option to upload an image in my app.
I would like to have two options: Click a new picture & Select from gallery.
Gallery selection is working fine on all devices using this code:
Intent in = new Intent();
in.setType("image/*");
in.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(in, getString(R.string.selectpicture)), 100);
The problem is with Click a new picture.
I want to use other camera apps installed on the device to get the image.
This code should save the image user clicks at the specified path.
Intent m_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageUri = getImageUri();
m_intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(m_intent, REQUEST_IMAGE_CAPTURE);
But what happens is, the EXTRA_OUTPUT is not respected by all camera apps.
Also if memory is low, my app is killed by the system which makes things more complicated.
So, what's the best way to enable user to click a new picture and get the image path in my app?
If using third party libraries is better, which one's are reliable?
the EXTRA_OUTPUT is not respected by all camera apps.
Any time you delegate anything to a third party app, you can run into problems.
Also if memory is low, my app is killed by the system which makes things more complicated.
You need to handle this anyway. Save the value you put in EXTRA_OUTPUT in the saved instance state Bundle.
what's the best way to enable user to click a new picture and get the image path in my app?
If you wish to stick with ACTION_IMAGE_CAPTURE, I'd go with this triage:
If there is an image in the location you provided to EXTRA_OUTPUT, use it
If not, and getData() on the Intent given to you in onActivityResult() returns a Uri (and not null), use that (and if you truly need a File, use ContentResolver and openInputStream() with the Uri and copy the contents into your own file)
If neither are true, and getParcelableExtra("data") returns a value, save that Bitmap to a file
If none of those are true, suggest to the user to get a different camera app, perhaps pointing them to one that you have tried and know works
Or, take the picture yourself, directly or using a library like mine.
In my camera app for Android i would like to share a photo taken by the user to the user's facebook wall. I would like it has:
a text description written by the user (like in a shareDialog)
the image taken with my camera app
the link to the image itself in the album (to swipe to the previously uploaded ones)
some text (caption+description) about my app
a link to my app (with icon?) in google play
Here's a picture of what i want: (tweet-to-facebook posts are very similar to this, so i think it can be done!)
How to achieve this?
Should i use Open Graph?
I tried following developers.facebook tutorials, but i failed!! i think samples are buggy! It's very frustrating...
Please help, i need someone to show me the right way!
EDIT
actually this is my code, no foto is shown:
private void shareWithFacebookOpenGraph(String pathToImage) {
Log.i("SHARE", "1. share with OpenGraph");
OpenGraphObject photo = OpenGraphObject.Factory.createForPost("myapp:photo");
photo.setProperty("title", "MyApp Photo");
photo.setProperty("image", "http://play.google.com/to_my_app_launcher_icon");
photo.setProperty("url", "http://play.google.com/to_my_app");
photo.setProperty("description", "Image taken with myApp for Android");
List<File> files = new ArrayList<File>();
files.add(new File(pathToImage));
OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class);
action.setProperty("photo", photo);
FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(this, action, "myapp:take", "photo")
//.setImageAttachmentFilesForObject("image", files, true) // Error: image is not a property
//.setImageAttachmentFilesForAction(files, true) // Error sharing pictue: null
//.setImageAttachmentFilesForObject("photo", files, true) // can't create Collection (?!?!)
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
}
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.
I'm writing an app that uses the camera. I want to lauch an intent to allow users to annotate the resulting image with lines and text, AND I would like to provide the user with a list of appropriate image editting apps they can use, but I'm coming across these problems:
1. Not all image editting apps appear in the list when I perform this code:
editIntent = new Intent();
editIntent.setAction(Intent.ACTION_EDIT);
Uri imageToEditUri = selectedPhotoLocation; // Uri of existing photo
String imageToEditMimeType = "image/*";
editIntent.setDataAndType(imageToEditUri, imageToEditMimeType);
startActivityForResult(Intent.createChooser(editIntent,"Edit Image"), IMPLICIT_EDIT_IMAGE);
Is there a way to get a list of apps that will respond to Intent.ACTION_EDIT?
2. PS Express is the only app I've found that returns the Uri of the editted image in the data.getDate() Uri returned to OnActivityResult(), with other apps the user is forced to save, remember the location, and reselect the editted image.
Is there a way to know what apps return the Uri of the image to OnActivityResult()
Not all image editting apps appear in the list when I perform this code
Just because an app implements image editing does not necessarily mean that it is set up to allow third parties to link to their image-editing activities.
Is there a way to get a list of apps that will respond to Intent.ACTION_EDIT?
If you mean that you want to do this programmatically at runtime, see Jedil's answer.
Is there a way to know what apps return the Uri of the image to OnActivityResult()
No, except for those applications that have documentation on how developers should integrate with them.
First question answer:
try queryIntentActivities
Intent editIntent = new Intent(android.content.Intent.ACTION_EDIT);
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(editIntent, 0);