拜托,我快疯了。
我可以从我的一位测试人员那里购买,但我无法检索我的产品价格。
看,下面是“连接”的代码:
//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 > (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 字符串。
那么,你能告诉我我在获取价格的功能中做错了什么吗?十分感谢大家。