CrossWalk的XWalkView Angular2js 自制Android Studio浏览器

1.前言
XWalkView是Crosswalk提供的webview,可用于替代系统原生的webview
公司做的网页是用Angular2js,导致在原生android 的webview运行不起来
腾讯的x5内核也运行不起来,最后偶然发现CrossWalk的XWalkView

2.使用步骤
在app的build.gradle中,添加maven地址和complie

CrossWalk的XWalkView Angular2js 自制Android Studio浏览器_第1张图片
648808A8-06FF-482E-86E9-C092C42F5FDD.png
  1. ndk {
    abiFilters "armeabi-v7a"
    }
  2. repositories {
    maven { url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2' }
    }
  3. compile 'org.xwalk:xwalk_core_library:23.53.589.4'

4.添加权限








5.MainActivity

package com.tuojie.webview;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.Toast;
import org.xwalk.core.XWalkView;

public class MainActivity extends AppCompatActivity {
private XWalkView mXWalkView;
private long lastClickBackTime;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //取消状态栏
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);
    mXWalkView = (XWalkView) findViewById(R.id.webview);

    mXWalkView.getNavigationHistory().clear();  //清除历史记录
    mXWalkView.setDrawingCacheEnabled(false);   //不使用缓存
    mXWalkView.clearCache(true);                //清楚包括磁盘缓存
    mXWalkView.load("-----", null);         //写入要加载的网址
}

@Override
protected void onPause() {
    super.onPause();
    if (mXWalkView != null) {
        mXWalkView.pauseTimers();
        mXWalkView.onHide();
    }
}

@Override
protected void onResume() {
    super.onResume();
    if (mXWalkView != null) {
        mXWalkView.resumeTimers();
        mXWalkView.onShow();
    }
}

@Override
protected void onDestroy() {
    super.onDestroy();
    if (mXWalkView != null) {
        mXWalkView.onDestroy();
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (mXWalkView != null) {
        mXWalkView.onActivityResult(requestCode, resultCode, data);
    }
}

@Override
protected void onNewIntent(Intent intent) {
    if (mXWalkView != null) {
        mXWalkView.onNewIntent(intent);
    }
}

//监听返回键
@Override
public void onBackPressed() {
    if (System.currentTimeMillis() - lastClickBackTime > 2000) { // 后退阻断
        Toast.makeText(getApplicationContext(),"再点一次退出应用",Toast.LENGTH_LONG).show();
        lastClickBackTime = System.currentTimeMillis();
    } else { // 关掉app
        super.onBackPressed();
    }
}

}

Sum:有问题欢迎您指教,谢谢你

你可能感兴趣的:(CrossWalk的XWalkView Angular2js 自制Android Studio浏览器)