中文

Experience Sharing: How to embed Crosswalk's WebView (XWalkView) in Android Studio

1. Download Crosswalk WebView package from https://crosswalk-project.org/documentation/downloads.html , and unzip
2. Copy xwalk_core_library_java.jar from crosswalk libs to app/libs directory, right click this file, select "Add As Library..."
3. Copy other resources (so files) from crosswalk libs to app/src/main/jniLibs directory
4. Add new resource folder res2, and copy all files from crosswalk res directory to res2
5. Modify AndroidMenifest.xml, add permissions as follows:
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
add following attribue to application node: android:hardwareAccelerated="true" (crosswalk webview can only works when hardware accelerate enabled) 6. In layout file, add following codes:
      <org.xwalk.core.XWalkView android:id="@+id/webview"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
    </org.xwalk.core.XWalkView>
7. In Activity file, use crosswalk webview(XWalkView) to load web page:
      XWalkView mXWalkView = (XWalkView) findViewById(R.id.webview);
      mXWalkView.load("http://zhuatang.com", null);
If you want to remote inspect web page, add following code:
      XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true);
Note:testing code has already uploaded to github, clone or browse it from https://github.com/zhsoft88/TestCrosswalkEmbed2. Enjoy!
Products: Sealion Seacat Seaflower Seaspider Seasnipe Seastar Seadog Jiong WBXL Xultray webapp
iDocSet iDocSetHelper Blink templateJS
(C) 2017 ZHUATANG.COM, All rights reserved

update: 2015-9-21