I want to check if my application is set as the default application for the Intents I'm handling inside my App.
As an example ff more than one application supports to open a specified file format. I need to make my application as a default application from my code. How it possible to make my application a default (from the code)? Can anyone help me?
At least I would like to check this on startup of my app and redirect the user to fill in some information if my App is not set as the default on the device.
As far as I know this is not possible. That dialogue is handled by the system - your app will only be launched if the user picks your app from the list.
Allowing such a behaviour would impact the user's ability to control their default applications, and from a technical point of view would mean a process and its memory would have to be allocated to every app in the list every time such a list appeared.
You could use this method:
public static boolean isOurAppDefault(Context context) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com"));
ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(browserIntent,PackageManager.MATCH_DEFAULT_ONLY);
String defaultBrowserPkg = null;
if (resolveInfo != null) {
if (resolveInfo.activityInfo != null) {
defaultBrowserPkg = resolveInfo.activityInfo.packageName;
}
}
return TextUtils.equals(context.getPackageName(), defaultBrowserPkg);
}
It's actual for some editor or browser. In other case use different Uri data for intent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With