Android Intent choose set default app - java

I am working on an android app and when a user clicks on a link and/or file, I want to give them the choice of choosing which app they want to use to open that link and/or file. At the moment it works the way it was intended to, but I am having trouble trying to let the user select a checkbox which lets them choose the default app to open that file with so they won't have to keep selecting it each time. I was thinking of having a checkbox in the dialog and then committing the value of it to the Shared prefs along with the app choice. After that, each time they click that file, the default app will be opened. In essence I am trying to get a dialog like this one,
But I keep getting this one,
Here is the code:
Intent intent = new Intent(Intent.ACTION_VIEW).setDataAndType(uri, mimeChoice);
startActivity(Intent.createChooser(intent,getActivity().getString(R.string.open_with_title)));

like tambykojak point out, the "The Android OS will take care of this depending on the Intent you've constructed" and thereĀ“s no option for default app. But you will construct your own custom dialog by gettin the apps installed determined by the package:
for example:
Facebook: "com.facebook.katana"; Whatsapp: "com.whatsapp"; Twitter: "com.twitter.android"; Google Playstore: "com.android.vending"; Chrome: "com.android.chrome" etc...
And saving the "default" option in preferences.
More info:
How to force Share Intent to open a specific app?
How to filter specific apps for ACTION_SEND intent (and set a different text for each app)

Related

Android Settings permissions not not acting as they should

I need to ask for permission from the user. One of the permissions I need is ACTION_MANAGE_OVERLAY_PERMISSION and the other is Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION. When asking for it as you can see in the code below, it takes the user to the Settings screen so the user could tick the permission from there.
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, OVERLAY_PERMISSION_REQUEST_CODE);
On some Android phones and Android versions, it takes the user straight to the specific application setting (the app that it is called from) on other devices it opens up the list of applications from which the user has to find the app and then tick the permission. In most cases on Androids lower than 10 it opens up the specific app settings window and when it's 10 or higher, it opens up the list.
Is there a way to make it consistently open the current application setting that is open?
I tried adding:
intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse("package:" + getApplicationContext().getPackageName()));
But that did not help either.
And secondly, is there a way to ask for this and other Settings permissions without opening the Settings menu and instead of doing it in a dialog inside the application?
If not then is there a way to ask for multiple Settings permissions one after another because my application requires two Settings type permissions.
EDIT
Here is what I meant by the specific application settings vs the list.
On the left picture, all apps are listed and on the right picture the specific app is opened (happens if you click on the app in the list).
Now in some cases, it directly opens the right picture but mostly it opens the left. Is there a way to force open the right picture at all times?
Is there a way to force open the right picture at all times?
No.
The Settings app usually is modified substantially by the device manufacturer. They can do whatever they want. This includes ignoring the Uri or outright removing third-party access to this screen, where the latter is what the documentation is warning against:
In some cases, a matching Activity may not exist, so ensure you safeguard against this.
If you make your own Android firmware, you could ensure that this Intent action behaves as you want, for whatever devices run your firmware.

Launch any maps app on Android

I want to create an Intent in my Android app that launches a map application with a specified address in response to the user clicking on the button. It is straightforward enough to do this with Google Maps, as is explained here.
However, I was wondering what the correct way to do this would be in order to launch any maps application (i.e., not necessarily Google Maps). This way, if the user prefers a different maps application, it would open in their app of choice instead.
For example, to launch the user's preferred calendar application, one sends an Intent to com.android.calendar, and it opens whichever calendar application is the default, not necessarily Google Calendar.
Use a geo: URI, as stated here. Disappointingly, this does not provide a mechanism for launching directly into turn-by-turn navigation.

Android - 'Complete action using' keeps showing even after selecting 'Always'

I'm trying to use an intent to browse for images. I managed to get my code working but the only problem is that every time I choose the browse file button, the app always shows the pop up dialog 'Complete action using' even after Always is selected.
I still want the user to select from the available app installed and set it as default when 'always' is selected.
Do I need to programmatically save the user's choice? I have only tested this in Genymotion's emulator (Android's Studios emulator is very slow in my laptop) and my Lenovo S820 Android 4.4.2. Is it a specific bug in my phone or am I missing something? Thank you in advance.
I have searched everywhere and found this similar
question, but it's also unanswered.
I am calling my intent like this:
public Intent browse(){
Intent getterIntent = new Intent(Intent.ACTION_GET_CONTENT);
getterIntent.addCategory(Intent.CATEGORY_OPENABLE);
getterIntent.setType("image/*");
return getterIntent;
}

Open Another App with android.intent.action.VIEW

I want to open another app and open a specific page in it!
in their guide they said to use the bellow for default action
android.intent.action.VIEW
and use a kind of intent, which didn't get which, like bellow to go to that specific page:
somecompany://details?id=com.example.calendar
but i don't know how!
And i tryed a ton of solutions but coudn't do it !
Thanks for your help.
I think this is what you're asking for. This will open a specific app's page in the Google Play store.
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(
"market://details?id=com.mycompany.mypackage")));
Don't replace the word market. That is specifically reserved by Android to open the Google Play store.
You can launch an app using intents. But to go to a specific page in the app, there should be a pre defined intent to reach there. Either it can be custom intent defined by that app and exposed to others or may be predefined system app. For example, you can open Settings application and reach a particular page in it based on the intents "Setting Application" has defined. Another example is "Camera Application". You can launch it and reach some page in it but not all pages.
In your case you may try something like this though:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "video/mp4");
I hope you understand what I meant.

Customizing a share dialog

I'm trying to obtain a share dialog similar to the one below for sharing some plain text with a preselected list of apps (email, Facebook, Twitter, Google+). The problem is that if I launch an intent to share text, the dialog has too many apps.
1) Can I explicitly choose the apps shown in the dialog?
2) If not, I can make a custom dialog. If so, can I specifically choose an app to launch and provide it with my intent? for each dialog option, I'd launch a specific app. First item - email, second item - facebook etc.
1) Can I explicitly choose the apps shown in the dialog?
You cannot modify this list that the OS creates with the app chooser. (I'm guessing that all of these apps accept the very common data type "text/plain".)
2) If not, I can make a custom dialog. If so, can I specifically choose an app to launch and provide it with my intent? for each dialog option, I'd launch a specific app. First item - email, second item - facebook etc.
As far as building your own custom list, you need to consider a few points:
You could create Intents that explicitly open the GMail and Facebook apps, but some users don't use these particular apps. Instead you should display apps that accept specific data types (or MIME types).
Email apps have a specific MIME type: "message/rfc822", but some don't use it. You might be safer using "text/plain".
I am unaware of any specific Facebook MIME type, you will have to use "text/plain" anyways. Alternatively, you could use the PackageManager to search every installed appfor the string "facebook", however a third party Facebook app might not have this string in its package name....
If you are going to use the "text/plain" data type then you will end up with the list that the OS already automatically created for you...
What you want to do is not impossible, but it is harder than it sounds. In the end you accidentally might exclude the user's favorite app from your customized list...
(Android has an insightful blog on this subject: Sharing with Intents.)

Categories