拜托,我对此感到疯狂。
我可以从我的一位测试人员那里购买,但我无法检索我的产品价格。
请参阅下面的“连接”代码:
//Binding Service
bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"),
mServiceConn, Context.BIND_AUTO_CREATE);
String base64EncodedPublicKey;
base64EncodedPublicKey = getString(R.string.baseEncodedPubKey);
// compute your public key and store it in base64EncodedPublicKey
mHelper = new IabHelper(this, base64EncodedPublicKey);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
// Oh noes, there was a problem.
Log.d("TMA Setup Billing", "Problem setting up In-app Billing: " + result);
}
// Hooray, IAB is fully set up!
else{
Log.d("TMA Setup Billing", "Ready to sell! OK!! " + result);
//Get the prices of inApps
Bundle teste = null;
ArrayList<String> teste1 = null;
getInAppsInfo(teste,teste1);
}
}
});
从上面的代码中,我收到了Ok消息,因此它正在连接......
问题在于以下代码:
//Func syncr to download prices
private synchronized void getInAppsInfo(final Bundle querySkus,final ArrayList<String> skuList) {
AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {
@Override
public String doInBackground(Void... params) {
ArrayList<String> skuList = new ArrayList<String>();
skuList.add(getString(R.string.prod1_maistempo));
Bundle querySkus = new Bundle();
querySkus.putStringArrayList("DETAILS_LIST", skuList);
String resposta = getString(R.string.naodisp);
try {
Bundle skuDetails = mService.getSkuDetails(3, getPackageName(), "inapp", querySkus);
int response = skuDetails.getInt("RESPONSE_CODE");
Log.d("TMA Synch Billing","response = " + response );
preco = preco + " " + response;
if (response == 0) {
Log.d("TMA Synch Billing","response = OK");
ArrayList<String> responseList = skuDetails.getStringArrayList("DETAILS_LIST");
for (String thisResponse : responseList) {
JSONObject object = new JSONObject(thisResponse);
String sku = object.getString("productId");
String price = object.getString("price");
Log.d("TMA Synch Billing","Sky e Price: " + sku + " " + price);
if (sku.equals(getString(R.string.prod1_maistempo))) resposta = price;
}
}
} catch (RemoteException e) {
// TODO Auto-generated catch block
Log.d("TMA Synch Billing","Error Remote: " + e.getMessage());
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.d("TMA Synch Billing","Error JSON: " + e.getMessage());
}
return resposta;
}
@Override
protected void onPostExecute(String result) {
preco = preco + " " + result;
}
};
task.execute();
}
这个功能正在返回5&gt;
(BILLING_RESPONSE_RESULT_DEVELOPER_ERROR 5
提供给API的参数无效。此错误还可能表示应用程序未正确签名或未正确设置为Google Play中的应用内结算,或者在其清单中没有必要的权限)
但是,我可以使用这个相同的设备(和我的所有测试人员的朋友一样),使用以下代码购买inApp:
//Yes button clicked, Start buy Activity
Bundle buyIntentBundle;
try {
buyIntentBundle = mService.getBuyIntent(3, getPackageName(),
getString(R.string.prod1_maistempo), "inapp", "buyer info");
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();
Log.d("TMA billing Buy "," Remote " + e.getMessage());
} catch (SendIntentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.d("TMA billing Buy "," SendIntent " + e.getMessage());
}
然后,我可以使用google中的示例来处理JSON字符串。
那么,你能告诉我在我的功能中我做错了什么来获得价格吗?非常感谢你们。
答案 0 :(得分:0)
您传入Bundle
的{{1}}有一个getSkuDetails
,其密钥为ArrayList<String>
,而不是ITEM_ID_LIST
(DETAILS_LIST
是DETAILS_LIST
响应ArrayList<String>
)中的Bundle