2014-08-28 145 views
0

我知道这里有一些帖子,但他们没有解决我的问题。 事情是:loadUrl()与CordovaWebView崩溃

我有一个科尔多瓦应用程序(android平台)。在我的activity_main.xml中,我声明了一个CordovaWebView,并且我想调用loadUrl()方法来加载位于我的资产文件夹中的网站。当我调用该方法时,应用程序崩溃显示“不确定,MyApp已停止”。

奇怪的事情我注意到:

  • 如果我仿真RLS使用的设备具有API 10或16,这WORKS FINE。如果我用17测试它,那么NOT WORK

  • 如果我不使用CordovaWebView并直接调用:this.loadUrl("file:///android_asset/www/index.html");它工作正常,但它就像我没有使用我定义的布局(所以我没有我的广告横幅)。

有关此问题的任何想法?

谢谢!

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:id="@+id/layout_home" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

     <LinearLayout 
      android:id="@+id/layout_body" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" 
      android:layout_above="@+id/layout_banner" 
      android:background="@color/abc_search_url_text_normal"> 

      <org.apache.cordova.CordovaWebView 
        android:id="@+id/webview" 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_weight="1" 
        android:background="@color/common_signin_btn_dark_text_disabled" /> 
     </LinearLayout> 
     <RelativeLayout 
      android:id="@+id/layout_banner" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:background="@color/wallet_hint_foreground_holo_dark"> 
     </RelativeLayout> 
</RelativeLayout> 

MainAcitivy.java

public class MainActivity extends CordovaActivity { 

CordovaWebView cwv; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    ..LOAD ADVERTISEMENT INTO LAYOUT_BANNER... 

    cwv = (CordovaWebView) findViewById(R.id.webview); 
    cwv.getSettings().setJavaScriptEnabled(true); 
    cwv.loadUrl("file:///android_asset/www/index.html"); 
} 
+0

为什么你需要activity_main.xml和所有android的东西,只需使用cordova命令行启动一个新的项目。标准的cordova项目中不需要任何xml。 – mentat 2014-08-29 06:25:04

+0

@mentat,如果我按你说的做,我该如何在底部添加广告横幅? – user2422900 2014-08-29 12:08:37

+0

我不知道你用什么横幅,但理论上你可以把它放在你的html中的div上。 – mentat 2014-08-29 12:54:47

回答

-1

为什么你需要activity_main.xml中和所有的Android的东西,用科尔多瓦命令行刚开始一个新的项目。标准的cordova项目中不需要任何xml。

你有科尔多瓦插件内部科尔多瓦网络视图中显示AdMob广告,看http://plugreg.com/search?q=admob