android – onIabPurchaseFinishedListener永远不会被调用

前端之家收集整理的这篇文章主要介绍了android – onIabPurchaseFinishedListener永远不会被调用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的onIabPurchaseFinishedListener永远不会被调用,即使我在inapp对话框中单击立即购买,logcat也不会打印任何内容.
public class CreateAlbumActivity extends Activity {
IabHelper mHelper;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_create_album);
        mHelper = new IabHelper(this,Global.inapp);

    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
           public void onIabSetupFinished(IabResult result) {
              if (!result.isSuccess()) {
                 // Oh noes,there was a problem.
                 // AlertDialogHelper.CreateNormalDialog(context,"Failed to set In-App Billing: " +result);
                 Log.d(Global.TAG,"Problem setting up In-app Billing: " + result);
                 return;
              }            
                 // Hooray,IAB is fully set up!  

           }
        });
    }
 public void createAlbumEvent(){

                    mHelper.launchPurchaseFlow(CreateAlbumActivity.this,"android.test.purchased",10001,mPurchaseFinishedListener,"bGoa+V7g/yqDXvKRqq");


    }
    IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener 
     = new IabHelper.OnIabPurchaseFinishedListener() {
     public void onIabPurchaseFinished(IabResult result,Purchase purchase) 
     {
        if (result.isFailure()) {
           Log.d(Global.TAG,"Error purchasing: " + result);
           return;
        }      
        Log.d(Global.TAG,"SUCCESS PURCHASE!");
     }
     };
     @Override
     protected void onActivityResult(int requestCode,int resultCode,Intent data) {
         Log.d(Global.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,data);
         }
         else {
             Log.d(Global.TAG,"onActivityResult handled by IABUtil.");
         }
     }
}

解决方法

好吧,所以在花了几个小时试图解决这个问题后,我遇到了以下答案: https://stackoverflow.com/a/17411617/1203043

问题是我的活动有一个“没有历史”的旗帜.如果我从活动中删除此标志,它就可以正常工作.我真的不知道为什么会发生这种情况,但现在就是这样.

希望你们永远不会经历我经历过的噩梦.

猜你在找的Android相关文章