I'm using an adview in my application and want to know when someone has clicked that Adview!
How I can do that?
The onclicklistener does not seem to work.
You can set the listener this way:
adView.setAdListener(this);
And then implement this:
#Override
public void onPresentScreen(Ad arg0) {
//OnClick here
}
The click is handled inside of the AdMob API, and I don't think there is a way to do what you are asking with the API as its against the TOS to use a "unlock feature by clicking X number of ads" model. For that reason I don't believe it is available in the API where the onclicklistener is.
Try this
mAdView.setAdListener(new AdListener() {
#Override
public void onAdOpened() {
super.onAdOpened();
}
});
Related
I'm trying to use the AdListener in C#.
I have an interstitial ad loading when the app is first started, but sometimes my ad gets skipped because it isn't fully loaded yet. I think an Adlistener should do the trick.
Unfortunately, I have NO CLUE on how to implement it. Also, there is no tutorial on how to do it in C# only in Java and I couldn't find a translation for it :(
Add:
adListener.OnAdLoaded() += (o, e) =>
{
mInterstitialAd.Show();
};
This doesn't work :(
Any help would be awesome!
You can create a class which inherits from Android.Gms.Ads.AdListener, then use the instance of this class as the Listener for your mInterstitialAd, for example:
mInterstitialAd.AdListener = new AdListener(this);
AdListener:
private class AdListener : Android.Gms.Ads.AdListener
{
private MainActivity that;
public AdListener(MainActivity t)
{
that = t;
}
public override void OnAdLoaded()
{
base.OnAdLoaded();
}
public override void OnAdClosed()
{
that.RequestNewInterstitial();
that.BeginSecondActivity();
}
}
You can also checked the official demo for xamarin android ad: AdMobExample Sample.
I am using the following view in my activity xml.
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-6844894412719021~8904567900">
</com.google.android.gms.ads.AdView>
Your adUnitId seems to be incorrect. Did you get it via email?
You should be using following app id (replace ~ with /)
ads:adUnitId="ca-app-pub-6844894412719021/8904567900">
Try to add to your xml:
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
and to gradle:
compile 'com.google.android.gms:play-services-ads:9.8.0'
It looks like you are using app_id instead of banner_id.
<string name="app_id">ca-app-pub-xxxxxxxxxxxxxxxx~xxxxxxxxxx</string>
<string name="banner_id">ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx</string>
these two values are different from each other.
Check if you have latest versions of adMob and GooglePlayServices lib.
When you try to show banner inside of svg images then care about it are you using smart banner or banner it may effect, sometimes you implement the code right but when you try to show toast in ad loaded like this.
adView2.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
Toast.makeText(App_Mainpage.this, "add is loaded", Toast.LENGTH_SHORT).show();
adView2.setVisibility(View.VISIBLE);
}
#Override
public void onAdFailedToLoad(int errorCode) {
}
#Override
public void onAdOpened() {
}
#Override
public void onAdLeftApplication() {
}
#Override
public void onAdClosed() {
}
});
AdRequest adRequest = new AdRequest.Builder().build();
adView2.loadAd(adRequest);
if it shows you in toast the ad is loaded but not showing when you testing, then actually you are implementing Smart_banner that takes large space to show, so use Banner Just it will show then, i solve it by change this thing.
then i changed to smart banner .
I tried to implement MoPub interstitials in my libgdx android application.
When I pass a wrong ID in the MoPubInterstitial() constructor, the onInterstitialFailed() method in the listener is called correctly, but when I pass my correct ID nothing happens.
onInterstitialLoaded() should be called eventually, but it isn't.
MoPubInterstitial.isReady() never is true.
Am I missing something?
I don't know, which part of my code I should paste. I'm out of ideas, how to debug this.
Any suggestions?
private static final String MoPubInterstitialID = "xxxxxxxxxxxxx";
private MoPubInterstitial moPubInterstitial;
moPubInterstitial = new MoPubInterstitial(this, MoPubInterstitialID);
moPubInterstitial.setInterstitialAdListener(this);
moPubInterstitial.load();
moPubInterstitialButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Log.d("MoPub", "Interstitial button clicked");
if ( moPubInterstitial.isReady() )
{
Log.d("MoPub", "Interstitial is Ready");
moPubInterstitial.show();
Log.d("MoPub", "Interstial Shown");
moPubInterstitial.forceRefresh();
}
}
});
These are all the steps that i took to make it work. Let me know if you have any questions.
I followed this link to use the +1 button in my Android application to +1 a link or a website, but unfortunately it didn't work as expected and it didn't respond when I click on it. I tried to use the following:
mPlusOneButton.setOnPlusOneClickListener(new OnPlusOneClickListener() {
#Override
public void onPlusOneClick(Intent arg0) {
// TODO Auto-generated method stub
startActivityForResult(arg0, 0);
}
});
But also no response. As an example I tried to use the following line of code:
mPlusOneButton.initialize(plusClient, "http://www.googleplustoday.net", PLUS_ONE_REQUEST_CODE);
And there is no effect on my Google plus profile at the +1 tab.
Who can help? Thanks in advance.
Make sure to be connected to Google Plus:
mPlusOneButton.setOnPlusOneClickListener(new OnPlusOneClickListener() {
#Override
public void onPlusOneClick(Intent intent) {
if(!plusClient.isConnected()) {
plusClient.connect();
} else {
startActivityForResult(intent, 0);
}
}
}
Be sure that you initialize your mPlusOneButton prior to handling clicks such as in the onResume method. When I tested by not initializing before the click then I could get it to fail.
In the androidsdk/extras/google/google_play_services/samples/plus/src/com/google/android/gms/samples/plus/PlusOneActivity.java contains a skeleton activity for getting the PlusOne button working.
If you can post your full activity code and any applicable errors from logcat that would help further identify the issue.
I had recently implemented ads for my android game app. Through AdWhirl, I have integrated Admob and Millennial Media. Now, I am looking for the possibility to integrate ads Smaato through Adwhirl as I have integrated Admob & Millennial Media.
The AdWhirl SDK which I have downloaded does not have any adapter class for Smaato so far. I also want to know whether it is possible to write adapter class for Smaato & integrate with Adwhirl SDK?
Thanks in advance.
Regards,
Atul Prakash Singh
We have build such an adapter for iOS but not for Android yet. It should be possible to write it for Android as well.
Regards
Michael
Smaato Inc.
You have to write function for Custom event on top hierarchy.
This is a sample code :satrt_SUMO
May it helps you.
public class XXXX extends Activity implements AdWhirlInterface {
SOMABanner mBanner;<br>
AdWhirlLayout MAdWhirlLayout;
......
#Override
public void adWhirlGeneric() {
// TODO Auto-generated method stub
}
com.smaato.SOMA.AdListener adls=new com.smaato.SOMA.AdListener(){
#Override
public void onFailedToReceiveAd(AdDownloader arg0, ErrorCode arg1) {
// TODO Auto-generated method stub
//AdWhirl will now load from another ad network you have added
mBanner.setAutoRefresh(false);
mBanner.removeAdListener(adls);
MAdWhirlLayout.rollover();
}
#Override
public void onReceiveAd(AdDownloader arg0, SOMAReceivedBanner arg1) {
// TODO Auto-generated method stub
Log.v("SUMO Listener", "Ad Received.");
//AdWhirl will wait for 30 seconds or so before it will start requesting ad
mBanner.setAutoRefresh(false);
mBanner.removeAdListener(adls);
MAdWhirlLayout.adWhirlManager.resetRollover();
MAdWhirlLayout.rotateThreadedDelayed();
}
};
public void start_SUMO() {
mBanner= new SOMABanner(this);
mBanner.setPublisherId(**your publisher ID**);
mBanner.setAdSpaceId(**your space ID**);
mBanner.asyncLoadNewBanner();
mBanner.setAutoRefresh(true);
mBanner.addAdListener(adls);
MAdWhirlLayout.pushSubView(mBanner);
}
.....