How can I check if the Android Market is installed on my user's device?

和自甴很熟 提交于 2019-12-30 02:30:11

问题


How could I write a code which can tell me that android market is installed on your android phone?


回答1:


There are two ways. You can use the already mentioned getPackageManager() and getApplicationInfo() (if the package is not found, a PacketManager.NameNotFoundException will be thrown - see here). Android Market's package name is com.android.vending.

However, you can also create a dummy intent for searching the market and check how it is handled. If the resulting list has at least one entry, you can be sure that Android Market is installed:

Intent market = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=dummy"));
PackageManager manager = getPackageManager();
List<ResolveInfo> list = manager.queryIntentActivities(mmarket, 0);



回答2:


Here's what I did (assumes browser exists):

Intent market = new Intent(Intent.ACTION_VIEW).setData(Uri
        .parse("market://details?id=com.example.app"));


Intent website = new Intent(Intent.ACTION_VIEW).setData(Uri
        .parse("http://play.google.com/store/apps/details?id=com.example.app"));

try {

    startActivity(market);

} catch (ActivityNotFoundException e) {

    startActivity(website);

}


来源:https://stackoverflow.com/questions/7482036/how-can-i-check-if-the-android-market-is-installed-on-my-users-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!