在Android中删除Admob的应用内购买



我已经实现了admob激活的代码,我想介绍应用内购买以删除admob,有人能告诉我如何完美地做到这一点吗?我已经查看了很多教程,但还不清楚概念,请在这方面帮助我。

 private ImageView imview;
    private int w,h;
    private Bitmap filtaringImage = null;
    private Bitmap Changebitmap=null;
    private Context context;
    private LinearLayout linear;
    private LinearLayout mainLayout;
    private ProgressDialog effectProgress;
    private ImageButton normal,r_nd_g,g_nd_b,hsv,hls;
    private ContentResolver mContentResolver;
    private int IMAGE_MAX_SIZE = 1024;
    private List<Bitmap> history;
    private List<Bitmap> redo;
    //private File temp File = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"./."+UtilsPixolish.TEMP_FILE_NAME);

    private boolean showBackAllart;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //***************************************
        context = this;
        AdView adView = (AdView)this.findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().addTestDevice("unit id ").build();
        adView.loadAd(adRequest);
        //createTempFolder();
        //***************************************
        mainLayout = (LinearLayout) findViewById(R.id.mainLayout);
        linear = (LinearLayout) findViewById(R.id.sub_liner_scroll);
        normal = (ImageButton) findViewById(R.id.normal);
        r_nd_g = (ImageButton) findViewById(R.id.r_g);
        g_nd_b = (ImageButton) findViewById(R.id.g_b);
        hsv = (ImageButton) findViewById(R.id.hsv);
        hls = (ImageButton) findViewById(R.id.hls);
        imview=(ImageView)findViewById(R.id.imageView1);
        showBackAllart = false;
        //******** original bitmap *********//
//      original = ((BitmapDrawable)imview.getDrawable()).getBitmap();
        history = new ArrayList<Bitmap>();
        redo = new ArrayList<Bitmap>();
        Log.i("Tik", String.valueOf(history.size()));
        //history.add(original);
//      filtaringImage = ((BitmapDrawable)imview.getDrawable()).getBitmap();
//      Changebitmap=((BitmapDrawable)imview.getDrawable()).getBitmap();
        imview.setOnLongClickListener(this);
        mContentResolver = getContentResolver();
        applyNewEffect();
    }

在我的activity.xml文件中,我为admob 添加了这个

<com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/admob_id"/>

好吧,我将实现与@reverse所说的相同的事情并进行规划,但我想确认其他开发人员的想法。然而,他的答案本身就是完整的,我只是给出步骤:

  1. 你已经实现了AdMob
  2. 转到playstore开发者帐户,在您的应用程序中,添加应用程序内购买项目。比方说:"没有广告",名字在这里不重要,身份证很重要
  3. 使用谷歌提供的IAB帮助文件,并按照步骤使用它。请参阅此链接:http://developer.android.com/training/in-app-billing/preparing-iab-app.html
  4. 提供一个链接,由用户为应用程序中的"无广告"元素付费
  5. 在应用程序启动检查时,通过使用上面的类检查用户是否已经支付/购买了应用程序内元素,将标志标记为true。为了一致性和不重复检查,请将共享首选项中的此变量保持为null
  6. 空意味着,你必须与谷歌播放核实用户购买
  7. 如果购买,请标记为真,否则为假
  8. 如果这个标志是真的:不要显示广告

因此,最简单的答案是,如果用户在应用程序内购买和/或隐藏AdView:,则不运行以下行

AdRequest adRequest = new AdRequest.Builder().addTestDevice("unit id ").build();
adView.loadAd(adRequest);
adView.setVisibility(View.Gone);

但让我们深入了解更多细节:假设您将使用Google中的IABHelper类。这个类包括一个回调方法,让您了解用户的购买情况:

IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
        public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
            if (mHelper == null)
                return;
            if (result.isFailure()) {
                // handle error here
                return;
            } else {
                if (inventory.hasPurchase(PremiumUtils.SKU_AD_FREE)){
                    // User paid to remove the Ads - so hide 'em
                    hideAd();
                }
                else{
                    // Free user - annoy him with ads ;)
                    showAd();
                }
                return;
            }
        }
};

正如你所看到的:根据库存("管理"所有购买),广告将被加载/显示或隐藏。当然,您必须自己编写hideAd()showAd()法。有关如何将应用内计费添加到应用程序的更多信息,请参阅文档(单击)
希望这能回答你的问题。

最新更新