尝试在我的应用中实现应用内购买 v3 时,我看到了 null 异常。以下是我的代码:
mServiceConn = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
mService = null;
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mService = IInAppBillingService.Stub.asInterface(service);
}
};
MainActivity.this.bindService(new Intent(
"com.android.vending.billing.InAppBillingService.BIND"),
mServiceConn, Context.BIND_AUTO_CREATE);
try {
System.out.println("mService " + mService);
Bundle buyIntentBundle = mService
.getBuyIntent(
3,
getPackageName(),
"android.test.purchases",
"inapp",
"aaa");
PendingIntent pendingIntent = buyIntentBundle
.getParcelable("BUY_INTENT");
startIntentSenderForResult(pendingIntent.getIntentSender(), 1001,
new Intent(), Integer.valueOf(0), Integer.valueOf(0),
Integer.valueOf(0));
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SendIntentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我看到的例外是服务为空。我放在代码中的 sysout 正在打印 null。以上所有代码都是我活动的 onCreate 方法的一部分。任何指针?