Android 选择地点或尝试 return 时,地点选取器显示空白屏幕

Android Place Picker shows blank screen when place is selected, or when trying to return

我正在尝试在我的 android 应用程序中实施 Google 地图地点 API。

单击按钮后,它会打开地点选择器,选择器工作正常(您可以四处移动、放大和缩小、搜索并转到当前位置),直到您尝试单击 "Select this location" 按钮;单击该按钮时,将打开一个空白屏幕,唯一的选择是关闭该应用程序。 按下后退按钮时也会发生同样的情况(导航栏中的那个,或者 AppBar 中的那个)

Image: Inside the Place Picker Activity

Image: Blank Screen

几个星期前还好好的,后来就不行了,一天前又开始用了,今天又不行了。

打开地点选取器的代码:

    private void openPlacePicker() {
       Log.i(TAG, "open place picker");

       PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
       try { 
           startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);                          
       }
       catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
           e.printStackTrace();
       }
    }

是的,我在执行函数之前为 ACCESS_FINE_LOCATION 添加了权限检查。

代码 Activity 结果:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.i(TAG, "onActivityResult");
    if (requestCode == PLACE_PICKER_REQUEST) {
        if (resultCode == RESULT_OK) {
            final Place place = PlacePicker.getPlace(this, data);
    (...)

我的日志没有显示任何错误,并且未调用 OnActivityResult 日志:

D/libgps: proxy_gps_stop: called.
D/libgps: proxy_gps_status_cb: called.
D/libgps: proxy_gps_status_cb: called.
I/art: Background partial concurrent mark sweep GC freed 58725(4MB) AllocSpace objects, 23(2MB) LOS objects, 40% free, 14MB/23MB, paused 1.422ms total 101.850ms
D/gpsd: WakeLock(Release,GPSD)
I/Auth: [AuthDelegateWrapper] Service intent: Intent { cmp=com.google.android.gms/.auth.account.authenticator.DefaultAuthDelegateService }.
I/Auth: [AuthDelegateWrapper] Service intent: Intent { cmp=com.google.android.gms/.auth.account.authenticator.DefaultAuthDelegateService }.
I/Auth: [AuthDelegateWrapper] Service intent: Intent { cmp=com.google.android.gms/.auth.account.authenticator.DefaultAuthDelegateService }.
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
I/GCoreUlr: Successfully inserted 1 locations
I/WifiHAL: Got channel list with 11 channels
I/WifiHAL: Got channel list with 9 channels
I/WifiHAL: Got channel list with 13 channels
W/ActivityManager: Launch timeout has expired, giving up wake lock!

我的清单元数据和权限:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />

<application
    (...)

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="AIza(...)" />
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

我检查了 Google 控制台页面,包名和 SHA-1 指纹是正确的。 当我在 Overview > Google Maps APIs > Google Places API for Android > Usage 时,它​​显示没有任何使用情况,当它应该展示一些,因为正如我之前所说,一天前它正在工作并且我使用了它。

这个问题在我的 Nexus 9 (Android N) 和 Moto G3 (Android M) 上发生过。

注意:在 Moto G 上它会第一次工作,用户点击一个按钮,地点选择器打开,用户点击选择器的 "Select Location" 按钮,转到上一个 activity 一切正常;但如果他再次点击按钮打开选择器,并尝试再次点击选择器的 "Select Location" 按钮,他将进入空白屏幕,并且必须关闭应用程序并重试)。

TLDR; 当我尝试 select 某个位置或离开地点选择器 Activity.

时,我的 android 应用程序中的地点选择器进入空白屏幕

谢谢

正如我之前的评论所述,我今天早些时候遇到了完全相同的问题。 为我解决的是替换:

compile 'com.google.android.gms:play-services:9.0.0'

compile 'com.google.android.gms:play-services-location:9.0.0'

此更改是由

建议的

注意:如果您使用的不仅仅是 play-services 库中的 location,请确保包含其他组件,例如

compile "com.google.android.gms:play-services-games:9.0.0"
compile "com.google.android.gms:play-services-plus:9.0.0"
compile "com.google.android.gms:play-services-ads:9.0.0"

此错误 timeout has expired, giving up wake lock! 表示您的 Activity 启动时间过长。如果您在 UI 线程上进行大量处理,Android 会终止您的应用程序。您应该将 AsyncTask 用于任何处理密集型的东西。 Activity无法显示,因为它还在尝试完成执行;同时 ActivityManager 超时。

AsyncTask 可以正确和轻松地使用 UI 线程。 class 允许在 UI 线程上执行后台操作并发布结果,而无需操作线程 and/or 处理程序。

Asyntask 的示例实现:

private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
protected Long doInBackground(URL... urls) {
}

protected void onProgressUpdate(Integer... progress) {
}

protected void onPostExecute(Long result) {
}
}

对于选择位置时的黑屏,请确保您拥有 manifest file 中的权限。

uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/ >
uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>