How can I determine which application is the default application for a certain action? For example I want to know which application is used for making calls or receiving text messages. Is there any way to find out which application is set as default programmatically?
Asked
Active
Viewed 3,878 times
2 Answers
4
PackageManager.resolveActivity does something along the lines of what you're looking for. From the official docs:
Determine the best action to perform for a given Intent. This is how resolveActivity(PackageManager) finds an activity if a class has not been explicitly specified.
And here's an example:
Intent i = (new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.com")));
PackageManager pm = context.getPackageManager();
final ResolveInfo mInfo = pm.resolveActivity(i, 0);
Toast.makeText(
context,
pm.getApplicationLabel(mInfo.activityInfo.applicationInfo),
Toast.LENGTH_LONG
).show();
Note that the return value is somewhat fuzzy:
Returns a ResolveInfo containing the final activity intent that was determined to be the best action. Returns null if no matching activity was found. If multiple matching activities are found and there is no default set returns a ResolveInfo containing something else, such as the activity resolver.
-
I used ACTION_DIAL and was able to get the packageName of the dialer app. Thank you very much. Any idea how to find out which app is chosen as default SMS app? – theknut Apr 19 '14 at 19:29
-
You mean some specific action? Maybe ACTION_SENDTO, but I'm just guessing :) Glad I could help. – keyser Apr 19 '14 at 21:01
-
I tried ACTION_SENDTO but it's only for sending emails as far as I know. – theknut Apr 20 '14 at 05:46
-
1Does [this](http://stackoverflow.com/a/2372665/645270) help? It uses `setData` on the intent ACTION_VIEW. – keyser Apr 20 '14 at 11:17
-
Why if I use Intent i = (new Intent(Intent.ACTION_DIAL, Uri.parse("tel:0123456789"))) or Intent i = (new Intent(Intent.ACTION_DIAL)) is result allways System Android? – pudnivec74 Jul 28 '18 at 08:40
-
Did you try adding MATCH_DEFAULT_ONLY flag which insures to return the same activity as startActivity would? – yaugenka Jan 08 '20 at 10:23
1
Use Intent Filters and resolveActivity().
From Android's documentation on Intent Filters:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, textMessage);
sendIntent.setType(HTTP.PLAIN_TEXT_TYPE); // "text/plain" MIME type
ComponentName compName = sendIntent.resolveActivity();

Christian Cederquist
- 513
- 3
- 16
-
2Using your example I get "android" as compName.getPackageName(). Doesn't seem to work. Any idea? – theknut Apr 19 '14 at 19:13