2

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

2 回答 2

9

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

  1. 您已经实施了 AdMob。
  2. 转到 Playstore 开发者帐户,然后在您的应用中,添加应用内购买项目。比方说:“无广告”,名称在这里无关紧要,ID 很重要。
  3. 使用 google 提供的 IAB 帮助文件,并按照如何使用它的步骤进行操作。参考这个链接:http: //developer.android.com/training/in-app-billing/preparing-iab-app.html
  4. 提供一个链接,让用户为“无广告”应用内元素付费。
  5. 在应用程序启动检查时,通过使用上述类检查用户是否已经支付/购买了应用内元素,将标志标记为真。为了保持一致性和不重复检查,请将此变量在共享首选项中保留为空。
  6. Null 表示,您必须通过 google play 确认用户购买。
  7. 如果已购买,则将其标记为 true,否则标记为 false。
  8. 如果此标志为真:不显示广告。
于 2015-01-19T06:25:00.777 回答
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()方法。有关如何将In-App Billing添加到您的应用程序的更多信息,请参阅文档(单击)
希望这能回答你的问题。

于 2014-08-28T11:39:57.633 回答