开发者

Check to see if user has a specific app on start

What is the easiest way to see if a user has a specific app in the Android Market, in my case Flash Player. If they don't have it I want to be able to take them to the Marke开发者_如何学编程t to download it before continuing on with the app. Thanks.


Here is a similar question about checking for Flash Player.

The relevant code (taken from Lior's answer) is this:

Intent intent = new Intent();
intent.setComponent(new ComponentName("com.adobe.flashplayer", "com.adobe.flashplayer.FlashExpandableFileChooser"));
PackageManager pm = getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
if (activities != null && activities.size() > 0)
{
    Toast.makeText(this, "Flash is installed!", Toast.LENGTH_LONG).show();
}
else
{
    Intent flashIntent = new Intent(Intent.ACTION_VIEW,Uri.parse("https://market.android.com/details?id=com.adobe.flashplayer"));
    startActivity(flashIntent);
}


I know this has been answered but here is how I implemented something similar:

Intent intent = getActivity().getPackageManager().getLaunchIntentForPackage("com.package.address");
if (intent != null) {
    // start the activity
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
} else {
    // bring user to the market
    // or let them choose an app?
    intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setData(Uri.parse("market://details?id="+"com.package.address"));
    startActivity(intent);
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