I have an activity that opens the image picker. When starting the gallery the selection intent opens and you are able to choose a photo, this works sometime and on some devices but other times does not work and closes the Activity instead of calling OnActivityResult (The application appears to be backgrounded, but upon reopening the application restarts)
When it does succeed everything works as expected.
I have tried this:
Button menu_upload = menu.FindViewById<Button>(Resource.Id.menu_upload);
menu_upload.Click += (o, e) =>
{
var imageIntent = new Intent();
imageIntent.SetType("image/*");
imageIntent.PutExtra(Intent.ExtraAllowMultiple, true);
imageIntent.SetAction(Intent.ActionPick);
StartActivityForResult(Intent.CreateChooser(imageIntent, "Select Image"), REQUEST_IMAGE_CAPTURE_MULTI);
// ALSO TRIED THIS WITH SAME RESULT
/*var imageIntent = new Intent();
imageIntent.SetType("image/*");
imageIntent.SetAction(Intent.ActionGetContent);
StartActivityForResult(
Intent.CreateChooser(imageIntent, "Select photo"), REQUEST_IMAGE_CAPTURE_MULTI);*/
};
It seems looks like the activity is being destroyed when it's backgrounded. How do I do this correctly? Or How do I get the chooser to resume to my activity after the image has been chosen?
I have checked out the other articles on this topic but I am unable to get anything to work.
The activity that was attempting to launch the picker was launched with an android:noHistory flag set. This means that when the picker is launched and the parent activity is no longer on the screen it is closed by Andriod.
More info can be found in the official documentation here:
Official Android Activity Documentation
Related
How can we start the gallery app in Android without telling it which file to display?
This is because I want to show images in an album/folder. However, I understand there is no such function. So, I would like to just start the gallery app.
ACTION_VIEW will always result in an "unsupported file" message, if there is no URI specified, or if MediaStore.Images.Media.EXTERNAL_CONTENT_URI is specified. This is bearable, but not desirable, as it tells the user something is wrong with my app.
ACTION_PICK works partially, but the later half is not what I want. I want the user to choose images, and see the chosen images in the gallery. The gallery should not return the URI to my app, and expect my app to display it. There is a reason for this, that is, I want the user to be able to switch from one image to another without returning to my app. The user should return only after he/she has decided not to view anymore image.
The code that I have tried :
intent = new Intent (Intent.ACTION_VIEW);
intent.setType ("image/*");
startActivity (intent);
intent = new Intent (Intent.ACTION_PICK,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivity (intent);
Any suggestion?
I've got several problems.
I have a task to provide different map applications to a user when he pushes a button.
I do it by creating an Intent.createChooser. Everything works fine until the user install application "Zoom" for online meeting. And it's literally not what user expects to see in the dialog of apps and obviously he can't use it as map application.
I create an Uri with coordinates, put it to the Intent with ACTION_VIEW. Like this:
val mapIntent = Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=53.9000,27.5667"))
Then i create Intent chooser:
val chooser = Intent.createChooser(mapIntent, "Build a route with:")
And then I start Activity with chooser: startActivity(chooser)
And then I get a wrong app "Zoom" in this dialog:
WRONG DIALOG SCREENSHOT
The first question is:
Maybe there are some ways to see how actually Zoom App appears in this dialog and why my Intent receives this app activity?
The second problem is a case how I try to solve the first one. So I tried to use queryIntentActivities for my Map Intent and see in Log what activities are suitable for my Intent. It should return me a list of all activities that Intent chooser shows me, but in fact it returns me only one! activity MapsActivity:
val pm: PackageManager = packageManager
val activityList = pm.queryIntentActivities(mapIntent, MATCH_ALL) //or MATCH_BY_DEFAULT, no difference
activityList.forEach {
Log.d("ACTIVITY MAP", it.toString())
}
And in Log it shows next info:
D/ACTIVITY MAP: ResolveInfo{6c40733com.google.android.apps.maps/com.google.android.maps.MapsActivity m=0x208000}
Only one MapsActivity is shown... Where is the others Activities that shown to me in the Intent chooser?
In my app I run camera intent to take picture with photo App, with this code below:
Activity activity;
File currentPhotoFile;
Intent capturePhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri uri = GenericFileProvider.getUriForFile(activity, activity.getPackageName() + providerSufixName, currentPhotoFile);
capturePhoto.putExtra(MediaStore.EXTRA_OUTPUT, uri);
activity.startActivityForResult(capturePhoto, REQUEST_PHOTO);
And after that I catch the created photo in my activity.onActivityResult function in Activity
If I have only one! photo App on my mobile device - everything works fine.
But! If I installed on my device one more! photo application - the code above is not working :(
In case two photo apps, when I call activity.startActivityForResult - I see andoid system dialog with list of all available photo apps. (like Intent.createChooser calling). I select from it, preferable photo app and tap "JUST ONCE". Selected application runs, I take picture inside it and press Ok button for returning back to my App.
At this moment I recieve callback to my onActivityResult with my code: REQUEST_PHOTO but with requestCode = RESULT_CANCELED. And that's all :(
Why it's not working?
And how I can resolve this issue and use camera intent with more than one photo application?
The problem was that in manifest I have option:
android:launchMode="singleInstance" for my activity.
<activity
android:name="MyActivity"
android:launchMode="singleInstance"
>
For solving above issue you should remove singleInstance option from manifest file (or replace it within singleTask option).
This is resolve the issue and onActivityResult is properly working.
Hi in my app I have a dialog that asks if they would like to turn on my accessibility service if it is off. If they hit okay it launches an intent to open to accessibility like this
Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
startActivityForResult(intent, 0);
This works fine however if they hit home from accessibility and then open my app again it doesn't show the dialog or anything but opens directly to accessiblity everytime. The only way to get around it is to hit back till I'm back at my home screen then reopening the app no longer opens to accessibility.
Why does it keep launching my old intent unless I back out? Why can't I hit back and then it not launch the intent again
Thanks for any help
Use flag FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivityForResult(intent, 0);
However if the user launch your app from the history list, it will still show up.
I think the problem is that your activity is still waiting for a result.
If so, calling forceFinish() in your onResume() should fix the problem.
http://developer.android.com/reference/android/app/Activity.html#finishActivity%28int%29
I am using this code
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
photoPickerIntent.setType("image/*");
photoPickerIntent.setAction(Intent.ACTION_GET_CONTENT);
photoPickerIntent.addCategory(Intent.CATEGORY_OPENABLE);
photoPickerIntent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(Intent.createChooser(photoPickerIntent, "Image File Picker"), 1000);
to pick image from sdcard within my application.
this is working fine, according to my requirement i need to close that ACTION_PICK chooserActivity myself, like when we touch outside the dialog that will closed fine...
but how can we close this type of dialog programmatically?
You can't.
That chooser is actually a separate activity, launched by intent (which will then launch another activity via intent when the user selects something).
You don't control that chooser, its not actually in your app.