问题描述
这是检查设备上安装的软件包的一个简单的事情......以前我我的操作系统升级到2.3.5,我可以找到市场/ Play商店,使用这种code:
私有静态最后弦乐GooglePlayStorePackageName =com.google.market;
无效的someMethod(){
packageManager = getApplication()getPackageManager()。
名单< PackageInfo>包= packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
对于(PackageInfo packageInfo:包){
如果(packageInfo.packageName.equals(GooglePlayStorePackageName)){
googlePlayStoreInstalled = TRUE;
打破;
}
}
}
由于某些原因,更新后,我根本无法找到打包的名字,表示安装了应用程序,虽然它是在设备上,我可以进入市场。
的包名称改变?或者我在看这个错误的方式?
谢谢
亚当。
更新:
这是一个愚蠢的方法来检查是否安装了包...一个更好的方法是:
保护最终布尔isPackageInstalled(字符串的packageName){
尝试 {
。application.getPackageManager()getPackageInfo(的packageName,0);
}赶上(的NameNotFoundException E){
返回false;
}
返回true;
}
该包的名称发生了变化,现在是com.android.vending
尝试:
私有静态最后弦乐GooglePlayStorePackageNameOld =com.google.market;
私有静态最后弦乐GooglePlayStorePackageNameNew =com.android.vending;
无效的someMethod(){
PackageManager packageManager = getApplication()getPackageManager()。
名单< PackageInfo>包= packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
对于(PackageInfo packageInfo:包){
如果(packageInfo.packageName.equals(GooglePlayStorePackageNameOld)||
packageInfo.packageName.equals(GooglePlayStorePackageNameNew)){
googlePlayStoreInstalled = TRUE;
打破;
}
}
}
This was a simple matter of checking the installed packages on the device... before I've upgraded my OS to 2.3.5, I could locate the Market/Play store, using this code:
private static final String GooglePlayStorePackageName = "com.google.market";
void someMethod() {
packageManager = getApplication().getPackageManager();
List<PackageInfo> packages = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
for (PackageInfo packageInfo : packages) {
if (packageInfo.packageName.equals(GooglePlayStorePackageName)) {
googlePlayStoreInstalled = true;
break;
}
}
}
For some reason after the update, I simply cannot find the to package name to indicate the application is installed, although it is on the device, and I can access the market.
Has the package name changed? or perhaps I'm looking at this the wrong way?
Thanks,
Adam.
UPDATE:
That was a stupid way to check if a package is installed... a better way is:
protected final boolean isPackageInstalled(String packageName) {
try {
application.getPackageManager().getPackageInfo(packageName, 0);
} catch (NameNotFoundException e) {
return false;
}
return true;
}
The package name has changed, it is now com.android.vending
Try:
private static final String GooglePlayStorePackageNameOld = "com.google.market";
private static final String GooglePlayStorePackageNameNew = "com.android.vending";
void someMethod() {
PackageManager packageManager = getApplication().getPackageManager();
List<PackageInfo> packages = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
for (PackageInfo packageInfo : packages) {
if (packageInfo.packageName.equals(GooglePlayStorePackageNameOld) ||
packageInfo.packageName.equals(GooglePlayStorePackageNameNew)) {
googlePlayStoreInstalled = true;
break;
}
}
}
这篇关于无法确定谷歌Play商店中是否安装或没有在Android设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!