Android JS interaction
WebView web;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
web=(WebView) findViewById(R.id.web);
web.getSettings().setDefaultTextEncodingName("UTF-8") ;
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setAllowFileAccess(true);
web.addJavascriptInterface(new JsOperator(MainActivity.this),"JsInteraction");
web.loadData("test<script type="text/javascript">function showMsg(){JsInteraction.showDialog("Login start...");}", "text/html", "UTF-8");
//shareMsg("active ttt","ttttttt","test http://www.qq.com/ 测试","/assets/1.jpg");
}
package com.wgscd.gwang.myapplication;
/**
- Created by gwang on 2017/3/14.
*/
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.webkit.JavascriptInterface;
import org.json.JSONObject;
public class JsOperator {
private Context context;
public JsOperator(Context context) {
this.context = context;
}
/**
* 弹出消息对话框
*/
@JavascriptInterface
public void showDialog(String message) {
AlertDialog.Builder builder = new Builder(context);
builder.setMessage(message);
builder.setTitle("提示");
builder.setPositiveButton("确认", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.setNegativeButton("取消", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
}
/**
* 获取登录的用户名和密码
* @return JSON格式的字符串
*/
@JavascriptInterface
public String getLoginInfo(){
try{
JSONObject login = new JSONObject();
login.put("Username", "YLD");
login.put("Password", "111");
return login.toString();
}catch(Exception e){
e.printStackTrace();
}
return null;
}
}
Android JS interaction的更多相关文章
- Atitit.android js 的键盘按键检测Back键Home键和Menu键事件
Atitit.android js 的键盘按键检测Back键Home键和Menu键事件 1. onKeyDown @Override public boolean onKeyDown(int keyC ...
- android ReactNative之Cannot find entry file index.android.js in any of the roots
android ReactNative之Cannot find entry file index.android.js in any of the roots 2018年04月02日 14:53:12 ...
- android js 互相调用
代码地址如下:http://www.demodashi.com/demo/13107.html android js 互相调用 第二版 支持js匿名函数接收 支持js json对象接收 支持js函数返 ...
- Android js相互调用
一.webview相当于android中的浏览器,基于webkit开发,可以浏览网页文件,支持css javas cript 以及html webview.getSettings().setJavaS ...
- android js调试
http://blog.allenm.me/ 其他平台去这篇文章看 //js调试调试功能支持4.4版本以上的 if(Build.VERSION.SDK_INT >= Build.VERSION_ ...
- Android JS桥交互("Uncaught ReferenceError: xxx is not defined or xxx has no method")
网上android和js交互的代码有不少,也很容易搜到.最近在做的项目需要用到js桥,遇到了一些问题,记录下来,希望以后遇到能马上解决掉. 一开始我找的demo是从这个:http://blog.csd ...
- Android JS 交互出现 Uncaught Error: Error calling method on NPObject
由于HTML5的功能越来越强大,native app的一些功能逐步被html页面代替,不可避免的JS交互也用到的也越来越多.在第一个版本向第二个版本迭代的过程中却发生了莫名其妙的问题,第一个版本JS调 ...
- 我的博客:C# PHP J2ee Java Android js WP Asp.net mvc Python
<p><A target="_blank" href="http://blog.163.com/hr_company_product/" &g ...
- android js与控件交互初探。
1.创建一个mainacvity 在oncreate中加入, mWeb是一个webview组件,网络权限记得自己加. <uses-permission android:name="an ...
随机推荐
- Ubuntu16安装GPU版本TensorFlow(个人笔记本电脑)
想着开始学习tf了怎么能不用GPU,网上查了一下发现GeForce GTX确实支持GPU运算,所以就尝试部署了一下,在这里记录一下,避免大家少走弯路. 使用个人笔记本电脑thinkpadE570,内存 ...
- CentOS 中 配置 Nginx 支持 https
一.基础设置: .yum -y update .yum -y install openssl* .cd /usr/local/nginx/conf .mkdir ./ssl .cd ./ssl # 在 ...
- ExpressRoute 合作伙伴和对等位置
本文中的表格提供有关 ExpressRoute 连接提供商.ExpressRoute 地理覆盖范围.通过 ExpressRoute 支持的 Azure 服务以及 ExpressRoute 系统集成商 ...
- font-family:中文字体的英文名称 (宋体 微软雅黑)
宋体 SimSun 黑体 SimHei 微软雅黑 Microsoft YaHei 微软正黑体 Microsoft JhengHei 新宋体 NSimSun 新细明体 PMingLiU 细明体 Ming ...
- Oracle EBS 获取用户挂的职责 请求 请求的类别(RTF还是什么的)
select fu.user_ID, fu.user_name, fu.start_date, fu.END_DATE, fu.description, fe.last_name, fr.RESPON ...
- .net Cookie的操作
using System; using System.Collections.Generic; using System.Web; namespace Zhong.Core { /// <sum ...
- CentOS服务器的加固方案
>>>Centos账户安全 对Centos的加固首先要控制用户的权限,用户权限主要涉及到/etc下的/passwd,/shadow和/group三个文件 /passwd文件主要是存储 ...
- HDFS NameNode内存全景
一.概述 从整个HDFS系统架构上看,NameNode是其中最重要.最复杂也是最容易出现问题的地方,而且一旦NameNode出现故障,整个Hadoop集群就将处于不可服务的状态,同时随着数据规模和集群 ...
- ZT 二分插入排序也称折半插入排序
二分插入排序也称折半插入排序,基本思想是:设数列[0....n]分为两部分一部分是[0...i]为有序序列,另一部分是[i+1.....n]为无序序列,从无序序列中取一个数 x ,利用二分查找算法找到 ...
- Yarn遭到挖矿病毒攻击
测试环境在阿里云上暴露出了公网端口,前一段时间CDH集群原本是开启了Kerberos认证,但是因为大家反映使用麻烦,所以就又关闭了Kerberos. 最近几天大家普遍反映测试环境上hive和hdfs ...