我可以从其他应用程序查看最新版本的Play商店吗?

时间:2014-06-12 12:37:07

标签: android in-app-purchase google-play

在调用应用内服务之前,我如何检查移动设备中的Play商店是否可用以及是否是我的应用中的最新版本?

2 个答案:

答案 0 :(得分:1)

请尝试以下代码:

public boolean IsPlaystoreInstalled() {
    List<PackageInfo> packages = getApplication().getPackageManager().getInstalledPackages(0);
    for (PackageInfo packageInfo : packages) {
        if (packageInfo.packageName.equals("com.android.vending") ||
            packageInfo.packageName.equals("com.google.market")) {
            return true;
        }
    }
    return false;
}

答案 1 :(得分:0)

您可以检查设备上的Google Play服务是否可用,如下所示:

int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity());
switch(errorCode) {
    case ConnectionResult.SUCCESS:
        // Google Play Services installed and up to date
        break;

    case ConnectionResult.SERVICE_MISSING:
        // Google Play services is missing on this device.
        break;

    case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
        // The installed version of Google Play services is out of date.
        break;

    case ConnectionResult.SERVICE_DISABLED:
        // The installed version of Google Play services has been disabled on this device.
        break;

    case ConnectionResult.SERVICE_INVALID:
        // The version of the Google Play services installed on this device is not authentic.
        break;

    case ConnectionResult.DATE_INVALID:
        // The device date is likely set incorrectly.
        break;          
}

如果出现问题,您还可以显示相应的错误消息:

int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity());
if(GooglePlayServiceUtil.showErrorDialogFragment(errorCode, getActivity(), REQUEST_CODE)) {
    // There was a problem. Error dialog was shown.
} else {
    // Everything is fine. Error dialog was not shown.
}
相关问题