在应用内购买Android中删除Admob

时间:2014-08-28 10:35:24

标签: android in-app-purchase admob addremoveprograms

我已经实现了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"/>

2 个答案:

答案 0 :(得分:8)

好吧,我将实现同样的事情并按照@reverse所说的计划,但想确认其他开发人员的想法。但是,他的回答本身就是完整的,我只是给出了步骤:

  1. 您已经实施了AdMob。
  2. 转到Playstore开发者帐户,然后在您的应用中添加应用内购买项目。让我们说:“没有广告”,这里的名字并不重要,ID很重要。
  3. 使用谷歌提供的IAB帮助文件,并按照如何使用它的步骤。请参阅此链接:http://developer.android.com/training/in-app-billing/preparing-iab-app.html
  4. 提供用户支付“无广告”应用内元素的链接。
  5. 在应用程序启动检查时,通过使用上述类检查用户是否已支付/购买了应用程序内元素,将该标志标记为true。对于一致性和不重复检查,请将此变量保持为共享首选项为null。
  6. Null表示,您必须与Google Play一起检查以供用户购买。
  7. 如果购买,请将其标记为true,否则为false。
  8. 如果此标志为真:请勿展示广告。

答案 1 :(得分:6)

因此,最简单的答案是,如果用户购买了应用程序内部并且/或隐藏了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()方法。有关如何将应用内结算添加到您的应用的详细信息,请参阅Docs (click)
希望这能回答你的问题。