资料内容:
第⼀步: Android对Js的接口,新建AndroidInterfaceForJs.js
import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.RequiresApi;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.webkit.ValueCallback;
import android.widget.Toast;
import com.just.agentweb.AgentWeb;
import com.yidumedical.ui.activity.PAWebActivity;
/**
* Created by shiby on 2018/1/24.
*/
public class AndroidInterfaceForJS {
private Handler deliver = new Handler(Looper.getMainLooper());
private AgentWeb agent;
private Context context;
public AndroidInterfaceForJS(AgentWeb agent, Context context) {
this.agent = agent;
this.context = context;
}
@JavascriptInterface
public void callAndroid(final String msg) {
deliver.post(new Runnable() {
@Override
public void run() {
Log.i("Info", "main Thread:" + Thread.currentThread());
Toast.makeText(context.getApplicationContext(), "" + msg, Toast.LENGTH_LONG).show();
}
});
Log.i("Info", "Thread:" + Thread.currentThread());
}
}