简体   繁体   English

当使用`FusedLocationApi`时,android在`LocationServices.API`和`Auth.GOOGLE_SIGN_IN_API`之间发生冲突

[英]android clashed between `LocationServices.API` and `Auth.GOOGLE_SIGN_IN_API` when using `FusedLocationApi`

I have code setGoogleSignInAccount like this 我有这样的代码setGoogleSignInAccount

mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();

and i have code for get location using FusedLocationApi like this 而且我有使用FusedLocationApi这样获取位置的代码

Location mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
                            mGoogleApiClient);

and it's work but my question is now when i click logout error because .addApi(LocationServices.API) when i changes to .addApi(Auth.GOOGLE_SIGN_IN_API, gso) the logout is success but now the FusedLocationApi is error 它是可行的,但是现在我的问题是当我单击注销错误时,因为当我更改为.addApi(Auth.GOOGLE_SIGN_IN_API, gso)时, .addApi(LocationServices.API)可以成功注销,但是现在FusedLocationApi是错误的

and this logcat when FusedLocationApi error 和这个logcat当FusedLocationApi错误时

07-17 11:58:16.763 26607-26607/com.emergency.e_place E/AndroidRuntime: FATAL EXCEPTION: main
                                                                       Process: com.emergency.e_place, PID: 26607
                                                                       java.lang.NullPointerException: Appropriate Api was not requested.
                                                                           at com.google.android.gms.common.internal.zzx.zzb(Unknown Source)
                                                                           at com.google.android.gms.common.api.internal.zzj.zza(Unknown Source)
                                                                           at com.google.android.gms.location.LocationServices.zzi(Unknown Source)
                                                                           at com.google.android.gms.location.internal.zzd.getLastLocation(Unknown Source)
                                                                           at com.emergency.e_place.MainActivity$1.onClick(MainActivity.java:166)
                                                                           at android.view.View.performClick(View.java:4646)
                                                                           at android.view.View$PerformClick.run(View.java:19403)
                                                                           at android.os.Handler.handleCallback(Handler.java:733)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                           at android.os.Looper.loop(Looper.java:146)
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5511)
                                                                           at java.lang.reflect.Method.invokeNative(Native Method)
                                                                           at java.lang.reflect.Method.invoke(Method.java:515)
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
                                                                           at dalvik.system.NativeStart.main(Native Method)

when i changes to .addApi(Auth.GOOGLE_SIGN_IN_API, gso) the logout is success 当我更改为.addApi(Auth.GOOGLE_SIGN_IN_API,gso)时,注销成功

Don't change. 不要改变 Add. 加。

mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                // Add more APIs, as needed
                .build();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Auth.GOOGLE_SIGN_IN_API不能与Games.API一起使用 - Auth.GOOGLE_SIGN_IN_API cannot be used with Games.API java.lang.IllegalStateException:使用Auth.GOOGLE_SIGN_IN_API时不得在GoogleApiClient.Builder中设置范围 - java.lang.IllegalStateException: Must not set scopes in GoogleApiClient.Builder when using Auth.GOOGLE_SIGN_IN_API LocationRequest和LocationServices.API未解决 - LocationRequest and LocationServices.API are not resolved LocationServices.API 在此设备上不可用 - LocationServices.API is not available on this device Google Play服务LocationServices.API - 新选项“never” - Google Play Services LocationServices.API - new option “never” 我必须为Drive.API和Auth.GOOGLE_SIGN_IN_API创建2个Google Api客户端吗? - Do i have to create 2 Google Api Client for Drive.API and Auth.GOOGLE_SIGN_IN_API? 无法解析符号GOOGLE_SIGN_IN_API。.我的应用程序中的Google登录,无法访问变量Auth.GOOGLE_SIGN_IN_API - Cannot resolve symbol GOOGLE_SIGN_IN_API.. Google sign-in in my app, Unable to access variable Auth.GOOGLE_SIGN_IN_API 在Android应用和API之间使用Google登录 - Using Google sign in between Android app and api Android LocationServices.FusedLocationApi 已弃用 - Android LocationServices.FusedLocationApi deprecated Android Studio模拟器在LocationServices.fusedLocationApi上崩溃 - Android Studio Emulator crashes on LocationServices.fusedLocationApi
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM