少年击剑更吹箫,剑气箫心一例消。这篇文章主要讲述Android 集成 X5 WebView相关的知识,希望能为你提供帮助。
AndroidManifest.xml
1.添加jar包
在libs目录下添加sdk中的jar包
将Demo中的jniLibs目录复制到 main文件夹下
2.需要添加权限
<
uses-permission android:name="
android.permission.WRITE_EXTERNAL_STORAGE"
/>
<
uses-permission android:name="
android.permission.ACCESS_NETWORK_STATE"
/>
<
uses-permission android:name="
android.permission.ACCESS_WIFI_STATE"
/>
<
uses-permission android:name="
android.permission.INTERNET"
/>
<
uses-permission android:name="
android.permission.READ_PHONE_STATE"
/>
3.build.gradle 添加配置
ndk {
abiFilters "
armeabi"
, "
armeabi-v7a"
, "
x86"
, "
mips"
}
4.页面
<
com.tencent.smtt.sdk.WebView
android:id="
@+id/web_view"
android:layout_width="
fill_parent"
android:layout_height="
fill_parent"
android:paddingLeft="
5dp"
android:paddingRight="
5dp"
/>
5.Activity
package com.sykj.article.articlesystem;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import com.tencent.smtt.sdk.QbSdk;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;
public class MainActivity extends AppCompatActivity {private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.web_view);
initX5WebView();
webView = findViewById(R.id.web_view);
//防止跳转到系统浏览器
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
loadurlLocalMethod(view, url);
return false;
}
});
webView.loadUrl("
http://www.baidu.com"
);
}public void loadurlLocalMethod(final WebView webView, final String url) {
new Thread(new Runnable() {
@Override
public void run() {
webView.loadUrl(url);
}
});
}private void initX5WebView() {
//搜集本地tbs内核信息并上报服务器,服务器返回结果决定使用哪个内核。
QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback() {
@Override
public void onViewInitFinished(boolean arg0) {
if (arg0) {
Log.d("
ArticleSystem"
, "
X5 内核加载成功"
);
} else {
Log.d("
ArticleSystem"
, "
X5 内核加载失败"
);
}
}@Override
public void onCoreInitFinished() {
}
};
//x5内核初始化接口
QbSdk.initX5Environment(getApplicationContext(), cb);
}
}
完整配置
AndroidManifest.xml
<
?xml version="
1.0"
encoding="
utf-8"
?>
<
manifest xmlns:android="
http://schemas.android.com/apk/res/android"
package="
com.sykj.article.articlesystem"
>
<
uses-permission android:name="
android.permission.WRITE_EXTERNAL_STORAGE"
/>
<
uses-permission android:name="
android.permission.ACCESS_NETWORK_STATE"
/>
<
uses-permission android:name="
android.permission.ACCESS_WIFI_STATE"
/>
<
uses-permission android:name="
android.permission.INTERNET"
/>
<
uses-permission android:name="
android.permission.READ_PHONE_STATE"
/>
<
application
android:allowBackup="
true"
android:icon="
@mipmap/ic_launcher"
android:label="
@string/app_name"
android:roundIcon="
@mipmap/ic_launcher_round"
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>
<
/activity>
<
/application>
<
/manifest>
web_view.xml
<
?xml version="
1.0"
encoding="
utf-8"
?>
<
android.support.constraint.ConstraintLayout xmlns:android="
http://schemas.android.com/apk/res/android"
xmlns:app="
http://schemas.android.com/apk/res-auto"
xmlns:tools="
http://schemas.android.com/tools"
android:layout_width="
match_parent"
android:layout_height="
match_parent"
tools:context="
.MainActivity"
>
<
com.tencent.smtt.sdk.WebView
android:id="
@+id/web_view"
android:layout_width="
fill_parent"
android:layout_height="
fill_parent"
android:paddingLeft="
5dp"
android:paddingRight="
5dp"
/>
<
/android.support.constraint.ConstraintLayout>
【Android 集成 X5 WebView】build.gradle
apply plugin: '
com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "
com.sykj.article.articlesystem"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "
1.0"
testInstrumentationRunner "
android.support.test.runner.AndroidJUnitRunner"
ndk {
abiFilters "
armeabi"
, "
armeabi-v7a"
, "
x86"
, "
mips"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('
proguard-android.txt'
), '
proguard-rules.pro'
}
}
}dependencies {
implementation fileTree(include: ['
*.jar'
], dir: '
libs'
)
implementation '
com.android.support:appcompat-v7:27.1.1'
implementation '
com.android.support.constraint:constraint-layout:1.1.3'
testImplementation '
junit:junit:4.12'
androidTestImplementation '
com.android.support.test:runner:1.0.2'
androidTestImplementation '
com.android.support.test.espresso:espresso-core:3.0.2'
implementation files('
libs/tbs_sdk_thirdapp_v3.6.0.1352_43618_sharewithdownload_withoutGame_obfs_20180918_120327.jar'
)
}
推荐阅读
- android形状属性锁屏密码动态模糊kotlin项目抖音动画记账app视频播放器等源码
- AutoCAD中的Donut和Helix
- AutoCAD单位介绍和设置图解
- AutoCAD学生版2020下载和安装详细图解
- AutoCAD锥面和切片
- APPIUM-----自动发现兼容的Chromedrivers
- 信用卡智能代还APP系统以及信贷分销系统未来的市场和趋势!!
- PlusToken持币生息app软件
- 支付宝下载|支付宝app下载