How to Add Crosswalk Webview in My Own Android Library Module

How to add crosswalk webview in my own android library module?

I create a new app from the webview to XWalkView to render the three.js stl loader demo, which is not support by the webview no matter WebGlRenderer or CanvasRenderer.
Here is the process how to use the crosswalk module:

Step 1:File->New->Import Module

File->New->Import Module

step 2 select the module and rename if you need

select the module and rename if you need

step 3 choose all the option

choose all the option

here android studio may ask you to update, update it

Sample Image

step 4 process the module dependency

process the module dependency
Sample Image
Sample Image

After this ,the Gradle Build Running automatically
Here We have finished the crosswalk inport.

step 5 use the XWalkView

add this priviledges to AndroidManifest.xml

<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 hardware acceleration on to application node of AndroidManifest.xml

android:hardwareAccelerated="true"

add this to layout file

<org.xwalk.core.XWalkView 
android:id="@+id/xWalkView"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</org.xwalk.core.XWalkView>

add this to activity

XWalkView mXWalkView = (XWalkView) findViewById(R.id.xWalkView);
mXWalkView.load("http://192.168.1.42/test", null);

Here we finished
this is the result I use webview and XWalkView to render three.js STL loader.

webview not support

webview not support

XWalkView supports well

XWalkView supports well

Haha it works.


Follow is the another old implementation , and you can also refer to this good [post] or doc11.

here is the source code.

Download proper Crosswalk Android webview package and unpackage it from https://crosswalk-project.org/documentation/downloads.html

Copy xwalk_core_library_java.jar from crosswalk libs to app/libs/ in the android studio project, and write click on the file, select the "Adds As Library"

Copy other contents under crosswalk libs to app/src/main/jniLibs/

Make an Android Resource dir res2, and copy files in crosswalk res dir to this dir.

Add this to AndroidMenifest.xml

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

and add android:hardwareAccelerated="true" to application node.to use hardware acceleration which is needed by crosswalk webview

add this to layout

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

add this to Activity

XWalkView mXWalkView = (XWalkView) findViewById(R.id.webview);
mXWalkView.load("http://xxxxxx.com", null);

if you want to debug romote add this.

XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true);

How to add a Progress in XWalkView

before i fix my problem i go to make umrah in makkah i try 2 day to fix problem after umrah i take 2 minute and fix my problem my god is help me

pls Do not remove this talk all we have from god

you need to Prayer to God and will you get all what you want

this my MainActivity

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.View;
import android.webkit.ValueCallback;
import android.widget.FrameLayout;
import android.widget.ProgressBar;

import org.xwalk.core.XWalkPreferences;
import org.xwalk.core.XWalkResourceClient;
import org.xwalk.core.XWalkUIClient;
import org.xwalk.core.XWalkView;

import static com.github.crazyorr.embeddedcrosswalk.R.string.url;
public class MainActivity extends AppCompatActivity {

private XWalkView mXWalkView;
private FrameLayout frameLayout;
private SwipeRefreshLayout swipe;
private ProgressBar progressBar;

@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
frameLayout = (FrameLayout) findViewById(R.id.framelayout);
progressBar = (ProgressBar) findViewById(R.id.ProgressBar);
swipe= (SwipeRefreshLayout) findViewById(R.id.swipe);
swipe.setColorSchemeResources(R.color.orange, R.color.green, R.color.blue, R.color.purple);
swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

@Override
public void onRefresh()
{mXWalkView.reload(url);}
});

loadweb();
}

public void loadweb(){

mXWalkView = (XWalkView) findViewById(R.id.webview);
mXWalkView.setResourceClient(new ResourceClient(mXWalkView));
mXWalkView.setUIClient(new XWalkUIClient(mXWalkView) {
@Override
public void onPageLoadStarted(XWalkView view, String url) {
frameLayout.setVisibility(View.VISIBLE);
progressBar.setVisibility(ProgressBar.VISIBLE);
}

@Override
public void onPageLoadStopped(XWalkView view, String url, XWalkUIClient.LoadStatus status) {
progressBar.setVisibility(view.GONE);
swipe.setRefreshing(false);
}
});
XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true);
mXWalkView.getSettings().setJavaScriptEnabled(true);
mXWalkView.loadUrl("https://www.google.com.sa");
}

class ResourceClient extends XWalkResourceClient {

public ResourceClient(XWalkView xwalkView) {
super(xwalkView);
}

public void onProgressChanged(XWalkView view, int progressInPercent){

frameLayout.setVisibility(View.VISIBLE);
progressBar.setProgress(progressInPercent);

if (progressInPercent == 100){
frameLayout.setVisibility(View.GONE);
}
super.onProgressChanged(view, progressInPercent);

}

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}

@Override
public void onBackPressed() {
mXWalkView.evaluateJavascript("onBackPressed()", new ValueCallback<String>() {
@Override
public void onReceiveValue(final String value) {
if (!Boolean.valueOf(value)) {
MainActivity.super.onBackPressed();
}

}
});
}
}

i hop this help you



Related Topics



Leave a reply



Submit