我尝试将我的应用程序放入应用程序计费 v3。
我跟着:http: //developer.android.com/google/play/billing/billing_integrate.html
我将我的应用程序上传到开发者控制台 3 天并设置在应用程序产品中。
我输入了我的 Base64 编码的 RSA 公钥和我的应用内产品 ID。
当我开始购买时,我收到错误消息。当我检查我的 RESPONSE_CODE 它的 5 和谷歌
应用内结算参考 ( http://developer.android.com/google/play/billing/billing_reference.html#billing-codes )
看来我的应用程序设置有问题。
当我尝试像 android.test.purchased 这样的谷歌测试 ID 时,我得到了很好的结果。
这是我的代码,也许我在这里做错了什么:
some_id is my test in app product id.
protected void onCreate(Bundle savedInstanceState) {
..
..
..
Helper = new IabHelper(this, base64EncodedPublicKey);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
Toast.makeText(getApplicationContext(), "connection bad",Toast.LENGTH_SHORT).show();
}
Toast.makeText(getApplicationContext(), "connection good",Toast.LENGTH_SHORT).show();
}
});
mServiceConn = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
mService = null;
}
@Override
public void onServiceConnected(ComponentName name,
IBinder service) {
mService = IInAppBillingService.Stub.asInterface(service);
}
};
bindService(new
Intent("com.android.vending.billing.InAppBillingService.BIND"),
mServiceConn, Context.BIND_AUTO_CREATE);
...
...
..
我的购买代码:
IabHelper.QueryInventoryFinishedListener
mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory)
{
if (result.isFailure()) {
// handle error
return;
}
String applePrice =
inventory.getSkuDetails("some_id").getPrice();
// update the UI
}
};
ArrayList<String> skuList = new ArrayList<String>();
skuList.add("some_id");
Bundle querySkus = new Bundle();
querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
Bundle skuDetails = new Bundle();
try {
skuDetails = mService.getSkuDetails(3, getPackageName(), "inapp", querySkus);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String sku = "some_id";
Bundle buyIntentBundle = new Bundle();
try {
buyIntentBundle = mService.getBuyIntent(3, getPackageName(), sku, "inapp", "j");
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
try {
startIntentSenderForResult(pendingIntent.getIntentSender(),1001, new Intent(), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
} catch (SendIntentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
Bundle ownedItems = mService.getPurchases(3, getPackageName(), "inapp", null);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}