【问题标题】:Google Place Picker not launching on some phonesGoogle Place Picker 未在某些手机上启动
【发布时间】:2017-05-12 04:45:06
【问题描述】:

我们遇到了 Google Place Picker 的问题,它无法在一部特定手机(运行 Android 6.0 的 MI Note 4)上启动,并引发异常对话框“不幸的是,Google Play 服务...”。

1) 代码正在我们拥有的所有测试手机上运行,​​除了这款手机,大约有 20 种不同的型号,从姜饼到牛轧糖。因此,权限和密钥似乎没有问题。 com.google.android.geo.API_KEY 正确放置在应用程序部分。

2) 这个问题尤其发生在这款手机上。 Google play 服务已安装在手机上,调用 GooglePlayServicesUtil.isGooglePlayServicesAvailable 会按预期返回 ConnectionResult.SUCCESS,我们会在启动地点选择器之前对其进行检查。

3) 另外,手机有游戏商店,谷歌地图运行良好,这进一步确认游戏服务正常。

4) 我们甚至尝试将 google play API 降级到 10.0.1 和 9.2.0 只是为了找到原因,但行为是相同的。

下面是代码,它是标准的地点选择器代码。

try {
     PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
     Intent intent = builder.build(this);
     startActivityForResult(intent, PLACE_PICKER_REQUEST);
 } catch (GooglePlayServicesRepairableException e) {
     GooglePlayServicesUtil
                    .getErrorDialog(e.getConnectionStatusCode(), this, 0);
 } catch (GooglePlayServicesNotAvailableException e) {
       Toast.makeText(this, "Google Play Services is not available.", Toast.LENGTH_LONG).show();
 } catch (Exception e) {
       Toast.makeText(this, "Google Play Services exception.", Toast.LENGTH_LONG).show();
 }

知道可能出了什么问题吗?

【问题讨论】:

  • logcat 中是否有任何异常记录可以发布?

标签: android google-places-api


【解决方案1】:

此问题是由 Google 服务引起的。谷歌服务需要更新。因此,只需在打开您的应用或地点选择器之前进行检查即可。

if (googlePlayApiStatus == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED)

如果返回真。向用户显示一个对话框以更新 Google 服务并粘贴以下代码以将用户带到 Google Play 商店以更新服务。

final String appPackageName = "com.google.android.gms";
try {
/*IT WILL OPEN IN GOOGLE PLAY STORE*/
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
}
catch (android.content.ActivityNotFoundException anfe) {
/*IF GOOGLE PLAY STORE APP NOT FOUND IN DEVICE IT WILL OPEN IN WEB BROWSER*/
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}

就是这样!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-06
    • 2015-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多