更新时间:2022-06-01 21:54:46
有两种方式。您可以使用已经提到 getPackageManager()
和 getApplicationInfo()
(如果没有找到包, PacketManager.NameNotFoundException
将被抛出 - 见here). Android电子市场中的包名是 com.android.vending
。
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
.
不过,你也可以创建一个虚拟的意图用于搜索市场,并检查它是如何处理的。如果结果列表至少有一个入口,你可以肯定的是Android Market的安装:
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);