Google为多个开发人员提供API

时间:2018-04-12 08:41:00

标签: android google-api google-places-api

我们是一个在Android应用程序上合作的团队 不幸的是,只有那个使用google places API编写代码才能运行活动,而其他人则无法运行。 我们遇到了与google maps API相同的问题,但这是因为我们都使用了相同的API密钥。
更改API密钥(每个人自己的密钥)后,问题就停止了 这是导致崩溃的代码(再次,写活动的人设法运行它)

public void refreshPlacesData() {
        Uri uri = PlaceContract.PlaceEntry.CONTENT_URI;
        Cursor data = getContentResolver().query(
                uri,
                null,
                null,
                null,
                null);

        if (data == null || data.getCount() == 0) return;
        List<String> guids = new ArrayList<String>();
        while (data.moveToNext()) {
            guids.add(data.getString(data.getColumnIndex(PlaceContract.PlaceEntry.COLUMN_PLACE_ID)));
        }
        PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi.getPlaceById(mClient,
                guids.toArray(new String[guids.size()]));     <---this is where it crash
        placeResult.setResultCallback(new ResultCallback<PlaceBuffer>() {
            @Override
            public void onResult(@NonNull PlaceBuffer places) {
                mAdapter.swapPlaces(places);
                mGeofencing.updateGeofencesList(places);
                if (mIsEnabled) mGeofencing.registerAllGeofences();
            }
        });
    }



这是错误

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.rubz.dvir.rubz, PID: 25203
                  java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { (has extras) }} to activity {com.rubz.dvir.rubz/com.rubz.dvir.rubz.JobRequestActivity}: java.lang.NullPointerException: GoogleApiClient must not be null
                      at android.app.ActivityThread.deliverResults(ActivityThread.java:3382)
                      at android.app.ActivityThread.handleSendResult(ActivityThread.java:3425)
                      at android.app.ActivityThread.access$1300(ActivityThread.java:139)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1248)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:136)
                      at android.app.ActivityThread.main(ActivityThread.java:5105)
                      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:792)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
                      at dalvik.system.NativeStart.main(Native Method)
                   Caused by: java.lang.NullPointerException: GoogleApiClient must not be null
                      at com.google.android.gms.common.internal.zzbq.zza(Unknown Source)
                      at com.google.android.gms.common.api.internal.zzm.<init>(Unknown Source)
                      at com.google.android.gms.location.places.zzm$zzb.<init>(Unknown Source)
                      at com.google.android.gms.location.places.zzm$zzc.<init>(Unknown Source)
                      at com.google.android.gms.location.places.internal.zzl.<init>(Unknown Source)
                      at com.google.android.gms.location.places.internal.zzh.getPlaceById(Unknown Source)
                      at com.rubz.dvir.rubz.JobRequestActivity.refreshPlacesData(JobRequestActivity.java:445)
                      at com.rubz.dvir.rubz.JobRequestActivity.onActivityResult(JobRequestActivity.java:515)
                      at android.app.Activity.dispatchActivityResult(Activity.java:5467)
                      at android.app.ActivityThread.deliverResults(ActivityThread.java:3378)
                      at android.app.ActivityThread.handleSendResult(ActivityThread.java:3425) 
                      at android.app.ActivityThread.access$1300(ActivityThread.java:139) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1248) 
                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                      at android.os.Looper.loop(Looper.java:136) 
                      at android.app.ActivityThread.main(ActivityThread.java:5105) 
                      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:792) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608) 
                      at dalvik.system.NativeStart.main(Native Method) 
Application terminated.

1 个答案:

答案 0 :(得分:1)

您可以将多个 SHA-1&#39; 添加到您的地点api,转到cloud console

然后选择Google Places Api,限制您的Api,然后添加SHA

enter image description here

希望这有帮助