Integrating of Analytics doesn´t work - android

I try to integrate google Analytics to my Application but it doesn´t work.
This is my Activity:
public class InhaltsverzeichnisActivity extends Activity {
private SharedPreferencesManager prefs; //added
private InterstitialAd Interstitial;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.inhaltsverzeichnis);
prefs = new SharedPreferencesManager(this); //get SharedPreferencesManager instance
int t = prefs.retrieveInt("theme", 0); //get stored theme, zero is default
ThemeUtils.setTheme(t); //Set the stored theme, will default to Black
Tracker t1 = ((AnalyticsSampleApp)this.getApplication()).getTracker(TrackerName.APP_TRACKER);
t1.setScreenName("Inhaltsverzeichnis");
t1.send(new HitBuilders.AppViewBuilder().build());
Interstitial = new InterstitialAd(this);
Interstitial.setAdUnitId("ca-app-pub-XXXXXXXXXXXXX/XXXXXXXXXX");
AdRequest adRequest = new AdRequest.Builder().build();
Interstitial.loadAd(adRequest);
;
Interstitial.setAdListener(new AdListener(){
public void onAdLoaded(){
displayInterstitial();
Interstitial.show();
}
});
}
protected void displayInterstitial() {
// TODO Auto-generated method stub
}
public void onDismissScreen() {
// TODO Auto-generated method stub
}
public void onFailedToReceiveAd() {
// TODO Auto-generated method stub
}
public void onLeaveApplication() {
// TODO Auto-generated method stub
}
public void onPresentScreen() {
// TODO Auto-generated method stub
}
#Override
protected void onStart() {
super.onStart();
GoogleAnalytics.getInstance(InhaltsverzeichnisActivity.this).reportActivityStart(this);
}
#Override
protected void onStop() {
super.onStop();
GoogleAnalytics.getInstance(InhaltsverzeichnisActivity.this).reportActivityStop(this);
}
If I put the OnStart and OnStop method over the Interstitial Ad , Analytics works, but the Interstitial Ad goes crazy and appears every second again,
hope anyone can help me to solve this problem thanks.

Related

Admob interstitial ads are not closing

I'm showing interstitial ad in my app and ads are loading and displaying perfectly but the issue is that ads are not closing when I click cross button on back button I have to quit my app to close them
I created a new project and checked the ads in new project they are working fine and closing on back button but in my main app ads are not closing once they displayed to user
this is my Admob class
public class Admob {
public static InterstitialAd mInterstitial; // Interstital
private static AdView mAdView; // banner
public static void createLoadInterstitial(final Context context, View view)
{
mInterstitial = new InterstitialAd(context);
mInterstitial.setAdUnitId(context.getResources().getString(
R.string.admob_showIntersitial_ad_unit_id));
mInterstitial.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
// TODO Auto-generated method stub
showInterstitial();
}
#Override
public void onAdFailedToLoad(int errorCode) {
// TODO Auto-generated method stub
super.onAdFailedToLoad(errorCode);
}
#Override
public void onAdOpened() {
// TODO Auto-generated method stub
super.onAdOpened();
}
#Override
public void onAdClosed() {
// TODO Auto-generated method stub
super.onAdClosed();
}
#Override
public void onAdLeftApplication() {
// TODO Auto-generated method stub
// Called when an ad leaves the app (for example, to go to the
// browser).
super.onAdLeftApplication();
}
});
loadInterstitial();
}
public static void loadInterstitial() {
mInterstitial.loadAd(new AdRequest.Builder().
addTestDevice("").//ca-app-pub-3940256099942544/1033173712
build());
}
public static void showInterstitial() {
if (mInterstitial.isLoaded()) {
mInterstitial.show();
}
}
public static void createLoadBanner(final Context context, View view) {
mAdView = (AdView) view.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().
addTestDevice("").//ca-app-pub-3940256099942544/6300978111
build();
mAdView.loadAd(adRequest);
mAdView.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
// TODO Auto-generated method stub
super.onAdLoaded();
}
#Override
public void onAdClosed() {
// TODO Auto-generated method stub
super.onAdClosed();
}
#Override
public void onAdOpened() {
// TODO Auto-generated method stub
super.onAdOpened();
}
#Override
public void onAdLeftApplication() {
// TODO Auto-generated method stub
super.onAdLeftApplication();
}
#Override
public void onAdFailedToLoad(int errorCode) {
// TODO Auto-generated method stub
super.onAdFailedToLoad(errorCode);
}
});
}
}
This is how I show them in my activity
MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
Admob.createLoadInterstitial(this,null);
I have initialize this in Mainfest also
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713" />
I saw same questions on stackoverflow but none of them is answered the solution so any help will be really appreciated
If you are using Webiew check if there is webview is paused on ad shown

