簡體   English   中英

Admob無法與WebView一起使用

[英]Admob not working with webview

我的問題是我的應用程序無法正常工作了。 但是當我添加admob時。 我的網絡視圖不再顯示。 我用html和CSS編寫了我的應用程序。 現在他們也沒有加入演出。

主要活動

 package webbased.wingcrony.by.worldconqueror3tipsandtricks; import android.app.Activity; import android.net.Uri; import android.os.Bundle; import android.webkit.WebView; import com.google.android.gms.ads.AdView; import com.google.android.gms.appindexing.Action; import com.google.android.gms.appindexing.AppIndex; import com.google.android.gms.appindexing.Thing; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.ads.AdRequest; import static webbased.wingcrony.by.worldconqueror3tipsandtricks.R.id.activity_main_webview; public class MainActivity extends Activity { /** * ATTENTION: This was auto-generated to implement the App Indexing API. * See https://g.co/AppIndexing/AndroidStudio for more information. */ private GoogleApiClient client; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); WebView mWebView = (WebView) findViewById(activity_main_webview); mWebView.loadUrl("file:///android_asset/www/index.html"); // Force links and redirects to open in the WebView instead of in a browser // ATTENTION: This was auto-generated to implement the App Indexing API. // See https://g.co/AppIndexing/AndroidStudio for more information. client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); AdView mAdView = (AdView) findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest); } /** * ATTENTION: This was auto-generated to implement the App Indexing API. * See https://g.co/AppIndexing/AndroidStudio for more information. */ public Action getIndexApiAction() { Thing object = new Thing.Builder() .setName("Main Page") // TODO: Define a title for the content shown. // TODO: Make sure this auto-generated URL is correct. .setUrl(Uri.parse("http://[ENTER-YOUR-HTTP-HOST-HERE]/main")) .build(); return new Action.Builder(Action.TYPE_VIEW) .setObject(object) .setActionStatus(Action.STATUS_TYPE_COMPLETED) .build(); } @Override public void onStart() { super.onStart(); // ATTENTION: This was auto-generated to implement the App Indexing API. // See https://g.co/AppIndexing/AndroidStudio for more information. client.connect(); AppIndex.AppIndexApi.start(client, getIndexApiAction()); } @Override public void onStop() { super.onStop(); // ATTENTION: This was auto-generated to implement the App Indexing API. // See https://g.co/AppIndexing/AndroidStudio for more information. AppIndex.AppIndexApi.end(client, getIndexApiAction()); client.disconnect(); } } 

Activity_main.xml

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:ads="http://schemas.android.com/apk/res-auto"> <com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" ads:adSize="BANNER" ads:adUnitId="@string/banner_ad_unit_id"/> <WebView android:id="@+id/activity_main_webview" android:layout_width="match_parent" android:layout_height="match_parent"/> </RelativeLayout> 

build.gradle文件

 apply plugin: 'com.android.application' android { compileSdkVersion 24 buildToolsVersion "24.0.3" defaultConfig { applicationId "webbased.wingcrony.by.worldconqueror3tipsandtricks" minSdkVersion 11 targetSdkVersion 24 versionCode 3 versionName "3.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } productFlavors { } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:24.2.1' compile 'com.google.android.gms:play-services-appindexing:9.6.1' compile 'com.google.firebase:firebase-ads:9.6.1' testCompile 'junit:junit:4.12' return true } // `return void` removes the lint error: `Not all execution paths return a value`. return void } 

AndroidManifest.xml

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="webbased.wingcrony.by.worldconqueror3tipsandtricks"> <uses-permission android:name="android.permission.INTERNET" /> <application android:allowBackup="false" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter><!-- ATTENTION: This intent was auto-generated. Follow instructions at https://g.co/AppIndexing/AndroidStudio to publish your URLs. --> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <!-- ATTENTION: This data URL was auto-generated. We recommend that you use the HTTP scheme. TODO: Change the host or pathPrefix as necessary. --> <data android:host="[ENTER-YOUR-HTTP-HOST-HERE]" android:pathPrefix="/main" android:scheme="http" /> </intent-filter> </activity><!-- ATTENTION: This was auto-generated to add Google Play services to your project for App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. --> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> </application> </manifest> 

誰能幫我,使我的Webview應用程序與admob一起使用? 我想我做錯了。 但是我不知道。

 <com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/banner_ad_unit_id1"></com.google.android.gms.ads.AdView>

將此代碼用於AdView

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM