android ndk webview,Android 集成 X5 WebView

AndroidManifest.xml

1.添加jar包

在libs目录下添加sdk中的jar包

将Demo中的jniLibs目录复制到 main文件夹下

2.需要添加权限

3.build.gradle 添加配置

ndk {

abiFilters "armeabi", "armeabi-v7a", "x86", "mips"

}

4.页面

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

package="com.sykj.article.articlesystem">

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">

web_view.xml

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">

android:id="@+id/web_view"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:paddingLeft="5dp"

android:paddingRight="5dp" />

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')

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值