1.新建项目在app目录下新建文件夹libs,用于导入腾讯内核jar依赖包
2.main目录下新建jniLibs文件夹,用于存放x5内核的.so文件,播放视频用.
3.配置app目录下的build.gradle文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
applicationId "com.x5.nh"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
//确保64位可以播放
ndk {
abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/tbs_sdk_thirdapp_v3.5.0.1004_43500_sharewithdownload_withoutGame_obfs_20170801_113025.jar')
}
4.新建布局main.xml文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<com.tencent.smtt.sdk.WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="5dp"
android:paddingRight="5dp"/>
</LinearLayout>
5.新建MainActivity.java
package com.x5.nh;
import android.app.*;
import android.content.*;
import android.graphics.*;
import android.net.*;
import android.os.*;
import com.tencent.smtt.sdk.*;
public class MainActivity extends Activity
{
private WebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (com.tencent.smtt.sdk.WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);// 支持js
mWebView.setWebViewClient(new WebViewClient());//防止加载网页时调起系统浏览器
String url=mWebView.getUrl();
mWebView.loadUrl("https://www.jianshu.com/mobile/users/b010af3454b7/rewards/new");
//mWebView.loadUrl("http://192.240.120.102:8081/live/rec_c20289.m3u8");
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
final Activity context = MainActivity.this;
// ===========调用微信支付页面===========
// 如下方案可在非微信内部WebView的H5页面中调出微信支付
if (url.startsWith("weixin://wap/pay?") || url.startsWith("alipay") || url.startsWith("wechat"))
{
try
{
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
catch (Exception e)
{
e.printStackTrace();
}
return true;
}
return false;
}
//@Override
public void onPageStarted(WebView webView, String s, Bitmap bitmap)
{
super.onPageStarted(webView, s, bitmap);
}
@Override
public void onPageFinished(WebView view, String url)
{
super.onPageFinished(view, url);
}
});}}
6.新建MyAplication.java进行初始化
package com.x5.nh;
import android.app.Application;
import android.util.Log;
import com.tencent.smtt.sdk.QbSdk;
public class MyAplication extends Application {
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
initX5();
}
/**
* 初始化X5
*/
private void initX5() {
//x5內核初始化回调
QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback() {
@Override
public void onViewInitFinished(boolean arg0) {
// TODO Auto-generated method stub
//x5內核初始化完成的回调,为true表示x5内核加载成功,否则表示x5内核加载失败,会自动切换到系统内核。
Log.d("app", " onViewInitFinished is " + arg0);
}
@Override
public void onCoreInitFinished() {
// TODO Auto-generated method stub
}
};
//x5内核初始化接口
QbSdk.initX5Environment(getApplicationContext(), cb);
}
}
7.直接打包,咋们来看看效果吧!