SystemModule.java
4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package com.drp.util.react;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import com.alibaba.fastjson.JSON;
//import com.drp.mobliemall.support.QRCodeScanActivity;
import com.drp.mobliemall.app.GlobalContext;
import com.drp.mobliemall.config.Constants;
import com.drp.mobliemall.utils.SharePreferenceUtil;
import com.facebook.react.bridge.*;
import java.util.List;
/**
* 通信Module类
* Created by Song on 2017/2/17.
*/
public class SystemModule extends ReactContextBaseJavaModule {
//
private ReactApplicationContext mContext;
public static final String MODULE_NAME = "system";
// /**
// * 构造方法必须实现
// */
public SystemModule(ReactApplicationContext reactContext) {
super(reactContext);
this.mContext = reactContext;
}
//
/**
* 在rn代码里面是需要这个名字来调用该类的方法
*/
@Override
public String getName() {
return MODULE_NAME;
}
//
// /**
// * 打电话
// * @param phone 电话号码
// */
// @ReactMethod
// public void call(String phone) {
// XnDeviceApiUtils.getInstance().call(phone);
// }
//
/**
* 跳转至首页
*/
@ReactMethod
public void navTo(String page) {
Activity currentActivity = getCurrentActivity();
// 跳转到其它页面
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // 跳转需要添加flag, 否则报错
if(page == null) {
page = "";
}
ComponentName component = null;
switch(page.toUpperCase()) {
// case "APP":
// // 跳转至应用中心
// component = new ComponentName(currentActivity, MicroApplicationManagerActivity.class);
// break;
case "BACK":
// 后退
if(currentActivity != null) {
currentActivity.finish();
}
return;
}
intent.setComponent(component);
mContext.startActivity(intent);
}
//
// /**
// * 使用默认浏览器打开
// * @param url
// */
// @ReactMethod
// public void openUrl(String url) {
// Intent intent = new Intent(Intent.ACTION_VIEW);
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Uri uri = Uri.parse(url);
// intent.setData(uri);
// if (null != intent.resolveActivity(mContext.getPackageManager())) {
// mContext.startActivity(intent);
// }
// }
//
// /**
// * 判断是否安装了某软件
// * @param packageName 软件的应用ID
// */
// @ReactMethod
// public void hasApp(String packageName, Promise promise) {
// final PackageManager packageManager = mContext.getPackageManager();
// // 获取所有已安装程序的包信息
// List<PackageInfo> infoList = packageManager.getInstalledPackages(0);
// for(PackageInfo info : infoList) {
// if(info.packageName.equalsIgnoreCase(packageName)) {
// promise.resolve("true");
// }
// }
// promise.resolve("false");
// }
/**
* 获取运行模式
*/
@ReactMethod
public void getMode(Promise promise) {
promise.resolve(Constants.APP_ENV);
}
@ReactMethod
public void getMemberId(Promise promise) {
promise.resolve(String.valueOf(GlobalContext.getInstance().getSpUtil().getUserInfo().getId()));
}
//
// /**
// * 获取当前位置
// * @param callback
// */
// @ReactMethod
// public void getLocation(Callback callback) {
// XnLocation location = XnDeviceApiUtils.getInstance().getLocation();
// callback.invoke(JSON.toJSONString(location));
// }
/**
* 使用摄像头
*/
@ReactMethod
public void scan(Callback callback) {
// QRCodeScanActivity qrCodeScanActivity = new QRCodeScanActivity();
// QRCodeScanActivity.callback = callback;
// Intent intent = new Intent(getCurrentActivity(), QRCodeScanActivity.class);
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // 跳转需要添加flag, 否则报错
// getCurrentActivity().startActivity(intent);
//(intent);
// promise.resolve(Constants.FLAVOR);
}
}