Web View running on other than UI thread

I am trying to show flurry interstitial but getting following message in debug screen and I am not receiving interstitial on my screen.
07-14 15:55:31.390: W/webview(10588): java.lang.Throwable: Warning: A
WebView method was called on thread 'FlurryAgent'. All WebView methods
must be called on the UI thread. Future versions of WebView may not
support use on other threads.
I have followed this tutorial completely :
Android Integration
At present I am working on AndEngine. As error replying I put my all code in UI thread but result is same.
Here is my code for displaying ads :
protected void onCreate(Bundle pSavedInstanceState) {
super.onCreate(pSavedInstanceState);
// configure Flurry
FlurryAgent.setLogEnabled(false);
// init Flurry
FlurryAgent.init(MainGameActivity.this, MY_FLURRY_APIKEY);
mFlurryAdInterstitial = new FlurryAdInterstitial(MainGameActivity.this,
MY_ADSPACE_NAME);
FlurryAdTargeting adTargeting = new FlurryAdTargeting();
// enable test mode for this interstitial ad unit
adTargeting.setEnableTestAds(true);
mFlurryAdInterstitial.setTargeting(adTargeting);
// allow us to get callbacks for ad events
mFlurryAdInterstitial.setListener(interstitialAdListener);
mFlurryAdInterstitial.fetchAd();
}
FlurryAdInterstitialListener interstitialAdListener = new FlurryAdInterstitialListener() {
#Override
public void onFetched(final FlurryAdInterstitial adInterstitial) {
adInterstitial.displayAd();
}
#Override
public void onError(final FlurryAdInterstitial adInterstitial,
FlurryAdErrorType adErrorType, int errorCode) {
adInterstitial.destroy();
}
#Override
public void onAppExit(FlurryAdInterstitial arg0) {
// TODO Auto-generated method stub
}
#Override
public void onClicked(FlurryAdInterstitial arg0) {
// TODO Auto-generated method stub
}
#Override
public void onClose(FlurryAdInterstitial arg0) {
// TODO Auto-generated method stub
}
#Override
public void onDisplay(FlurryAdInterstitial arg0) {
// TODO Auto-generated method stub
}
#Override
public void onRendered(FlurryAdInterstitial arg0) {
// TODO Auto-generated method stub
}
#Override
public void onVideoCompleted(FlurryAdInterstitial arg0) {
// TODO Auto-generated method stub
}
};
#Override
protected void onStart() {
super.onStart();
FlurryAgent.onStartSession(MainGameActivity.this);
}
#Override
protected void onStop() {
super.onStop();
FlurryAgent.onEndSession(MainGameActivity.this);
}
#Override
public void onDestroy() {
super.onDestroy();
mFlurryAdInterstitial.destroy();
}
So what can I do in this situation?

how to place ads in admob in app

