Java资源分享网 - 专业的Java学习网站 学Java,上Java资源分享网
三步搞定:Vue.js调用Android原生操作 PDF 下载
发布于:2024-07-21 08:56:42
(假如点击没反应,多刷新两次就OK!)

三步搞定:Vue.js调用Android原生操作 PDF 下载 图1

 

 

资料内容:

 

 

第⼀步: AndroidJs的接口,新建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());
}
}