In app purchase for removing Admob in Android

♀尐吖头ヾ 提交于 2019-12-10 11:41:20

问题


I have implemented the code for admob activated , I want to introduce in-app purchase for remove admob , can anybody tell me how can I do this perfectly, I have checked many tutorial but not clear the concept , please help me in this regard.

 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();
    }

in my activity.xml file i have added this for 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"/>

回答1:


ok, I am going to implement the same thing and planning it as @reverse has told but wanted to confirm how other developers are thinking. However, his answer is complete in itself, I am just giving the steps:

  1. You already have AdMob implemented.
  2. Go to playstore developer account and in your app, Add an in-app purchase item. let's say: "No Ads", name doesn't matter here, an ID would matter.
  3. Use the IAB helper file provided by google and follow the steps how to use it. Refer to this link: http://developer.android.com/training/in-app-billing/preparing-iab-app.html
  4. Provide a link to pay for "No ads" in-app element by the user.
  5. On application startup check, by using the above class check whether user has already paid/purchased the in-app element, mark the flag to true. For consistency and unrepeated check, keep this variable in shared preference as null.
  6. Null means, You have to check with google play for purchase by the user.
  7. If purchased, mark it true else false.
  8. if this flag is true: do not show ads.



回答2:


So the simplest answer would be that you don't run the following line if the user has the In-App purchase and/or hide the AdView:

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

But let's get into more detail: Let's assume that you'll be using the IABHelper class from Google. This class includes a callback-method which let's you know about the purchases of the user:

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;
            }
        }
};

As you can see: Depending on the inventory (which "manages" all purchases) the Ad will be loaded/shown or hid. Of course you have to write the hideAd() and showAd() methods on your own. For more info how to add In-App Billing to your app see the Docs (click).
Hope this answers your question.



来源:https://stackoverflow.com/questions/25546690/in-app-purchase-for-removing-admob-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!