使Play Services 4.3中的Address API生效的问题

时间:2014-05-13 06:32:02

标签: android google-play-services

我已在我的项目中设置了Google Play Services 4.4库,并且我一直试图让地址选择器显示出来。以下是调用API(javadoc)的活动代码:

GoogleApiClient client = new GoogleApiClient.Builder(this).addApi(Address.API).useDefaultAccount().build();
client.connect();
Address.requestUserAddress(client, null, 1000);

这是我的onActivityResult代码:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 1000 && resultCode == RESULT_OK) {
        UserAddress address = UserAddress.fromIntent(data);
        Toast.makeText(this, address.toString(), Toast.LENGTH_LONG).show();
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

每当我运行应用程序时,都没有显示选择器,logcat会显示:

05-13 14:30:43.204: D/AddressRetreiver(2489): Is cached profile null?true
05-13 14:30:43.212: W/GLSUser(2505): GoogleAccountDataService.getToken()
05-13 14:30:43.212: W/GLSActivity(2505): [apc] Status from wire: BadUsername status: BAD_USERNAME
05-13 14:30:43.216: E/GetWalletProfileTask(2489): [<<default account>>:1]GoogleAuthException when getting auth token

有人看到这段代码有什么问题吗?

更新:

我正在使用安装了GApps的模拟器。我尝试了一种设备,但也没有用。然后,我从useDefaultAccount()电话中删除了GoogleApiClient.Builder。这适用于我的设备,但不适用于我的模拟器。虽然现在Google Play服务崩溃了以下日志:

05-14 12:17:38.265: E/AndroidRuntime(10184): FATAL EXCEPTION: main
05-14 12:17:38.265: E/AndroidRuntime(10184): Process: com.google.android.gms.ui, PID: 10184
05-14 12:17:38.265: E/AndroidRuntime(10184): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.android.gms/com.google.android.gms.wallet.address.RequestUserAddressActivity}: java.lang.NullPointerException: null reference
05-14 12:17:38.265: E/AndroidRuntime(10184):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2215)
05-14 12:17:38.265: E/AndroidRuntime(10184):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2265)
05-14 12:17:38.265: E/AndroidRuntime(10184):    at android.app.ActivityThread.access$800(ActivityThread.java:145)
05-14 12:17:38.265: E/AndroidRuntime(10184):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1206)
05-14 12:17:38.265: E/AndroidRuntime(10184):    at android.os.Handler.dispatchMessage(Handler.java:102)
05-14 12:17:38.265: E/AndroidRuntime(10184):    at android.os.Looper.loop(Looper.java:136)
05-14 12:17:38.265: E/AndroidRuntime(10184):    at android.app.ActivityThread.main(ActivityThread.java:5149)
05-14 12:17:38.265: E/AndroidRuntime(10184):    at java.lang.reflect.Method.invokeNative(Native Method)
05-14 12:17:38.265: E/AndroidRuntime(10184):    at java.lang.reflect.Method.invoke(Method.java:515)
05-14 12:17:38.265: E/AndroidRuntime(10184):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
05-14 12:17:38.265: E/AndroidRuntime(10184):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
05-14 12:17:38.265: E/AndroidRuntime(10184):    at dalvik.system.NativeStart.main(Native Method)
05-14 12:17:38.265: E/AndroidRuntime(10184): Caused by: java.lang.NullPointerException: null reference
05-14 12:17:38.265: E/AndroidRuntime(10184):    at bkm.a(SourceFile:27)
05-14 12:17:38.265: E/AndroidRuntime(10184):    at com.google.android.gms.wallet.address.RequestUserAddressActivity.onCreate(SourceFile:106)
05-14 12:17:38.265: E/AndroidRuntime(10184):    at android.app.Activity.performCreate(Activity.java:5231)
05-14 12:17:38.265: E/AndroidRuntime(10184):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-14 12:17:38.265: E/AndroidRuntime(10184):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
05-14 12:17:38.265: E/AndroidRuntime(10184):    ... 11 more

似乎是图书馆的一个问题。

0 个答案:

没有答案