Reputation: 2553
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?
Upvotes: 2
Views: 4200
Reputation: 19189
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.
Upvotes: 5
Reputation: 513
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();
And here's the documentation on ComponentName
Upvotes: 1