解决Google官方PlacesPicker示例

时间:2016-03-21 04:33:52

标签: android google-play-services

我正在尝试Google的官方PlacesPicker示例。它运行并呈现第一个活动,但是当我点击按钮时,选择一个地方"它会暂时进入下一个活动,但在显示地图很短的时间后,它会返回到主要活动 当我查看日志时,它有两个我无法解决的问题是

第一个问题

Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.zze.zzb

我尝试通过将android.support.mulitdex.MultiDexApplication添加到我的清单来解决

<application
        android:allowBackup="true"
        android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher"
        android:theme="@style/AppTheme"
        android:name="android.support.multidex.MultiDexApplication">

我还将此添加到build.gradle

compile 'com.android.support:multidex:1.0.0'

其他已接受的解决方案也表明它可能与65k限制错误有关,因此我也选择仅将必要的google play服务添加到build.gradle

compile 'com.google.android.gms:play-services-measurement:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.google.android.gms:play-services-location:8.4.0'
compile 'com.google.android.gms:play-services-plus:8.4.0'

第二个问题

12934/com.example.google.playservices.placepicker E/GMPM: GoogleService failed to initialize, status: 10, Missing an expected resource: 'R.string.google_app_id' for initializing Google services.  Possible causes are missing google-services.json or com.google.gms.google-services gradle plugin.
03-21 11:29:02.583 12934-12934/com.example.google.playservices.placepicker E/GMPM: Scheduler not set. Not logging error/warn.
03-21 11:29:02.653 12934-13065/com.example.google.playservices.placepicker E/GMPM: Uploading is not possible. App measurement disabled

我在Stackoverflow中尝试了很多解决方案,但没有成功。 thisthisthis只是我尝试过的一些可接受的答案。

我确信api密钥有效,因为呼叫是在我的Google开发者控制台上注册的。令人沮丧的是,官方示例无法轻松编译和测试。有没有人遇到过这个问题,你是如何解决它们的?此外,如果您知道或拥有更好的Android Places API更新工作示例,请分享,我将非常感激。

更新1:我的显示文件

 <?xml version="1.0" encoding="UTF-8"?><!--
 Copyright 2013 The Android Open Source Project

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->


    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.google.playservices.placepicker"
        android:versionCode="1"
        android:versionName="1.0">

        <uses-sdk
            android:minSdkVersion="14"
            android:targetSdkVersion="19" />

        <!-- PlacePicker requires the ACCESS_FINE_LOCATION permission and a geo API key.
        See this page for more information on how to obtain an API key:
        https://developers.google.com/places/documentation/android/start
        -->
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

        <!-- PlacePicker also requires OpenGL ES version 2 -->
        <uses-feature
            android:glEsVersion="0x00020000"
            android:required="true" />

        <application
            android:allowBackup="true"
            android:label="@string/app_name"
            android:icon="@mipmap/ic_launcher"
            android:theme="@style/AppTheme"
            android:name="android.support.multidex.MultiDexApplication"
            >

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




            <meta-data
                    android:name="com.google.android.geo.API_KEY"
                    android:value="AIza..xxx...key.from.google" />



            <activity
                android:name=".MainActivity"
                android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>


    </manifest>

2 个答案:

答案 0 :(得分:0)

同样的问题也发生在我身上。我通过在strings.xml中提供正确的google_maps_key来解决它         以及google_maps_api.xml文件。

答案 1 :(得分:0)

添加此答案,因为可能其他人会发现它有用。

正如您在评论中提到的那样。

  

[1]添加适当的用户权限

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

还在应用程序标记

中添加这些行
<meta-data
   android:name="com.google.android.geo.API_KEY"
   android:value="@string/google_maps_key" />
  

[2]在google developer console中注册正确的软件包名称。清单文件中定义的包名称。 e.g!

package="com.example.xyz"
  

[3]仔细检查地方api是否正确启用了   适当的项目