浏览器Localstorage被StartApp / adMob / mobileCore阻止

时间:2014-07-23 10:00:22

标签: cordova webview admob cordova-3 startapp

我终于设法将StartApp实施到我的cordova项目中,当一切看起来不错时,出现了最大的问题。 StartApp以某种方式搞砸了我的本地存储数据库。正如我在互联网上看到的那样,adMob也会发生这种情况。当我按住中间按钮进入最近的应用程序并强制关闭我的应用程序时,下次打开它时,来自localstorage的所有内容似乎都被剔除了。我不确定如何,但如果我进入并关闭它多次本地存储得到他的旧价值,而不是再次失去它们。

我确定它的Startapp因为如果我发表评论: StartAppSDK.init(this, "xxx", "xxx", true);一切正常。 我在网上看到,StartApp(也可能是adMob)和本地存储之间可能存在冲突。 一种方法是延迟StartApp初始化,就像我在我的代码中完成的那样。这似乎有效,但我得到了另一个问题: 通过这种方法加载横幅之后:它每秒刷新一次而不是像以前那样5-6秒,这真的令人沮丧(横幅几乎无限滚动,我无法真正阅读广告)。此解决方案的另一个问题是横幅错过了左右两侧的几个像素。所以宽度有点缩小,看起来并不好看。

注意:我注意到,当设备处于onPause时,我使用什么方法来初始化StartApp,因为我在logcat中获得了FAILED BINDER TRANSACTION。但一切正常。 onPuse和onResume中的代码被触发。我猜测这可能是StartApp弄乱本地存储的原因(因为只有当我强行关闭应用程序时才会发生这种情况,并且在强制关闭onPause事件之前触发)。

有时在onResume或应用程序启动时我得到: E / Web控制台:视口参数键""不承认和忽视。在http://www.startappexchange.com/:20

同样对我的ap没有任何影响,但也许它可能对本地存储有影响..

主要java文件:

 package com.Snap.What;

    import android.app.Activity;
    import android.os.Bundle;
    import android.os.Handler;
    import android.util.Log;
    import android.view.View;
    import android.view.ViewGroup;
    import android.webkit.JavascriptInterface;
    import android.widget.RelativeLayout;

    import org.apache.cordova.*;

    import com.startapp.android.publish.StartAppAd;
    import com.startapp.android.publish.StartAppSDK;
    import com.startapp.android.publish.banner.Banner;

    public class WhatSnap extends CordovaActivity 
    {

        private StartAppAd startAppAd = new StartAppAd(this);
        private ViewGroup layout;
        private Handler mHandler = new Handler();

        @Override
        public void onCreate(Bundle savedInstanceState){
            super.onCreate(savedInstanceState);
            super.init();
            // Set by <content src="index.html" /> in config.xml
            JavaScriptInterface jsInterface = new JavaScriptInterface(this);
            appView.getSettings().setJavaScriptEnabled(true);
            appView.addJavascriptInterface(jsInterface, "JSInterface");
            super.loadUrl(Config.getStartUrl());
            //super.loadUrl("file:///android_asset/www/index.html");


            mHandler.postDelayed(new Runnable() {
                public void run() {
                    doStuff();
                }
            }, 5000); 


            setLayout(); 
    //      showBanner();
        }

        public void doStuff(){
            StartAppSDK.init(this, "xxx", "xxx", true);
            startAppAd.loadAd(); // load the next ad
        }


        public class JavaScriptInterface {
            private Activity activity;

            public JavaScriptInterface(Activity activiy) {
                this.activity = activiy;
            }

            @JavascriptInterface
            public void displayBanner()
            {
                activity.runOnUiThread(new Runnable() {
                    public void run() {
                        //Code that interact with UI
                        initBanner();
                    }
                });

            }

            @JavascriptInterface
            public void displayexitAd()
            {
                activity.runOnUiThread(new Runnable() {
                    public void run() {
                        //Code that interact with UI
                        exitAd();
                    }
                });

            }

            @JavascriptInterface
            public void displayAd()
            {
                activity.runOnUiThread(new Runnable() {
                    public void run() {
                        //Code that interact with UI
                        showAd();
                    }
                });

            }

        }

        public void setLayout(){
            root.removeView((View) appView);
            layout = new RelativeLayout(this);

            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
            layout.setLayoutParams(lp);

            appView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
                  RelativeLayout.LayoutParams.MATCH_PARENT));

            appView.setVisibility(View.INVISIBLE);
            layout.addView((View) appView);
            setContentView(layout);

            Log.e("setLayout", "setLayout");    
        }

        public void initBanner(){
            Banner startAppBanner = new Banner(this);
            RelativeLayout.LayoutParams bannerParameters =
                        new RelativeLayout.LayoutParams(
                                    RelativeLayout.LayoutParams.WRAP_CONTENT,
                                    RelativeLayout.LayoutParams.WRAP_CONTENT);
            bannerParameters.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);  
            bannerParameters.addRule(RelativeLayout.CENTER_HORIZONTAL);
          // Add to main Layout

           layout.addView(startAppBanner, bannerParameters);

            Log.e("showBanner", "showBanner"); 
        }

        public void exitAd(){
            startAppAd.onBackPressed();
        }

        public void showAd(){
            startAppAd.showAd(); // show the ad
            startAppAd.loadAd(); // load the next ad
        }

    }

的AndroidManifest.xml:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" android:windowSoftInputMode="adjustPan" package="com.Snap.What" xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="preferExternal">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:launchMode="singleTop" android:name="WhatSnap" android:screenOrientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.startapp.android.publish.list3d.List3DActivity"
          android:theme="@android:style/Theme" />

        <activity android:name="com.startapp.android.publish.AppWallActivity"
                  android:theme="@android:style/Theme.Translucent"
                  android:configChanges="orientation|keyboardHidden|screenSize" />
    </application>
    <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    </manifest>

我还看到了一个可能的解决方法,即删除mHandler代码并覆盖onAttachedToWindow,如:

 @Override public void onAttachedToWindow() {
        super.onAttachedToWindow();

        doStuff();
    };

但有时当我强行关闭应用程序时,本地存储有时不会。

请帮助我,我花了3天时间来解决这个问题,没有任何好事发生过。

0 个答案:

没有答案