Android + HTML5 (LocalStorage) + Admob: error?

I am developing a Phonegap application (Android) that uses javascript / HTML5 LocalStorage. The application works great, however, when I add Admob to the application, localStorage does not work. Keeping in mind the saved values ​​are deleted when the application is closed forcibly or the phone restarts.

public class TestActivity extends DroidGap {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.loadUrl("file:///android_asset/www/index.html");

        // ADMOB: If comment, work.
        /*
        LinearLayout layout = super.root;
        AdView adView = new AdView(this, AdSize.BANNER, **MY_CODE_ADMOB**);
        layout.addView(adView);
        AdRequest request = new AdRequest();
        adView.loadAd(request);
        */
    }
}        

Thank!!

+2
source share
2 answers

You need to delay the code that starts the ad for a few seconds ... below worked for me.

public class youActivity extends DroidGap {
private Handler mHandler = new Handler();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.loadUrl("file:///android_asset/www/index.html");
    mHandler.postDelayed(new Runnable() {
        public void run() {
            doStuff();
        }
    }, 5000); 
}
private void doStuff() {
    final String MY_AD_UNIT_ID = "yourAD_UNIT_ID";
    AdView adView; 
    // Create the adView 
    adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID); 
    LinearLayout layout = super.root; // this is the only change from the sample 
    // Add the adView to it 
    layout.addView(adView); 
    // Initiate a generic request to load it with an ad 
    adView.loadAd(new AdRequest());
}
}
+10
source

, AdMob , Phonegap/Cordova, sqlite db apk db. , . , window.openDatabase("xxx", "1.0", "xxx", 1000000); AdRequest. , , , .

, , https://github.com/lite4cordova/Cordova-SQLitePlugin. , websql, - ( , ). , :

var db = window.sqlitePlugin.openDatabase({name: "DB"});

DB.db, 0000000000000001.db. AdMob. 2 , :

  • ondeviceready, , , db.

  • sqlite , apk, , .

0

Source: https://habr.com/ru/post/1779983/


All Articles