开发者

How to let user know he/she needs to install another app that my app depends on

开发者 https://www.devze.com 2023-03-07 10:53 出处:网络
I am developing an application which has defined some intent filters (in the form of action strings, e.g. com.example.project.UPLOAD) for other applications to use. Consider a device that didn\'t have

I am developing an application which has defined some intent filters (in the form of action strings, e.g. 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:

  1. While installing an application that depends on another applications to handle some of the intents, suggest user 开发者_StackOverflow中文版to install the application that can handle the intent
  2. Dynamically determine if the intent can be handled. If not, launch the market showing the application that can handle the intent

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

0

精彩评论

暂无评论...
验证码 换一张
取 消