Android Studio 应用内购买配置
Android Studio In-App purchases configuration
我正在为我的应用程序设置应用程序内购买,但卡在了某个特定点。目前我使用的代码如下:
IabHelper mHelper;
protected void onCreate(Bundle savedInstanceState) {
mHelper = new IabHelper(this, base64EncodedPublicKey); //base64EncodedPublicKey is a string declared earlier and not reposted here.
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
Log.d(TAG, "Failed: " + result);
Toast.makeText(MainActivity.this, "IAB setup Failed", Toast.LENGTH_SHORT).show();
} else {
Log.d(TAG, "Worked");
Toast.makeText(MainActivity.this, "IAB setup Successful", Toast.LENGTH_SHORT).show();
final List additionalSkuList = new ArrayList();
additionalSkuList.add("remove_ad");
mHelper.queryInventoryAsync(true, additionalSkuList, mQueryFinishedListener);
}
}
});
在这一点上,一切似乎都很顺利。 "Worked" 段代码触发并处理成功。代码此时向mHelper.queryInventoryAsync
发送请求,配置如下,在onCreate()
之外:
IabHelper.QueryInventoryFinishedListener mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory)
{
if (result.isFailure()) {
Toast.makeText(MainActivity.this, "Query Listener Error", Toast.LENGTH_SHORT).show();
return;
}
String removalPrice =
inventory.getSkuDetails("remove_ad").getPrice();
Toast.makeText(MainActivity.this, removalPrice, Toast.LENGTH_SHORT).show();
// update the UI
}
};
此时Toast触发说"Query Listener Error",表示if (result.isFailure())已经触发。这就是我被困的地方。它没有给我任何关于为什么会发生这种情况的线索。
在开发者控制台中,这些是我的应用内产品的详细信息:
Name/ID: Remove Ad (remove_ad)
Type: Managed product
Last Update: Jul 15, 2015
Status: Active
我做错了什么?唯一我不太确定的是我是如何声明和使用我的 arrayList
,以及我在哪里提交了一个字符串值到 .getPrice();
mHelper.launchPurchaseFlow(Activity.this, SKU, 11,
mPurchaseFinishedListener, "mypurchasetoken");
调用此方法并实现如下所示的监听器,您将获得结果
public IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result,
Purchase purchase)
{
if (result.isFailure()) {
}
return;
}
};
参考下面link:
http://www.techotopia.com/index.php/An_Android_Studio_Google_Play_In-app_Billing_Tutorial
我正在为我的应用程序设置应用程序内购买,但卡在了某个特定点。目前我使用的代码如下:
IabHelper mHelper;
protected void onCreate(Bundle savedInstanceState) {
mHelper = new IabHelper(this, base64EncodedPublicKey); //base64EncodedPublicKey is a string declared earlier and not reposted here.
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
Log.d(TAG, "Failed: " + result);
Toast.makeText(MainActivity.this, "IAB setup Failed", Toast.LENGTH_SHORT).show();
} else {
Log.d(TAG, "Worked");
Toast.makeText(MainActivity.this, "IAB setup Successful", Toast.LENGTH_SHORT).show();
final List additionalSkuList = new ArrayList();
additionalSkuList.add("remove_ad");
mHelper.queryInventoryAsync(true, additionalSkuList, mQueryFinishedListener);
}
}
});
在这一点上,一切似乎都很顺利。 "Worked" 段代码触发并处理成功。代码此时向mHelper.queryInventoryAsync
发送请求,配置如下,在onCreate()
之外:
IabHelper.QueryInventoryFinishedListener mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory)
{
if (result.isFailure()) {
Toast.makeText(MainActivity.this, "Query Listener Error", Toast.LENGTH_SHORT).show();
return;
}
String removalPrice =
inventory.getSkuDetails("remove_ad").getPrice();
Toast.makeText(MainActivity.this, removalPrice, Toast.LENGTH_SHORT).show();
// update the UI
}
};
此时Toast触发说"Query Listener Error",表示if (result.isFailure())已经触发。这就是我被困的地方。它没有给我任何关于为什么会发生这种情况的线索。
在开发者控制台中,这些是我的应用内产品的详细信息:
Name/ID: Remove Ad (remove_ad)
Type: Managed product
Last Update: Jul 15, 2015
Status: Active
我做错了什么?唯一我不太确定的是我是如何声明和使用我的 arrayList
,以及我在哪里提交了一个字符串值到 .getPrice();
mHelper.launchPurchaseFlow(Activity.this, SKU, 11,
mPurchaseFinishedListener, "mypurchasetoken");
调用此方法并实现如下所示的监听器,您将获得结果
public IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result,
Purchase purchase)
{
if (result.isFailure()) {
}
return;
}
};
参考下面link:
http://www.techotopia.com/index.php/An_Android_Studio_Google_Play_In-app_Billing_Tutorial