Browse Source

[提交内容]:nfc

wangyj18 9 years ago
parent
commit
a54e708c3a
1 changed files with 19 additions and 11 deletions
  1. 19 11
      wade-mobile-func/src/com/wade/mobile/func/MobileDevice.java

+ 19 - 11
wade-mobile-func/src/com/wade/mobile/func/MobileDevice.java

7

7

8
import com.wade.mobile.app.MobileAppInfo;
8
import com.wade.mobile.app.MobileAppInfo;
9
import com.wade.mobile.common.nfc.activity.NfcActivity;
9
import com.wade.mobile.common.nfc.activity.NfcActivity;
10
import com.wade.mobile.common.nfc.util.NfcConstant;
10
import com.wade.mobile.frame.IWadeMobile;
11
import com.wade.mobile.frame.IWadeMobile;
11
import com.wade.mobile.frame.plugin.Plugin;
12
import com.wade.mobile.frame.plugin.Plugin;
12
import com.wade.mobile.ui.helper.HintHelper;
13
import com.wade.mobile.ui.helper.HintHelper;
15

16

16
public class MobileDevice extends Plugin {
17
public class MobileDevice extends Plugin {
17
	private static final int INIT_NFC = 1;
18
	private static final int INIT_NFC = 1;
18
	private static String NFC_CALLBACK;
19
	private static String nfcCallback;
19

20

20
	public MobileDevice(IWadeMobile wademobile) {
21
	public MobileDevice(IWadeMobile wademobile) {
21
		super(wademobile);
22
		super(wademobile);
30
			return;
31
			return;
31
		}
32
		}
32
		String cmds = param.getString(0);
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
			Utility.error("参数为空异常!");
36
			Utility.error("参数为空异常!");
36
		}
37
		}
37
		
38

38
		Intent intent = new Intent(context, NfcActivity.class);
39
		Intent intent = new Intent(context, NfcActivity.class);
39
		intent.putExtra(NfcActivity.CMDS, cmds);
40
		intent.putExtra(NfcActivity.CMDS, cmds);
40
		startActivityForResult(intent, INIT_NFC);
41
		startActivityForResult(intent, INIT_NFC);
41
	}
42
	}
42
	
43

43
	@Override
44
	@Override
44
	public void onActivityResult(int requestCode, int resultCode, Intent intent) {
45
	public void onActivityResult(int requestCode, int resultCode, Intent intent) {
45
		if (requestCode == INIT_NFC) {
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
}