How to let user know he/she needs to install another app that my app depends on
I am developing an application which has defined some intent filters (in the form of action strings, eg com.example.project.UPLOAD) for other applications to use. Consider a device that didn't have my application but with applications that use my intent filters, the Intent created will fail the action test as described in the documentation. Is there any way to prevent this happening or give a better user experience? Here are some of the approaches I can think of but don't know if there are feasible:
What is the best approach to handle this? Please provide some implementation references if possible.
Aside from mentioning it in the Marketplace, I'm not sure how you'd go about presenting messages during the application installation, as (to my knowledge) there is no supported way to execute code upon installation.
If other applications use your filters, then it's up to them to make sure your package is installed. You can't really give them anything without being installed.
They can test to see if a package is installed using the PackageManager, and adjust their logic to notify the user when they need to install your package. Example:
private boolean isInstalled(){
ComponentName comp = new ComponentName("com.yourpackagestuff", "com.yourpackagestuff.TestClass");
Intent intentName = new Intent().setComponent(comp);
List <ResolveInfo> list = ctx.getPackageManager().queryIntentActivities(intentName, PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}
That's how I'd go about it, at least.
You can try calling the Intent and catch the ActivityNotFoundException
if it is thrown. If it does get thrown, you know it doesn't exist so you can implement your backup code.
This solution is quicker Android check for dependent application during installation?
getPackageManager().getApplicationInfo("com.myproject", 0 );
No exception means its ok
链接地址: http://www.djcxy.com/p/7214.html