|
@ -7,6 +7,7 @@ import android.os.Build;
|
7
|
7
|
|
8
|
8
|
import com.wade.mobile.app.MobileAppInfo;
|
9
|
9
|
import com.wade.mobile.common.nfc.activity.NfcActivity;
|
|
10
|
import com.wade.mobile.common.nfc.util.NfcConstant;
|
10
|
11
|
import com.wade.mobile.frame.IWadeMobile;
|
11
|
12
|
import com.wade.mobile.frame.plugin.Plugin;
|
12
|
13
|
import com.wade.mobile.ui.helper.HintHelper;
|
|
@ -15,7 +16,7 @@ import com.wade.mobile.util.Utility;
|
15
|
16
|
|
16
|
17
|
public class MobileDevice extends Plugin {
|
17
|
18
|
private static final int INIT_NFC = 1;
|
18
|
|
private static String NFC_CALLBACK;
|
|
19
|
private static String nfcCallback;
|
19
|
20
|
|
20
|
21
|
public MobileDevice(IWadeMobile wademobile) {
|
21
|
22
|
super(wademobile);
|
|
@ -30,25 +31,32 @@ public class MobileDevice extends Plugin {
|
30
|
31
|
return;
|
31
|
32
|
}
|
32
|
33
|
String cmds = param.getString(0);
|
33
|
|
NFC_CALLBACK = param.getString(1);
|
34
|
|
if(isNull(cmds)||isNull(NFC_CALLBACK)){
|
|
34
|
nfcCallback = param.getString(1);
|
|
35
|
if (isNull(cmds) || isNull(nfcCallback)) {
|
35
|
36
|
Utility.error("参数为空异常!");
|
36
|
37
|
}
|
37
|
|
|
|
38
|
|
38
|
39
|
Intent intent = new Intent(context, NfcActivity.class);
|
39
|
40
|
intent.putExtra(NfcActivity.CMDS, cmds);
|
40
|
41
|
startActivityForResult(intent, INIT_NFC);
|
41
|
42
|
}
|
42
|
|
|
|
43
|
|
43
|
44
|
@Override
|
44
|
45
|
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
45
|
46
|
if (requestCode == INIT_NFC) {
|
46
|
|
String nfcMsg = intent.getStringExtra(NfcActivity.NFC_DATA);
|
47
|
|
StringBuilder buff = new StringBuilder();
|
48
|
|
buff.append("if(").append(NFC_CALLBACK).append("){");
|
49
|
|
buff.append(NFC_CALLBACK).append("(unescape(").append(EscapeUnescape.escape(nfcMsg)).append("));");
|
50
|
|
buff.append("}else{alert('请设置获取NFC的回调方法');};");
|
51
|
|
wademobile.getCurrentWebView().executeJs(buff.toString());
|
|
47
|
if (resultCode == NfcConstant.SUCCESS_CODE) {
|
|
48
|
String nfcMsg = intent.getStringExtra(NfcActivity.NFC_DATA);
|
|
49
|
// StringBuilder buff = new StringBuilder();
|
|
50
|
// buff.append("if(").append(NFC_CALLBACK).append("){");
|
|
51
|
// buff.append("(function(msg){"+NFC_CALLBACK).append("(unescape(").append(EscapeUnescape.escape(nfcMsg)).append("));");
|
|
52
|
// buff.append("}else{alert('请设置获取NFC的回调方法');};");
|
|
53
|
// wademobile.getCurrentWebView().executeJs(buff.toString());
|
|
54
|
|
|
55
|
// 转义
|
|
56
|
String callback = "(function(msg){" + nfcCallback + "(unescape(msg));})";
|
|
57
|
String ret = callback + "('" + EscapeUnescape.escape(nfcMsg) + "')";
|
|
58
|
wademobile.getCurrentWebView().executeJs(ret);
|
|
59
|
}
|
52
|
60
|
}
|
53
|
61
|
}
|
54
|
62
|
}
|