アプリにアプリ内購入を含めることはできますが、アプリ内課金サービスにアクティビティをバインドすることはできません。IabHelperのアプリ内課金サービスをバインドしない
私はすでに物理デバイスでhttps://developer.android.com/training/in-app-billing/preparing-iab-app.html
のデバッグは、私は問題がIabHelperクラスの次のコマンドであることがわかっページに記載されたすべての手順で行われている:私は気づい
mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
をプログラムがServiceConnectionインスタンスの2つのメソッドのいずれかで停止しない、つまりonServiceConnected()またはonServiceDisconnected()で停止しないために動作しない
私のアクティビティで同じコマンドを直接使用し、アプリ内課金サービスとのバインドが成功しました。
したがって、アクティビティから要求されたバインドは動作していますが、IabHelperクラスから要求されたときには動作していません。
私の質問は、IABHelperクラスの課金サービスに自分のアクティビティをバインドするにはどうすればいいですか?ここで
がIabHelperからstartSetupメソッドを呼び出すコードです:
mHelper = new IabHelper(this, publicKey);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener()
{
@Override
public void onIabSetupFinished(IabResult result)
{
if(!result.isSuccess())
{
mHelper=null;
return;
}
if (mHelper == null) return;
}
});
これは、サービスに結合するIabHelperクラス内のコードです:
Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
serviceIntent.setPackage("com.android.vending");
List<ResolveInfo> intentServices = mContext.getPackageManager().queryIntentServices(serviceIntent, 0);
if (intentServices != null && !intentServices.isEmpty())
{
// service available to handle that Intent
mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
}
そして、ここでは、私が使用したコードですアクティビティから直接サービスにバインドする:
private IInAppBillingService mService;
ServiceConnection mServiceConn = new ServiceConnection()
{
@Override
public void onServiceDisconnected(ComponentName name)
{
mService = null;
}
@Override
public void onServiceConnected(ComponentName name,IBinder service)
{
mService = IInAppBillingService.Stub.asInterface(service);
}
};
Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
serviceIntent.setPackage("com.android.vending");
this.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
ご協力いただきありがとうございます
IabHelperクラスの 'mContext'は何ですか?それは "instanceof"活動ですか? – AADProgramming