how to use ad-mob in app and what are the steps how i post ads in ad-mob how can i test in my device before uploading to Google play store.i am new to ad-mob. please explain me with sample example of it by step-wise.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.interstitialAds = new InterstitialAd(this, "ca-app-pub-****");
this.interstitialAds.setAdListener(this);
Button loadButton = (Button) this.findViewById(R.id.loadButton);
loadButton.setOnClickListener(loadButtonOnClick);
this.textView = (TextView) this.findViewById(R.id.stateTextView);
}
private OnClickListener loadButtonOnClick = new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
textView.setText("Loading Intertitial Ads");
AdRequest adr = new AdRequest();
// add your test device here
adr.addTestDevice(AdRequest.TEST_EMULATOR);
interstitialAds.loadAd(adr);
}
};
#Override
public void onDismissScreen(Ad arg0) {
// TODO Auto-generated method stub
}
#Override
public void onFailedToReceiveAd(Ad ad, ErrorCode error) {
String message = "Load Ads Failed: (" + error + ")";
textView.setText(message);
}
#Override
public void onLeaveApplication(Ad arg0) {
// TODO Auto-generated method stub
}
/**
* Called when an Activity is created in front of the app (e.g. an
* interstitial is shown, or an ad is clicked and launches a new Activity).
*/
#Override
public void onPresentScreen(Ad arg0) {
// TODO Auto-generated method stub
}
#Override
public void onReceiveAd(Ad arg0) {
if (interstitialAds.isReady()) {
interstitialAds.show();
} else {
textView.setText("Interstitial ad was not ready to be shown.");
}
}
}
Get rid of your AdListener.
Call intersitial.loadAd in your constructor
Call interstitial.show at a natural break point in your app
Call interstitial.loadAd
Go to 3.
See https://developers.google.com/mobile-ads-sdk/docs/admob/android/interstitial

InterstitialAd should load after every exposure

I need to use InterstitialAd in my app. But the problem is that after first exposure, before showing I am creating ad, call loadAd method with request, and than show (calling show method)it in the right moment. Everything seems to work good, but when I try to call show method next time it doesn't work because of isLoaded returns false.
Is there any way to load ad only once.
EDIT
Thx for answer, but the main problem is that loadAd is network connection, but the google suggest not to perform internet tasks in main thread, so what the f..k it is loading ad from the internet in main ui thread.It causes lags in my app. They are contradicting themselves.
You'd have to reload the ad anytime it's closed. I define a single method "reloadInterstitial()" and invoke it within the onCreate() method. It works great. All you have to do is call displayInterstitial() whenever you wish you to show the ad:
public class MyActivityClass extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
interstitial = new InterstitialAd(MyActivityClass.this);
interstitial.setAdUnitId("*****");
reloadInterstitial();
// Create ad request
AdRequest adRequest = new AdRequest.Builder().build();
// Begin loading your interstitial
interstitial.loadAd(adRequest);
}
public void displayInterstitial(){
if(interstitial != null && interstitial.isLoaded())
interstitial.show();
}
private void reloadInterstitial(){
interstitial.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
// TODO Auto-generated method stub
super.onAdLoaded();
}
#Override
public void onAdFailedToLoad(int errorCode) {
// TODO Auto-generated method stub
super.onAdFailedToLoad(errorCode);
interstitial = new InterstitialAd(MyActivityClass.this);
interstitial.setAdUnitId("*****");
// Begin loading your interstitial
interstitial.loadAd(new AdRequest.Builder().build());
loadInterCallBacks();
}
#Override
public void onAdOpened() {
// TODO Auto-generated method stub
super.onAdOpened();
}
#Override
public void onAdClosed() {
// TODO Auto-generated method stub
super.onAdClosed();
interstitial = new InterstitialAd(MyActivityClass.this);
interstitial.setAdUnitId("****");
loadInterCallBacks();
// Begin loading your interstitial
interstitial.loadAd(new AdRequest.Builder().build());
}
#Override
public void onAdLeftApplication() {
// TODO Auto-generated method stub
super.onAdLeftApplication();
}
});
}
private void loadInterCallBacks(){
interstitial.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
// TODO Auto-generated method stub
super.onAdLoaded();
}
#Override
public void onAdFailedToLoad(int errorCode) {
// TODO Auto-generated method stub
super.onAdFailedToLoad(errorCode);
interstitial = new InterstitialAd(MyActivityClass.this);
interstitial.setAdUnitId("xxxxxxxxxxx");
// Begin loading your interstitial
interstitial.loadAd(new AdRequest.Builder().build());
loadInterCallBacks();
}
#Override
public void onAdOpened() {
// TODO Auto-generated method stub
super.onAdOpened();
}
#Override
public void onAdClosed() {
// TODO Auto-generated method stub
super.onAdClosed();
interstitial = new InterstitialAd(MyActivityClass.this);
interstitial.setAdUnitId("xxxxxx");
loadInterCallBacks();
// Begin loading your interstitial
interstitial.loadAd(new AdRequest.Builder().build());
}
#Override
public void onAdLeftApplication() {
// TODO Auto-generated method stub
super.onAdLeftApplication();
}
});
}

