Android 检查横幅是否被按下

发布于 2024-12-11 00:28:55 字数 696 浏览 0 评论 0原文

我试图找到一种方法来检查横幅(广告)是否被检查,但它更难接缝。

我尝试过

adView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            //TODO
        }
    });

,但它不起作用(我放置了调试打印,但它不起作用..)

然后我尝试创建一个 LinearLayout 来包装 adView 并将侦听器放在线性布局上,但它仍然不起作用。

然后我尝试创建一个包含所有显示的更大布局,并在其中添加 adView。我想在其中放置一个 onTouchListener ,并检查坐标,以检查添加是否被按下。但我真的不明白如何找到我的横幅的正确坐标(我创建了一个方法来获取 x 和 y 偏移以及用于放置横幅的重力)进行检查,我真的希望存在更好的方法。此外,我发现如果我按下横幅,该方法不会执行,但只有按下屏幕的其他部分时才会执行。

那么,有什么办法可以知道吗?我不在乎知道横幅页面是否已加载,或者是否重定向到市场或浏览器,我只需要知道横幅是否被按下。

也许设置一个在触摸屏幕时运行的检查,然后检查listner方法是否运行,如果没有运行,则触摸横幅可以工作,但我不知道如何实现它..

任何知道怎么做吗?

谢谢

I'm trying to find a method to check if a banner (ad) is checked, but it is more difficult that it seams.

I tried

adView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            //TODO
        }
    });

But it doesn't work(i put a debug print but it didn't work..)

Then i tried to create a LinearLayout that wraps the adView and putted the listener on the linear layout, but it still didn't work.

Then i tried to create a bigger layout that contained all the display, and added the adView in it. I thought to put a onTouchListener in it, and checking the coordinates, to check if the add was pressed. But i don't really understand the how to find the correct coordinates of my banner (i created a method that gets x and y offset and the gravity to use to place the banner) to check, and i really hope that a better way exists. In addition i found that the method is not executed if i press the banner, but only if other parts of the screen are pressed.

So, is there some way to know it? I don't care to know if the banner page was loaded, or if it redirected to the market or the browser, i just need to know if the banner was pressed.

Maybe setting a check that runs when the screen is touched, and than check if the listner method was run, and if it wasn't run that the banner was touched can work, but i don't know how to implement it..

Any idea how to do this?

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

把时间冻结 2024-12-18 00:28:55

我不知道为什么其他人没有谈论你使用的是哪个adView?
大多数(就像我所知道的那样)提供了一个您可以提供的侦听器,该侦听器在点击广告时有回调。

例如,MobFox 有 setBannerListener(BannerListenerlistener) 并且该监听器有一个方法 adClicked()。其他提供商(如 admob、inmobi、mopub)都有类似的监听器,您可以设置。

这应该是处理这个问题的方法,而不是侵入容器视图。

I don't know why other people haven't spoken about which adView you are using?
Most (like in all I know) provide a listener you can supply, that has a callback for when a ad is clicked.

MobFox for example has setBannerListener(BannerListener listener) and that listener has a method adClicked(). Other providers (like admob, inmobi, mopub) all have similar listeners you can set.

That should be the way to handle this, not hacking into a containerview.

浊酒尽余欢 2024-12-18 00:28:55

对于那些仍然不知道如何操作的人:

它使用 AdListener

adView.setAdListener(new AdListener() {
            public void onDismissScreen(Ad arg0) {
               Toast.makeText(BannerAdListener.this, "Back to app", Toast.LENGTH_SHORT).show();
            }

            public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
               Toast.makeText(BannerAdListener.this, "Error loading", Toast.LENGTH_SHORT).show();

            }

            public void onLeaveApplication(Ad arg0) {
               Toast.makeText(BannerAdListener.this, "Left app", Toast.LENGTH_SHORT).show();

            }

            public void onPresentScreen(Ad arg0) {
               Toast.makeText(BannerAdListener.this, "Sumthin sumthin", Toast.LENGTH_SHORT).show();

            }

            public void onReceiveAd(Ad arg0) {
               Toast.makeText(BannerAdListener.this, "Ad Received", Toast.LENGTH_SHORT).show();

            }
            });

For those who still didnt know how to:

Its using AdListener

adView.setAdListener(new AdListener() {
            public void onDismissScreen(Ad arg0) {
               Toast.makeText(BannerAdListener.this, "Back to app", Toast.LENGTH_SHORT).show();
            }

            public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
               Toast.makeText(BannerAdListener.this, "Error loading", Toast.LENGTH_SHORT).show();

            }

            public void onLeaveApplication(Ad arg0) {
               Toast.makeText(BannerAdListener.this, "Left app", Toast.LENGTH_SHORT).show();

            }

            public void onPresentScreen(Ad arg0) {
               Toast.makeText(BannerAdListener.this, "Sumthin sumthin", Toast.LENGTH_SHORT).show();

            }

            public void onReceiveAd(Ad arg0) {
               Toast.makeText(BannerAdListener.this, "Ad Received", Toast.LENGTH_SHORT).show();

            }
            });
楠木可依 2024-12-18 00:28:55

您是否尝试过在点击事件中添加祝酒词?

该应用程序可以编译并运行吗?

您有重复的 id 吗?

Did you try putting a toast in your click event?

Does the app compile and run?

Do you have duplicate ids ?

余罪 2024-12-18 00:28:55

好的,我解决了,由于我花了很多时间来寻找解决方案,所以我将其发布在这里,以便每个人都可以找到并使用它!

LinearLayout containAdView = null;

    if(registerTouch)
    {
            containAdView = new LinearLayout(pActivity){

            public boolean onInterceptTouchEvent(MotionEvent ev)
            {
                if(ev.getAction() == MotionEvent.ACTION_UP)
                {
                    bannerClicked(pActivity, shared_Prefs_name, shared_Save_name);

                    if(mainMenu.ISDEV)
                    {
                        final Toast tost = Toast.makeText(pActivity, "Banner Clicked", Toast.LENGTH_SHORT);
                        tost.show();
                    }
                }

                return super.onInterceptTouchEvent(ev);
            }
        };
        containAdView.addView(adView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT));
    }

Ok, i solved, and since i lost quite a bit of time to find the solution, i post it here so that everyone can find and use it!

LinearLayout containAdView = null;

    if(registerTouch)
    {
            containAdView = new LinearLayout(pActivity){

            public boolean onInterceptTouchEvent(MotionEvent ev)
            {
                if(ev.getAction() == MotionEvent.ACTION_UP)
                {
                    bannerClicked(pActivity, shared_Prefs_name, shared_Save_name);

                    if(mainMenu.ISDEV)
                    {
                        final Toast tost = Toast.makeText(pActivity, "Banner Clicked", Toast.LENGTH_SHORT);
                        tost.show();
                    }
                }

                return super.onInterceptTouchEvent(ev);
            }
        };
        containAdView.addView(adView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT));
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文