Android-使用真实项目id测试帐单购买时出现错误:未找到项目
我在一个测试设备上测试了一个项目id:android.test.purchased 事情成功了。然后,一旦我用真实的项目id更改了该字符串,当我按下buy按钮时,我开始获取item Not Found error 此外,购买项目是订阅,而不是一次性购买。这有区别吗 我不确定代码的哪一部分可能有错误,或者可能缺少什么,因此下面是用于此的类:Android-使用真实项目id测试帐单购买时出现错误:未找到项目,android,Android,我在一个测试设备上测试了一个项目id:android.test.purchased 事情成功了。然后,一旦我用真实的项目id更改了该字符串,当我按下buy按钮时,我开始获取item Not Found error 此外,购买项目是订阅,而不是一次性购买。这有区别吗 我不确定代码的哪一部分可能有错误,或者可能缺少什么,因此下面是用于此的类: public class SubscribeIntroActivity extends BaseActivity { IabHelper mHelpe
public class SubscribeIntroActivity extends BaseActivity
{
IabHelper mHelper;
// Does the user have the premium upgrade?
boolean isSubscriber = false;
// (arbitrary) request code for the purchase flow
static final int RC_REQUEST = 105;
// Subscribe SKU
static final String SUBSCRIBE_SKU = "11";
// Subscribe SKU
static final String TAG = "BILLING";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.subscribe_intro);
String base64EncodedPublicKey = "my_real_key";
// Create the helper, passing it our context and the public key to verify signatures with
mHelper = new IabHelper(this, base64EncodedPublicKey);
mHelper.enableDebugLogging(true);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result)
{
if (!result.isSuccess())
{
// Oh noes, there was a problem.
//complain("Problem setting up in-app billing: " + result);
return;
}
// Hooray, IAB is fully set up. Now, let's get an inventory of stuff we own.
mHelper.queryInventoryAsync(mGotInventoryListener);
}
});
// Listener that's called when we finish querying the items we own
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
if (result.isFailure())
{
//complain("Failed to query inventory: " + result);
return;
}
Log.d(TAG, "Query inventory was successful.");
// Do we have the premium upgrade?
isSubscriber = inventory.hasPurchase(SUBSCRIBE_SKU);
Log.d(TAG, "User is " + (isSubscriber ? "SUBSCRIBER" : "NOT SUBSCRIBER"));
// Check for gas delivery -- if we own gas, we should fill up the tank immediately
if (inventory.hasPurchase( SUBSCRIBE_SKU ))
{
Log.d(TAG, "HAS SUBSCRIPTION");
return;
}
//updateUi();
// TODO: TELL USER HE IS SUBSCIBED AND TAKE THEM TO THE QUESTION
//setWaitScreen(false);
Log.d(TAG, "Initial inventory query finished; enabling main UI.");
}
};
Button subscribe = (Button)findViewById(R.id.subscribe);
subscribe.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
// FIRST CHECK IF THE USER IS ALREADY A SUBSCRIBER.
mHelper.launchPurchaseFlow(SubscribeIntroActivity.this, SUBSCRIBE_SKU, RC_REQUEST, mPurchaseFinishedListener);
// Send me an email that a comment was submitted on a question.
//sendEmail("My Questions -> Add Question", "Someone clicked on add-question from my questions. User id: " + user_id );
//Intent myIntent = new Intent(MotivationActivity.this, WePromoteActivity.class);
//MotivationActivity.this.startActivity(myIntent);
}
});
// mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
// public void onIabSetupFinished(IabResult result)
// {
// if (!result.isSuccess())
// {
// // Oh noes, there was a problem.
//
// Log.d("INAPP BILLING", "Problem setting up In-app Billing: " + result);
// }
//
// // Hooray, IAB is fully set up!
//
//
// // First arg is whether product details should be retrieved
// // The List argument consists of one or more product IDs (also called SKUs) for the products that you want to query.
// // the QueryInventoryFinishedListener argument specifies a listener is
// // notified when the query operation has completed
// // and handles the query response.
//// mHelper.queryInventoryAsync(false, new ArrayList ( ).add("1"),
//// mQueryFinishedListener);
//
// //mHelper.queryInventoryAsync(mGotInventoryListener);
//
//
//// mHelper.launchPurchaseFlow(SubscribeIntroActivity.this, "11" , 105, mPurchaseFinishedListener, "" );
// }
// });
}
IabHelper.QueryInventoryFinishedListener
mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener()
{
public void onQueryInventoryFinished(IabResult result, Inventory inventory)
{
if (result.isFailure()) {
// handle error
return;
}
String applePrice =
inventory.getSkuDetails("1").getPrice();
String bananaPrice =
inventory.getSkuDetails(SUBSCRIBE_SKU).getPrice();
}
// update the UI
};
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
= new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase)
{
if (result.isFailure())
{
Log.d("ERROR", "Error purchasing: " + result);
return;
}
else if (purchase.getSku().equals("1"))
{
// consume the gas and update the UI
}
else if (purchase.getSku().equals(SUBSCRIBE_SKU))
{
// give user access to premium content and update the UI
Log.d(TAG, "PURCHASED: " + result);
}
}
};
IabHelper.QueryInventoryFinishedListener mGotInventoryListener
= new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {
if (result.isFailure()) {
// handle error here
}
else
{
// does the user have the premium upgrade?
isSubscriber = inventory.hasPurchase(SUBSCRIBE_SKU);
// update UI accordingly
}
}
};
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);
// Pass on the activity result to the helper for handling
if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
// not handled, so handle it ourselves (here's where you'd
// perform any handling of activity results not related to in-app
// billing...
super.onActivityResult(requestCode, resultCode, data);
}
else {
Log.d(TAG, "onActivityResult handled by IABUtil.");
}
}
@Override
public void onDestroy()
{
super.onDestroy();
if (mHelper != null) mHelper.dispose();
mHelper = null;
}
}
我认为新的应用内计费版本3目前不支持订阅。我可能是错的,但是我在示例代码或文档中没有看到任何关于订阅的内容,所以这可能是您收到ItemNotFound错误的原因
一般来说,要测试购买真实项目,您需要将应用程序的版本上载到开发者控制台,但不需要发布,并且必须使用相同的签名版本进行测试。Google Play还需要一些时间来处理/传播新添加的项目……因此,不幸的是,有时您只需要等待。如果还没有,请查看。我认为新的应用内计费版本3目前不支持订阅。我可能是错的,但是我在示例代码或文档中没有看到任何关于订阅的内容,所以这可能是您收到ItemNotFound错误的原因
一般来说,要测试购买真实项目,您需要将应用程序的版本上载到开发者控制台,但不需要发布,并且必须使用相同的签名版本进行测试。Google Play还需要一些时间来处理/传播新添加的项目……因此,不幸的是,有时您只需要等待。如果还没有,请查看。还有一件事要知道。购买不会立即出现。您可以在发布后的2-3小时内对其进行测试
对不起我的英语=还有一件事要知道。购买不会立即出现。您可以在发布后的2-3小时内对其进行测试
对不起,我的英语=因为这是一个订阅,我相信您必须替换这一行:
mHelper.launchPurchaseFlow(SubscribeIntroActivity.this, SUBSCRIBE_SKU, RC_REQUEST, mPurchaseFinishedListener);
关于这一点:
mHelper.launchSubscriptionPurchaseFlow(SubscribeIntroActivity.this, SUBSCRIBE_SKU, RC_REQUEST, mPurchaseFinishedListener);
至少这是我在代码中使用的,我已经成功地对其进行了测试。由于这是一个订阅,我相信您必须替换这一行:
mHelper.launchPurchaseFlow(SubscribeIntroActivity.this, SUBSCRIBE_SKU, RC_REQUEST, mPurchaseFinishedListener);
关于这一点:
mHelper.launchSubscriptionPurchaseFlow(SubscribeIntroActivity.this, SUBSCRIBE_SKU, RC_REQUEST, mPurchaseFinishedListener);
至少这是我在代码中使用的,我已经成功地对其进行了测试。每个请求限制20项。 即使你把它们分成20个项目的一组,它仍然可以
skuList.addAll(inv.getAllOwnedSkus(itemType));
如果拥有的项目数+查询的项目数大于20,尤其是拥有的项目数为21,则会出现错误
现在我明白了为什么有人建议从一开始就从头开始重写代码。每个请求限制20项。 即使你把它们分成20个项目的一组,它仍然可以
skuList.addAll(inv.getAllOwnedSkus(itemType));
如果拥有的项目数+查询的项目数大于20,尤其是拥有的项目数为21,则会出现错误
现在我明白了为什么有人建议从头开始重写代码。谢谢,订阅方面的观点很好。我真正不明白的是如何将未发布的应用程序从控制台复制到我的设备上。你能给我解释一下吗从控制台安装应用程序与通过adt工具安装应用程序真的有区别吗?即使我以同样的方式签名。不,也无法从开发者控制台下载未发布的应用程序。我的意思是,您应该使用使用adb安装安装的签名APK进行测试,该安装与上载到开发人员控制台的版本代码和版本名相同。您不需要对所有类型的测试都这样做,但您需要对真实产品进行测试。使用测试产品ID时,有一个表列出了可能的测试配置:。@ashhighes谢谢。最后你是对的。不支持订阅:谢谢,订阅的要点很好。我真正不明白的是如何将未发布的应用程序从控制台复制到我的设备上。你能给我解释一下吗从控制台安装应用程序与通过adt工具安装应用程序真的有区别吗?即使我以同样的方式签名。不,也无法从开发者控制台下载未发布的应用程序。我的意思是,您应该使用使用adb安装安装的签名APK进行测试,该安装与上载到开发人员控制台的版本代码和版本名相同。您不需要对所有类型的测试都这样做,但您需要对真实产品进行测试。使用测试产品ID时,有一个表列出了可能的测试配置:。@ashhighes谢谢。最后你是对的。不支持订阅: