import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.ContentValues;
+import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Environment;
+import android.os.Handler;
+import android.os.HandlerThread;
import android.support.v4.app.ActivityCompat;
import android.text.TextUtils;
import com.enqualcomm.support.provider.WeTalkMessageProvider;
import com.enqualcomm.support.service.HeartRateManager;
import com.enqualcomm.support.service.SilentManager;
+import com.enqualcomm.support.utils.CameraUtil;
import com.enqualcomm.support.utils.CellInfoUtil;
import com.enqualcomm.support.utils.Connection;
import com.enqualcomm.support.utils.DeviceInfoUtil;
import java.util.List;
import static com.enqualcomm.support.Constants.ACTION_ALARM_ALARM_CHANGE;
+import static com.enqualcomm.support.Constants.DIALOG_ACTION;
import static com.enqualcomm.support.Constants.FROM_SERVER;
import static com.enqualcomm.support.LocationClient.LOCATION_MODE;
import static java.lang.Math.abs;
private static final String CMDSPLIT = ",";
public static final String defaultServerIP = "en.beehome360.com";
public static final int defaultServerPort = 5018;
+ private Handler mHandler = null;
/**
BPTQ,//天气信息响应
BP75,//闹钟数据下发
AP75,//闹钟数据回复
+ AP46,//立即拍照
+ BP46,
}
private static HashMap<CMD_TYPE, String> cmdStrMap = null;
cmdStrMap.put(CMD_TYPE.BPTQ, "BPTQ");
cmdStrMap.put(CMD_TYPE.BP75, "BP75");
cmdStrMap.put(CMD_TYPE.AP75, "AP75");
+ cmdStrMap.put(CMD_TYPE.AP46, "AP46");
+ cmdStrMap.put(CMD_TYPE.BP46, "BP46");
//
cmdMap = new HashMap<>();
cmdMap.put("AP00", CMD_TYPE.AP00);
cmdMap.put("APTQ", CMD_TYPE.APTQ);
cmdMap.put("AP75", CMD_TYPE.AP75);
cmdMap.put("BP75", CMD_TYPE.BP75);
+ cmdMap.put("BP46", CMD_TYPE.BP46);
+ cmdMap.put("AP46", CMD_TYPE.AP46);
}
public protocol_beehome(Connection connect, Runtime runtime) {
mConnection = connect;
mRuntime = runtime;
-
+ if (mHandler == null) {
+ HandlerThread handlerThread = new HandlerThread("ic:protocol_s123-handler-thread");
+ handlerThread.start();
+ mHandler = new Handler(handlerThread.getLooper());
+ }
}
private StringBuffer cmdbuf = new StringBuffer();
String cmdStr = cmdItem.substring(2, 6);
ICLogger.d("cmdStr ==> " + cmdStr);
CMD_TYPE key = cmdMap.get(cmdStr);
+ if (key == null) {
+ ICLogger.d("不支持该指令==> " + cmdlist[i]);
+ return false;
+ }
ICLogger.d("found cmd keyid=" + key + " ,keyname=" + cmdStrMap.get(key) + " , " + cmdlist[i]);
if (key == CMD_TYPE.BP28) {
//如果是BP28则 后面的数据是音频,需要保留
}
+ public void handleBP46(String cmd, Connection connection, Runtime runtime) {
+ /***
+ * IWBP46,353456789012345,080835,1,[参数]#
+ * 说明:
+ * IW:标识符
+ * BP46 : 命令字符
+ * 353456789012345:IMEI号,设备唯一ID
+ * 080835 :指令流水号
+ * 1: 表示立即拍照
+ * [参数]: 此为可选项。根据不同类型设备扩展
+ * #:结尾标识符
+ * 设备响应: IWAP46,080835,1#
+ * 080835:指令流水号
+ * 1 成功 0失败
+ * # 结尾标识符
+ */
+ String[] cmdlist = cmd.split(CMDSPLIT);
+
+ if (cmdlist.length >= 4) {
+ String imei = cmdlist[1];
+ String id = cmdlist[2];
+ String cdd = cmdlist[3];
+ if (cmdlist.length == 5) {
+ String tmp = cmdlist[4];
+ }
+ connection.send(AP46(id, cdd));
+ Context context = mRuntime.getContextProxy().context.getApplicationContext();
+ if (cdd.equals("1")) {
+ //delay 启动
+
+// Intent intent = new Intent(context, com.enqualcomm.support.CoreService.class);
+// intent.setAction(ACTION_REMOTE_CAMERA);
+// intent.putExtra("remote_number", id);
+// context.startService(intent);
+// runtime.getContextProxy().context.sendBroadcast(intent);
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ (new CameraUtil(context)).getPicture(id);
+ }
+ });
+
+ } else if (cdd.equals("2")) {
+ Intent intent = new Intent();
+ intent.setAction(DIALOG_ACTION);
+ intent.putExtra("takephoto", "Take Photo !");
+ context.sendBroadcast(intent);
+ }
+ } else {
+ ICLogger.i(" BP46 Format error!");
+ }
+
+ }
+
+
+ public static StringMessage AP46(String id, String cmd) {
+ return genStringMessage(cmdStrMap.get(CMD_TYPE.AP46),
+ new StringBuffer(CMDHEADER).append(cmdMap.get(CMD_TYPE.AP46))
+ .append(CMDSPLIT).append(id)
+ .append(CMDSPLIT).append(cmd)
+ .append(CMDEND).toString());
+ }
+
+
public static StringMessage APHP(int ppg, int bph, int bpl, int spo2) {
//IWAPHP,60,130,85,95,90, , , , , , , , #
//IW:标识符
ICLogger.d("收到服务器BP05");
handleBP05(cmd);
break;
+ case BP46: //立即拍照
+ ICLogger.i("立即拍照!");
+ handleBP46(cmd, mConnection, mRuntime);
+ break;
+
}
return ret;
}