想要通过InAppPurchase删除广告

时间:2014-06-26 15:53:51

标签: android admob ads

我在我的Android应用中实现了admob interstitial。但是,如果用户愿意付费,我想停用广告。即InAppPurchase。我已经为IAP编写了以下代码,并且还在产品的beta测试中发布了apk。但仍然显示"没有找到产品",当我按下"删除广告"按钮。

任何人都可以帮我写一个真正的代码或检查下面的代码对IAP是对还是错?

public static final String PRO_SKU = "removeads";
private final String BASE_64_PUBLIC_KEY = "KEY";
private Inventory mInventory;
IabHelper mHelper;
public static boolean isPro;
private InterstitialAd interstitial;

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);}

    interstitial = new InterstitialAd(getActivity(),
            "AD UNIT");
    AdRequest adRequest = new AdRequest();

    interstitial.loadAd(adRequest);

    mHelper = new IabHelper(getActivity().getApplicationContext(),
            BASE_64_PUBLIC_KEY);
    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() 
    {
        @Override
        public void onIabSetupFinished(IabResult result) 
        {
            if (result.isSuccess()) 
            {
                loadInventory();
                Log.d("IAP", "IAP Setup Succesful yeah!");
            } else 
            {
                Log.d("IAP", "IAP Setup Failed");
            }
        }
    });
    ;

    //AD CODE

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_quality, container,
            false);

    ImageView purchaseAds = (ImageView) rootView.findViewById(R.id.promo);
    purchaseAds.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            purchasePro(PRO_SKU);

        }
    });

private void loadInventory() {
    mHelper.queryInventoryAsync(true,
            new IabHelper.QueryInventoryFinishedListener() {
                @Override
                public void onQueryInventoryFinished(IabResult result,
                        Inventory inventory) {
                    if (result.isSuccess()) {
                        mInventory = inventory;
                        Log.d("IAP inventory loader", "inventory loaded");
                        if (inventory.hasPurchase(PRO_SKU)) {
                            isPro = true;

                            Log.d("IAP inventory checker", "purchased");
                        } else {
                            Log.d("IAP inventory checker", "not purchased");
                            isPro = false;
                        }

                    } else {
                        Log.d("IAP inventory loader","inventory not loaded");
                    }
                }

            });
}

private void purchasePro(String sku) {

    mHelper.launchPurchaseFlow(getActivity(), sku, 1000,
            new IabHelper.OnIabPurchaseFinishedListener() {
                @Override
                public void onIabPurchaseFinished(IabResult result,
                        Purchase info) {
                    if (result.isSuccess()) {
                        isPro = true;
                        Log.d("IAP purchase person", "purchased!");
                    } else {
                        Toast.makeText(
                                getActivity().getApplicationContext(),
                                "Error in your purchase",
                                Toast.LENGTH_SHORT).show();
                        Log.d("IAP purchase person", "not purchased!");
                    }
                }
            }, null);

}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (!mHelper.handleActivityResult(1000, resultCode, data)) {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

}

0 个答案:

没有答案