1
拜託,我對此感到瘋狂。從Android的inApp中檢索價格
我可以從我的一位測試員處購買產品,但我無法檢索到我的產品的價格。
見,下面是「連接」的代碼:
//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();
}
這funcion將返回5> (BILLING_RESPONSE_RESULT_DEVELOPER_ERROR 5
參數無效p rovided到API。此錯誤還可能表示應用程序沒有正確簽名或針對Google Play中的應用內結算設置不正確,或者沒有在清單中擁有必要的權限)
但是接下來,我可以使用此相同設備(並且是相同的,以我所有的朋友測試),使用此代碼購買應用程式內sucesfully:
//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());
}
然後,我可以處理JSON字符串從谷歌的例子。
那麼,你能告訴我我在做什麼錯了,以獲得價格嗎?十分感謝大家。
謝謝ianhanniballake!所以我必須將「DETAIL_LIST」更改爲「ITEM_ID_LIST」? – Totalys
需要幾個小時來測試任何更改,因爲谷歌需要太多時間來發布更新,所以請給我一個提示,因爲我對這個結構有點失落...... tks。 – Totalys
@Totalys - 這是正確的 - 只是改變'querySkus.putStringArrayList(「DETAILS_LIST」,skuList);'到'querySkus.putStringArrayList(「ITEM_ID_LIST」,skuList);' – ianhanniballake