how to call ad mob ads show in some time intervals or different Activity in android apps

I am use ads of ad mob for advertise in my application its always display on on start up of my application but I want display this ads on when user exit application and back to the main activity call so how it implement in my app
my code is
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
interstitial = new InterstitialAd(this, "a152eb628a493d8");
adRequest = new AdRequest();
interstitial.loadAd(adRequest);
interstitial.setAdListener(this);
web=(WebView)findViewById(R.id.webview);
web.getSettings().setJavaScriptEnabled(true);
web.setWebViewClient(new WebViewClient());
web.getSettings().setBuiltInZoomControls(true);
web.loadUrl("http://dcs-dof.gujarat.gov.in/live-info.htm");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0,1,Menu.NONE,"About");
menu.add(0,2,Menu.NONE,"Feedback");
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id=item.getItemId();
if(id == 1)
{
Toast.makeText(MainActivity2.this,"About",Toast.LENGTH_LONG).show();
Intent i=new Intent(MainActivity2.this,about.class);
startActivity(i);
}
else {
Toast.makeText(MainActivity2.this,"Feedback",Toast.LENGTH_LONG).show();
Intent i2 =new Intent(MainActivity2.this,feedback.class);
startActivity(i2);
}
return super.onOptionsItemSelected(item);
}
private boolean doubleBackToExitPressedOnce = false;
#Override
protected void onResume() {
//interstitial.loadAd(adRequest);
super.onResume();
this.doubleBackToExitPressedOnce = false;
}
#Override
public void onBackPressed() {
if (doubleBackToExitPressedOnce) {
super.onBackPressed();
return;
}
this.doubleBackToExitPressedOnce = true;
Toast.makeText(this,"Press Again to Exit", Toast.LENGTH_SHORT).show();
}
#Override
public void onDismissScreen(Ad ad) {
// TODO Auto-generated method stub
}
#Override
public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
// TODO Auto-generated method stub
}
#Override
public void onLeaveApplication(Ad arg0) {
// TODO Auto-generated method stub
}
#Override
public void onPresentScreen(Ad arg0) {
// TODO Auto-generated method stub
}
#Override
public void onReceiveAd(Ad ad) {
Log.d("OK", "Received ad");
if (ad == interstitial) {
interstitial.show();
}
}
#Override
protected void onRestart() {
// TODO Auto-generated method stub
// interstitial.loadAd(adRequest);
super.onRestart();
}
#Override
protected void onStart() {
// TODO Auto-generated method stub
// interstitial.loadAd(adRequest);
super.onStart();
}
#Override
protected void onDestroy() {
// TODO Auto-generated method stub
//interstitial.loadAd(adRequest);
super.onDestroy();
}
#Override
protected void onStop() {
// TODO Auto-generated method stub
//interstitial.loadAd(adRequest);
super.onStop();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
// interstitial.loadAd(adRequest);
super.onPause();
}
You really don't want to attempt to display an ad to a user on exit from your Actvity, it is a poor user experience.
Even if you did orchestrate a way to get the ad and present prior to your Activity's destruction you don't know how long it will take to retrieve the ad so your Activity might hang for several seconds on exit. User's hate that kind of thing.
I strongly suggest you find another spot within your app in which to display ads.

Categories

Resources