android crosswalk 集成
生活随笔
收集整理的這篇文章主要介紹了
android crosswalk 集成
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
crosswalk 集成
在項目根路徑下的 build.gradle 中添加:
buildscript {repositorities {……}}allprojects {repositories {……maven { url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2'}}}在對應(yīng) module 的 build.gradle 中添加依賴:
android {......defaultConfig { targetSdkVersion 28 //改為28或以下,28以上會有異常.......ndk {// 設(shè)置支持的SO庫架構(gòu)abiFilters 'armeabi-v7a','x86'}}.......sourceSets {main {// 添加libs/so中的so文件jniLibs.srcDirs = ['libs']}}}dependencies {implementation 'org.xwalk:xwalk_core_library:23.53.589.4' }libs下放入對應(yīng)的架構(gòu)的so庫, so 下載地址
在 AndroidManifest.xml 中添加權(quán)限:
<Application android:hardwareAccelerated="true" /> //開啟硬件加速<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" />布局文件:
<org.xwalk.core.XWalkViewandroid:id="@+id/xWalkWebView"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" />代碼:
package com.gamebox.crosswalktest;import android.content.Intent; import android.os.Bundle; import android.util.Log;import org.xwalk.core.XWalkActivity; import org.xwalk.core.XWalkPreferences; import org.xwalk.core.XWalkView;public class MainActivity extends XWalkActivity {private static final String TAG = "MainActivity";private XWalkView xWalkWebView;@Overrideprotected void onXWalkReady() {xWalkWebView = (XWalkView) findViewById(R.id.xWalkWebView); // xWalkWebView.load("http://baidu.com", null);xWalkWebView.loadUrl("https://baidu.com");// 開啟調(diào)試(然后使用chrome打開頁面chrome://inspect)XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true);}@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Log.e(TAG, "onCreate: -----");}@Overrideprotected void onResume() {super.onResume();Log.e(TAG, "onResume: -----");if (xWalkWebView != null) {xWalkWebView.resumeTimers();xWalkWebView.onShow();}}@Overrideprotected void onPause() {super.onPause();Log.e(TAG, "onPause: -----");if (xWalkWebView != null) {xWalkWebView.pauseTimers();xWalkWebView.onHide();}}@Overrideprotected void onDestroy() {super.onDestroy();Log.e(TAG, "onDestroy: -----");if (xWalkWebView != null) {xWalkWebView.onDestroy();}}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);Log.e(TAG, "onActivityResult: -----");if (xWalkWebView != null) {xWalkWebView.onActivityResult(requestCode, resultCode, data);}}@Override protected void onNewIntent(Intent intent) {super.onNewIntent(intent);Log.e(TAG, "onNewIntent: -----");if (xWalkWebView != null) {xWalkWebView.onNewIntent(intent);}}}總結(jié)
以上是生活随笔為你收集整理的android crosswalk 集成的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 牛客 NC24858 [USACO 20
- 下一篇: while循环CPU占用率高问题深入分析