无法测试应用内订阅
Unable to test In App Subscription
我找不到通过 google 测试产品 ID 测试 InApp 订阅 的方法,即 private final String productID = "android.test.purchased"; // Test Product ID by Google
在docs中没有写到InAPP订阅无法用测试产品测试,也没有在任何地方提到如何测试InApp订阅。
我已经按照 docs(InAppV3).
实现了我的代码
文档说:
实施订阅:
启动订阅的购买流程类似于启动产品的购买流程,不同之处在于产品类型必须设置为 "subs"。购买结果会传送到您的 Activity 的 onActivityResult 方法,与应用内商品的情况完全一样。
而且我也正确地实施了。
如果我将 "inapp" 替换为 "subs",我的应用程序可以正常运行,即它非常适用于产品而非订阅。
当我将 "inapp" 更改为 "subs" 时,购买正在退货:
09-24 14:01:12.943: I/(16929): isBillingSupported() - success : return 0
09-24 14:01:12.943: D/Finsky(2598): [281] InAppBillingUtils.getPreferredAccount: com.kgandroid.inappsubscriptiondemo: Account from first account - [MOn42QuZgF98vxJi0p3wAN3rfzQ]
09-24 14:01:12.943: I/(16929): getPurchases() - success return Bundle
09-24 14:01:12.943: I/(16929): getPurchases() - "RESPONSE_CODE" return 0
09-24 14:01:12.943: I/(16929): getPurchases() - "INAPP_PURCHASE_ITEM_LIST" return []
09-24 14:01:12.943: I/(16929): getPurchases() - "INAPP_PURCHASE_DATA_LIST" return []
09-24 14:01:12.943: I/(16929): getPurchases() - "INAPP_DATA_SIGNATURE" return null
09-24 14:01:12.943: I/(16929): getPurchases() - "INAPP_CONTINUATION_TOKEN" return null
如您所见,android.test.purchased
没有详细信息 returning.The 测试应用内购买对话框也 未打开 。
相关购买代码(虽然和我猜的问题无关):
void purchase()
{
if (!blnBind) return;
if (mService == null) return;
ArrayList<String> skuList = new ArrayList<String>();
skuList.add(productID);
Bundle querySkus = new Bundle();
querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
Bundle skuDetails;
try {
skuDetails = mService.getSkuDetails(3, getPackageName(), "subs", querySkus);
System.out.println(skuDetails);
Toast.makeText(context, "getSkuDetails() - success return Bundle", Toast.LENGTH_SHORT).show();
Log.i(tag, "getSkuDetails() - success return Bundle");
} catch (RemoteException e) {
e.printStackTrace();
Toast.makeText(context, "getSkuDetails() - fail!", Toast.LENGTH_SHORT).show();
Log.w(tag, "getSkuDetails() - fail!");
return;
}
int response = skuDetails.getInt("RESPONSE_CODE");
Toast.makeText(context, "getSkuDetails() - \"RESPONSE_CODE\" return " + String.valueOf(response), Toast.LENGTH_SHORT).show();
Log.i(tag, "getSkuDetails() - \"RESPONSE_CODE\" return " + String.valueOf(response));
if (response != 0) return;
ArrayList<String> responseList = skuDetails.getStringArrayList("DETAILS_LIST");
Log.i(tag, "getSkuDetails() - \"DETAILS_LIST\" return " + responseList.toString());
if (responseList.size() == 0) return;
for (String thisResponse : responseList) {
try {
JSONObject object = new JSONObject(thisResponse);
String sku = object.getString("productId");
String title = object.getString("title");
String price = object.getString("price");
Log.i(tag, "getSkuDetails() - \"DETAILS_LIST\":\"productId\" return " + sku);
Log.i(tag, "getSkuDetails() - \"DETAILS_LIST\":\"title\" return " + title);
Log.i(tag, "getSkuDetails() - \"DETAILS_LIST\":\"price\" return " + price);
if (!sku.equals(productID)) continue;
Bundle buyIntentBundle = mService.getBuyIntent(3, getPackageName(), sku, "subs", "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ");
Toast.makeText(context, "getBuyIntent() - success return Bundle", Toast.LENGTH_SHORT).show();
Log.i(tag, "getBuyIntent() - success return Bundle");
response = buyIntentBundle.getInt("RESPONSE_CODE");
//Toast.makeText(context, "getBuyIntent() - \"RESPONSE_CODE\" return " + String.valueOf(response), Toast.LENGTH_SHORT).show();
Log.i(tag, "getBuyIntent() - \"RESPONSE_CODE\" return " + String.valueOf(response));
if (response != 0) continue;
PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
startIntentSenderForResult(pendingIntent.getIntentSender(), 1001, new Intent(), 0, 0, 0);
} catch (JSONException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
//Toast.makeText(context, "getSkuDetails() - fail!", Toast.LENGTH_SHORT).show();
Log.w(tag, "getBuyIntent() - fail!");
} catch (SendIntentException e) {
e.printStackTrace();
}
}
}
订阅支持试购吗??
如果没有,如何测试订阅?
如果是,为什么 google 返回 null?
任何相关文档或链接也会有所帮助。
我从未尝试过使用测试产品 ID ("android.test.purchased") 测试订阅,我不确定它是否有效,因为它似乎是产品 ID 而不是订阅 ID。我使用真实的订阅 ID(我在 Google Play Developer Console 上创建的),但我使用的帐户不是我的开发者帐户(即你用来发布应用程序的帐户)。
如果你去https://play.google.com/apps/publish/ then click on Settings, you'll see a field called "Gmail accounts with testing access". You can type one or more gmail addresses for accounts with which you want to test your purchases. Any account added there that purchases a subscription will not be charged and subscriptions will last for 24 hours. (source: http://developer.android.com/google/play/billing/billing_testing.html和我自己的经验)
这对我有用。虽然我确实似乎发现了一个错误:Trying to cancel an Android test subscription gives me a 500 response code
祝你的应用程序好运!
编辑:
来自 Google 文档 (http://developer.android.com/google/play/billing/billing_testing.html#billing-testing-test)
You cannot use your developer account to test the complete in-app
purchase process because Google payments does not let you buy items
from yourself.
您是否尝试过使用其他帐户?
我找不到通过 google 测试产品 ID 测试 InApp 订阅 的方法,即 private final String productID = "android.test.purchased"; // Test Product ID by Google
在docs中没有写到InAPP订阅无法用测试产品测试,也没有在任何地方提到如何测试InApp订阅。
我已经按照 docs(InAppV3).
实现了我的代码文档说:
实施订阅: 启动订阅的购买流程类似于启动产品的购买流程,不同之处在于产品类型必须设置为 "subs"。购买结果会传送到您的 Activity 的 onActivityResult 方法,与应用内商品的情况完全一样。
而且我也正确地实施了。
如果我将 "inapp" 替换为 "subs",我的应用程序可以正常运行,即它非常适用于产品而非订阅。
当我将 "inapp" 更改为 "subs" 时,购买正在退货:
09-24 14:01:12.943: I/(16929): isBillingSupported() - success : return 0
09-24 14:01:12.943: D/Finsky(2598): [281] InAppBillingUtils.getPreferredAccount: com.kgandroid.inappsubscriptiondemo: Account from first account - [MOn42QuZgF98vxJi0p3wAN3rfzQ]
09-24 14:01:12.943: I/(16929): getPurchases() - success return Bundle
09-24 14:01:12.943: I/(16929): getPurchases() - "RESPONSE_CODE" return 0
09-24 14:01:12.943: I/(16929): getPurchases() - "INAPP_PURCHASE_ITEM_LIST" return []
09-24 14:01:12.943: I/(16929): getPurchases() - "INAPP_PURCHASE_DATA_LIST" return []
09-24 14:01:12.943: I/(16929): getPurchases() - "INAPP_DATA_SIGNATURE" return null
09-24 14:01:12.943: I/(16929): getPurchases() - "INAPP_CONTINUATION_TOKEN" return null
如您所见,android.test.purchased
没有详细信息 returning.The 测试应用内购买对话框也 未打开 。
相关购买代码(虽然和我猜的问题无关):
void purchase()
{
if (!blnBind) return;
if (mService == null) return;
ArrayList<String> skuList = new ArrayList<String>();
skuList.add(productID);
Bundle querySkus = new Bundle();
querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
Bundle skuDetails;
try {
skuDetails = mService.getSkuDetails(3, getPackageName(), "subs", querySkus);
System.out.println(skuDetails);
Toast.makeText(context, "getSkuDetails() - success return Bundle", Toast.LENGTH_SHORT).show();
Log.i(tag, "getSkuDetails() - success return Bundle");
} catch (RemoteException e) {
e.printStackTrace();
Toast.makeText(context, "getSkuDetails() - fail!", Toast.LENGTH_SHORT).show();
Log.w(tag, "getSkuDetails() - fail!");
return;
}
int response = skuDetails.getInt("RESPONSE_CODE");
Toast.makeText(context, "getSkuDetails() - \"RESPONSE_CODE\" return " + String.valueOf(response), Toast.LENGTH_SHORT).show();
Log.i(tag, "getSkuDetails() - \"RESPONSE_CODE\" return " + String.valueOf(response));
if (response != 0) return;
ArrayList<String> responseList = skuDetails.getStringArrayList("DETAILS_LIST");
Log.i(tag, "getSkuDetails() - \"DETAILS_LIST\" return " + responseList.toString());
if (responseList.size() == 0) return;
for (String thisResponse : responseList) {
try {
JSONObject object = new JSONObject(thisResponse);
String sku = object.getString("productId");
String title = object.getString("title");
String price = object.getString("price");
Log.i(tag, "getSkuDetails() - \"DETAILS_LIST\":\"productId\" return " + sku);
Log.i(tag, "getSkuDetails() - \"DETAILS_LIST\":\"title\" return " + title);
Log.i(tag, "getSkuDetails() - \"DETAILS_LIST\":\"price\" return " + price);
if (!sku.equals(productID)) continue;
Bundle buyIntentBundle = mService.getBuyIntent(3, getPackageName(), sku, "subs", "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ");
Toast.makeText(context, "getBuyIntent() - success return Bundle", Toast.LENGTH_SHORT).show();
Log.i(tag, "getBuyIntent() - success return Bundle");
response = buyIntentBundle.getInt("RESPONSE_CODE");
//Toast.makeText(context, "getBuyIntent() - \"RESPONSE_CODE\" return " + String.valueOf(response), Toast.LENGTH_SHORT).show();
Log.i(tag, "getBuyIntent() - \"RESPONSE_CODE\" return " + String.valueOf(response));
if (response != 0) continue;
PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
startIntentSenderForResult(pendingIntent.getIntentSender(), 1001, new Intent(), 0, 0, 0);
} catch (JSONException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
//Toast.makeText(context, "getSkuDetails() - fail!", Toast.LENGTH_SHORT).show();
Log.w(tag, "getBuyIntent() - fail!");
} catch (SendIntentException e) {
e.printStackTrace();
}
}
}
订阅支持试购吗?? 如果没有,如何测试订阅? 如果是,为什么 google 返回 null?
任何相关文档或链接也会有所帮助。
我从未尝试过使用测试产品 ID ("android.test.purchased") 测试订阅,我不确定它是否有效,因为它似乎是产品 ID 而不是订阅 ID。我使用真实的订阅 ID(我在 Google Play Developer Console 上创建的),但我使用的帐户不是我的开发者帐户(即你用来发布应用程序的帐户)。
如果你去https://play.google.com/apps/publish/ then click on Settings, you'll see a field called "Gmail accounts with testing access". You can type one or more gmail addresses for accounts with which you want to test your purchases. Any account added there that purchases a subscription will not be charged and subscriptions will last for 24 hours. (source: http://developer.android.com/google/play/billing/billing_testing.html和我自己的经验)
这对我有用。虽然我确实似乎发现了一个错误:Trying to cancel an Android test subscription gives me a 500 response code
祝你的应用程序好运!
编辑:
来自 Google 文档 (http://developer.android.com/google/play/billing/billing_testing.html#billing-testing-test)
You cannot use your developer account to test the complete in-app purchase process because Google payments does not let you buy items from yourself.
您是否尝试过使用其他帐户?