java Admob不使用webview
我的问题是我的应用程序不再工作了。但当我添加admob时。我的网络视图不再显示。我用html和Css编程了我的应用程序。而且现在他们的照片也没有显示出来
主要活动。爪哇
package webbased.wingcrony.by.worldconqueror3tipsandtricks;
import 安卓.app.Activity;
import 安卓.net.Uri;
import 安卓.os.Bundle;
import 安卓.webkit.WebView;
import com.google.安卓.gms.ads.AdView;
import com.google.安卓.gms.appindexing.Action;
import com.google.安卓.gms.appindexing.AppIndex;
import com.google.安卓.gms.appindexing.Thing;
import com.google.安卓.gms.common.api.GoogleApiClient;
import com.google.安卓.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:///安卓_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();
}
}
主要活动。xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
xmlns:ads="http://schemas.安卓.com/apk/res-auto">
<com.google.安卓.gms.ads.AdView
安卓:id="@+id/adView"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_centerHorizontal="true"
安卓:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id"/>
<WebView
安卓:id="@+id/activity_main_webview"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"/>
</RelativeLayout>
建造。格雷德尔锉刀
apply plugin: 'com.安卓.application'
安卓 {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "webbased.wingcrony.by.worldconqueror3tipsandtricks"
minSdkVersion 11
targetSdkVersion 24
versionCode 3
versionName "3.0"
testInstrumentationRunner "安卓.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-安卓.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
安卓TestCompile('com.安卓.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.安卓.support', module: 'support-annotations'
})
compile 'com.安卓.support:appcompat-v7:24.2.1'
compile 'com.google.安卓.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:安卓="http://schemas.安卓.com/apk/res/安卓"
package="webbased.wingcrony.by.worldconqueror3tipsandtricks">
<uses-permission 安卓:name="安卓.permission.INTERNET" />
<application
安卓:allowBackup="false"
安卓:icon="@mipmap/ic_launcher"
安卓:label="@string/app_name"
安卓:supportsRtl="true"
安卓:theme="@style/AppTheme">
<activity 安卓:name=".MainActivity">
<intent-filter>
<action 安卓:name="安卓.intent.action.MAIN" />
<category 安卓:name="安卓.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 安卓:name="安卓.intent.action.VIEW" />
<category 安卓:name="安卓.intent.category.DEFAULT" />
<category 安卓:name="安卓.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
安卓:host="[ENTER-YOUR-HTTP-HOST-HERE]"
安卓:pathPrefix="/main"
安卓: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
安卓:name="com.google.安卓.gms.version"
安卓:value="@integer/google_play_services_version" />
</application>
</manifest>
有人能帮我让我的webview应用程序与admob配合使用吗? 我想我做错了什么。但我不知道是什么
# 1 楼答案
将此代码用于AdView