【问题标题】:In app purchase for removing Admob in Android在 Android 中移除 Admob 的应用内购买
【发布时间】:2014-08-28 10:35:24
【问题描述】:

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

【问题讨论】:

  • 请考虑更新您的帖子,因为您混淆了XML-CodeJava-Code

标签: android in-app-purchase admob addremoveprograms


【解决方案1】:

好的,我将按照@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. 如果此标志为真:不展示广告。

【讨论】:

    【解决方案2】:

    所以最简单的答案是,如果用户有应用内购买和/或隐藏AdView,则不要运行以下行:

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

    但让我们更详细地了解:假设您将使用 GoogleIABHelper 类。该类包含一个回调方法,让您了解用户的购买情况:

    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)
    希望这能回答您的问题。

    【讨论】:

    • 不,我想添加一个菜单项,如“AdFree”,然后设法控制由谷歌播放服务提供的 adremove。如果我使用这个 IabHelper,那么我可以在哪里放置广告单元 ID 并进行测试身份证?
    • 没有什么能比得上 "gplay 服务提供的广告删除,您必须自己完成此操作。此外,IABHelper 只是一个用于管理的 Helper-Class应用内购买与 Admob 完全无关。请参阅我在帖子中链接的文档。
    • 我只是想知道应用内购买移除admob的分步流程
    • 恐怕 StackO 不是do-this-for-me 网站。我们在这里帮助解决与编程相关的问题并引导您朝着正确的方向前进。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-31
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多