Prevent auto choose which sharing application use - android

I'm develop an application in Android.
I have a ListView with some image, when I click a row I open ContextMenu and I have two Choise, eliminate the image or sharing with other application.
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/*");
Uri r = Util.getImageUri(getActivity().getApplication(), image);
intent.putExtra(Intent.EXTRA_STREAM, r);
startActivity(intent);
I use this code to sharing the image, but after the first time, every time that I try to share image, the application choose always the first application with wich I send the first image.
How can I prevent it?
I want that user choose every time sharing application.
Thanks.
t

I use this code to sharing the image, but after the first time, every time that I try to share image, the application choose always the first application with wich I send the first image.
That was because you indicated, to the chooser, that you wanted to make this choice "always", instead of "just once".
I want that user choose every time sharing application
Use:
startActivity(Intent.createChooser(intent, "..."));
where "..." is your explanation for this.

In your phone go to settings-->Apps then select the app which get opens by default then there you will find an option "Open by default" open that option, in there press "Clear Defaults".
Then in your app again you will get the list of application to share with

Related

How to get callback of ACION_SEND Intent

I tried this
private void postImage(Uri uri) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/*");
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.putExtra(Intent.EXTRA_TEXT, "My bracelet image");
intent.putExtra(Intent.EXTRA_TITLE, "Action Bracelet");
intent.putExtra(Intent.EXTRA_STREAM,uri);
Intent chooser=Intent.createChooser(intent,"Share Image Using");
try{
context.startActivity(chooser);
}
catch(ActivityNotFoundException e){
Toast.makeText(context,"You don't have any share application installed",Toast.LENGTH_SHORT).show();
Log.e("Image Load","failed");
}
}
Now my problem is i need the application name on which this image is shared .I also created my custom dialog for it but problem remains same . Because when i select an option for share like facebook and i pressed back button then image is not share and i only know that the user click on facebook.
so i need a callback which gives me result_ok and result_cancle and the application name too . Can anyone help me i am stuck here from last three days ...
Now my problem is i need the application name on which this image is shared
If your minSdkVersion is 22 or higher, use the createChooser() that takes an IntentSender as the third parameter, as that is your only means of finding out what the user chose.
If your minSdkVersion is below 22, you will have to create your own chooser-style UI, using PackageManager and queryIntentActivities() to find out what activities should be listed in that UI.
I also created my custom dialog for it but problem remains same
You certainly know what the user chose in the dialog. That is all you are going to get from the API Level 22 createChooser() either.
Because when i select an option for share like facebook and i pressed back button then image is not share and i only know that the user click on facebook.
Of course. The user can do whatever the user wants in that other application. The user does not have to press BACK; the user can simply fail to send anything. That is between the user and that application — information about whether the user did anything, who the user shared the information with, and so on, is not available to you.

Android photoviwer VIEW intent only showing 1 image

In my android app, I create an intent to display an image in the photogallery app.
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file:///storage/sdcard0/arin/category/1/1.png"), "image/*");
context.startActivity(intent);
This opens the photo app and shows that image but only that image...
I know there are other images in the same folder. But the app wont let swipe left/right and switch images. How can I change the code so it will let me see the other pics in the same folder...
Thanks
How can I change the code so it will let me see the other pics in the same folder
Write your own "photogallery" code.
There are hundreds, perhaps thousands, of apps that are capable of responding to your Intent. None of them have to offer any means to "swipe left/right and switch images". If you want a specific set of behaviors, write them yourself. If you want the user to be able to view the image in the user's chosen app, then stick with your existing code and do not worry about the behavior of the user's chosen app.

Detecting the target application when sending an Intent

I am sharing image by using the send intent(ACTION_SEND).
I want to know if any application is selected for sharing or not. How can I do that and how do I know if the image was sent successfully?
Code I have used to share image is here :
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
share.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(imageSharePath)));
startActivity(Intent.createChooser(share, "Share Image"));
You need to implement your own dialog for the activity selection.
To create such dialogs you need to use PackageManager.queryIntentActivities(). This method returns List<ResolveInfo>.
ResolveInfo contains some information about an activity (e.g. resolveInfo.activityInfo.packageName), and with the help of PackageManager you can get other information (useful for displaying the activity in the dialog) - application icon drawable, application label, etc.
Display the results in a list in a dialog (or in an activity styled as a dialog). When an item is clicked create new Intent.ACTION_SEND, add the content you want and add the package of the selected activity intent.setPackage(pkgName).
The answer above is no longer correct.
Since API 22 it is possible to detect the target application when the user shares.
For details see:
Get IntentSender object for createChooser method in Android
https://medium.com/code-with-lisa/get-results-from-android-chooser-9cfc5445a871

Intent.ACTION_VIEW does not allow edit in gallery app

I have an app which wants to view an image in the gallery app.
I use this code to view it:
File cachedImage = cache.getFile(image.getImageUrl());
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(cachedImage), "image/*");
startActivity(intent);
This works except when I click the edit setting here:
and I get the no apps can perform this action message:
Is there some way to make this work? Do I need to pass additional extras? I know the Gmail app is able to view an image attachment in the gallery and the edit function works. This is on JellyBean.
Is there some way to make this work?
Install an app that can edit pictures. Your screenshots appear to be of the Gallery app, which is presumably trying to use ACTION_EDIT to start an activity to edit the picture, and there is no such activity available.

What is createChooser when I have to use Intents? What I could do with this method?

I have been taking a look over stackoverflow but I did't find a definition about what is "createChooser" and why I can use and in whick kind of situations is good to use it.
Thanks in advance.
For example: you have a share picture option in your application.
You define an intent like this:
Intent picMessageIntent = new Intent(android.content.Intent.ACTION_SEND);
picMessageIntent.setType("image/jpeg");
File downloadedPic = new File(
Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS),
"q.jpeg");
picMessageIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(downloadedPic));
Than when you call:
startActivity(picMessageIntent);
all applications on your phone capable of getting this picture will be listed.
If you want to custimize the title of that list, you can use createChooser like this:
startActivity(Intent.createChooser(picMessageIntent, "Send your picture using:"));
When startActivity(intent) is called for the first time from your app the user sees a list of all apps capable to handle this intent.
There is also an option to always handle this intent using one of the apps from the list. If this option is used then the list will never be shown again.
If you use createChooser in your intent then the "always use this app" option is not shown. The user always sees this list.
This method is used when you want to create a Custom Action using an Intent... Just like what android provides ACTION_VIEW etc... but here when there are multiple choices to perform an an Action this chooser will bring up a dialog which will have all available options and let the user select one... here is an example

Categories

Resources