1

谁能帮助我,从过去两天开始,我一直在尝试在 android 中实现 admob,但是收到以下错误消息-

08-08 19:05:33.362: W/webcore(3228): 在第一个布局后无法获取 viewWidth 08-08 19:10:51.632: W/dalvikvm(3328): VFY: 无法解析直接方法 3204 :Landroid/webkit/WebView;。(Landroid/content/Context;Landroid/util/AttributeSet;IZ)V 08-08 19:10:51.662: I/webclipboard(3328):clipservice: android.sec.clipboard.ClipboardExManager@40534500 08-08 19:10: 52.142:I/CordovaLog(3328):将日志级别更改为 DEBUG(3) 08-08 19:10:52.142:I/CordovaLog(3328):找到 useBrowserHistory=false 的首选项 08-08 19:10:52.142:D/ CordovaLog(3328):找到 useBrowserHistory=false 的首选项 08-08 19:10:52.152:E/dalvikvm(3328):找不到类 'android.webkit.WebResourceResponse',引用自方法 org.apache.cordova.CordovaWebViewClient。 generateWebResourceResponse 08-08 19:10:52.152: W/dalvikvm(3328): VFY:无法解析 Lorg/apache/cordova/CordovaWebViewClient 中的新实例 467 (Landroid/webkit/WebResourceResponse;);08-08 19:10:52.152: W/dalvikvm(3328): VFY: 无法找到签名中引用的类 (Landroid/webkit/WebResourceResponse;) 08-08 19:10:52.182: W/dalvikvm(3328): VFY : 找不到签名中引用的类 (Landroid/webkit/WebResourceResponse;) 08-08 19:10:52.182: W/dalvikvm(3328): VFY: 找不到签名中引用的类 (Landroid/webkit/WebResourceResponse;) 08 -08 19:10:52.182: W/dalvikvm(3328): VFY: 无法解析虚拟方法 3225: Landroid/webkit/WebViewClient;.shouldInterceptRequest (Landroid/webkit/WebView;Ljava/lang/String;)Landroid/webkit/ Web资源响应;08-08 19:10:52.182: D/DroidGap(3328): DroidGap.init() 08-08 19:10:52.192: D/CordovaWebView(3328): >>> loadUrl(file:///android_asset/www/index.html) 08-08 19:10:52.192: D/PluginManager(3328): init() 08-08 19:10:52.212: D/CordovaWebView(3328): >>> loadUrlNow() 08-08 19:10:52.272: E/Ads(3328): 找不到 com.google.ads.AdActivity,请确保它已在 AndroidManifest.xml 中注册。08-08 19:10:52.272:E/Ads(3328):您必须在 AndroidManifest.xml 中使用 configChanges 声明 AdActivity。08-08 19:10:52.282:I/webclipboard(3328):clipservice:android.sec.clipboard.ClipboardExManager@405512e0 08-08 19:10:52.332:I/webclipboard(3328):clipservice:android.sec.clipboard .ClipboardExManager@405512e0 08-08 19:10:52.902: D/AndroidRuntime(3328): 关闭 VM 08-08 19:10:52.902: W/dalvikvm(3328): threadid=1: 线程以未捕获的异常退出(组= 0x40018578) 08-08 19:10:52.902: E/AndroidRuntime(3328):

Following is the code of my main java file -


    import org.apache.cordova.*;
    import com.google.ads.*;
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.support.v4.app.NavUtils;
    import android.widget.*;

    public class Albania extends DroidGap {
        private AdView adView;


        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            super.loadUrl("file:///android_asset/www/index.html");
            super.setIntegerProperty("loadUrlTimeoutValue", 70000);
            adView = new AdView(this, AdSize.BANNER, "a1502224a0ab1f8");
            LinearLayout layout = (LinearLayout) findViewById(R.id.adView);
            layout.addView(adView);
            adView.loadAd(new AdRequest()); }

这是我的 activity_appname.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:padding="@dimen/padding_medium"
        android:text="@string/hello_world"
        tools:context=".Albania" />


    <com.google.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adSize="BANNER"
                         ads:testDevices="TEST_EMULATOR, S567041ba118d"
                         ads:loadAdOnCreate="true"/>


</RelativeLayout>

这是我的 android manifest.xml 文件

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Albania"
            android:label="@string/title_activity_albania" 
            android:configChanges="orientation|keyboardHidden|orientation|keyboard|screenSize|uiMode|screenLayout|locale"
            android:hardwareAccelerated="true" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity> 
    <activity
        android:name="com.google.ads.AdActivity"
 android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />         
    </application>
</manifest>
4

2 回答 2

0

您无需AdView在 XML 和代码中指定。只需放入ads:adUnitId="a1502224a0ab1f8"com.google.ads.AdView的 XML 中,您就可以删除以下 Adview 代码:

adView = new AdView(this, AdSize.BANNER, "a1502224a0ab1f8");
LinearLayout layout = (LinearLayout) findViewById(R.id.adView);
layout.addView(adView);
adView.loadAd(new AdRequest());

编辑:

Cordova 让您加载一个 url 并抽象您设置视图的方式。您必须手动获取 Cordova WebView 的父级,并将 AdView 添加到 parentView。代码可能如下所示:

adView = new AdView(this, AdSize.BANNER, "a1502224a0ab1f8");
// Get the parent of the cordova webview. May be able to do something like: this.webView.getParent();
parentView.addView(adView);
adView.loadAd(new AdRequest());
于 2012-08-08T21:11:07.970 回答
0

这个 SO question中,确保您的清单 xml 中有:

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15"/>
于 2012-08-08T14:16:05.200 回答