import com.enqualcomm.support.bean.Runtime;
import com.enqualcomm.support.bean.Silent;
import com.enqualcomm.support.bean.StringMessage;
+import com.enqualcomm.support.provider.FZDDatabaseHelper;
import com.enqualcomm.support.provider.FZDMembersProvider;
import com.enqualcomm.support.provider.FZDMessageProvider;
import com.enqualcomm.support.service.HeartRateManager;
import java.util.HashMap;
import static com.enqualcomm.support.Constants.FROM_SERVER;
+import static com.enqualcomm.support.Constants.contact;
import static com.enqualcomm.support.LocationClient.LOCATION_MODE;
import static java.lang.Math.abs;
FIND,//找手表指令
REMIND,//闹钟设置指令
TK,//对讲功能(微聊发送语音)
+ TKOne,//一对一微聊
PHL,//设置电话本+白名单(最多 50 条)
wdstart,//远程测温
bldstart,//远程测血压
ICLogger.d("key is == > " + key);
if (key == CMD_TYPE.TK) {
handlerGroupChatVoiceContent(totalByte);
+ } else if (key == CMD_TYPE.TKOne) {
+ handlerOneChatVoiceContent(totalByte);
} else {
String data = content.replace(CMDHEADER, "").replace(cmd, "").replace(CMDEND, "");
if (data.startsWith(CMDSPLIT)) {
return true;
}
- private static byte[] byteMerger(byte[]... byteList) {
- int lengthByte = 0;
- //求出总的长度
- for (int i = 0; i < byteList.length; i++) {
- lengthByte += byteList[i].length;
- }
- //创建总的数组
- byte[] allByte = new byte[lengthByte];
- int countLength = 0;
- for (int i = 0; i < byteList.length; i++) {
- byte[] b = byteList[i];
- System.arraycopy(b, 0, allByte, countLength, b.length);
- countLength += b.length;
+ /**
+ * 一对一微聊
+ *
+ * @param totalByte
+ */
+ private void handlerOneChatVoiceContent(byte[] totalByte) {
+ try {
+ //对数据进行处理
+ //数据格式:[XT*YYYYYYYYYYYYYYY*LEN*TKOne,App 账号,秒数,AMR 格式音频数据]
+ String cmdStr = new String(totalByte);
+ String[] split = cmdStr.split(",");
+ String header = split[0];
+ //账号
+ String count = split[1];
+ //秒数
+ String duration = split[2];
+ //数据包,对数据进行切割
+ byte[] dataPackage = Util.subArray(totalByte, header.length() + contact.length() + duration.length() + 3,
+ totalByte.length - 1);
+ //对数据进行转换
+ String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC) + "/Android/VoiceCache";
+ byte[] result = Util.fzdTransfer(dataPackage, false);
+ String amrFilepath = Util.saveFile(result,
+ 0, result.length,
+ new File(dir),
+ "receive_" + System.currentTimeMillis() + ".amr");
+ //插入到数据库中
+ voiceIn2Db(amrFilepath, FZDDatabaseHelper.MessageType.VOICE);
+ //返回结果
+ mConnection.send(TKOne("1"));
+ } catch (Exception e) {
+ e.printStackTrace();
+ mConnection.send(TKOne("0"));
}
- return allByte;
}
+ /**
+ * 群聊
+ *
+ * @param bytes
+ */
private void handlerGroupChatVoiceContent(byte[] bytes) {
try {
ICLogger.d("voice length == > " + bytes.length);
//更新发送状态
String value = cmdStr.substring(cmdLength, cmdLength + 1);
ICLogger.d("value is == > " + cmdLength);
+ String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC) + "/Android/VoiceCache";
if ("1".equals(value)) {
//修改为发送成功
//不知道ID,所以无法修改消息的状态
// ICLogger.d("playVoice: ERROR ");
//}
//包存到数据库中,这是群聊的内容,没有联系人的
- ContentResolver resolver = mRuntime.getContextProxy().getResolver();
- ContentValues contentValues = new ContentValues();
- //路径
- contentValues.put("content", amrFilepath);
- //类型为声音
- contentValues.put("type", 1);
- //状态:0表示未读
- contentValues.put("state", 0);
- //接受还是发送,1表示来信
- contentValues.put("in_or_out", 1);
- //对方号码是没有的
- contentValues.put("remote_num", "");
- contentValues.put("create_time", System.currentTimeMillis());
- contentValues.put("update_time", System.currentTimeMillis());
- resolver.insert(Uri.parse(FZDMessageProvider.MESSAGES), contentValues);
+ voiceIn2Db(amrFilepath, FZDDatabaseHelper.MessageType.VOICE);
//回复服务器状态
mConnection.send(TK("1"));
//通知有消息到
}
}
+ private void voiceIn2Db(String amrFilepath, int type) {
+ ContentResolver resolver = mRuntime.getContextProxy().getResolver();
+ ContentValues contentValues = new ContentValues();
+ //路径
+ contentValues.put("content", amrFilepath);
+ //类型为声音
+ contentValues.put("type", type);
+ //状态:0表示未读
+ contentValues.put("state", 0);
+ //接受还是发送,1表示来信
+ contentValues.put("in_or_out", 1);
+ //对方号码是没有的
+ contentValues.put("remote_num", "");
+ contentValues.put("create_time", System.currentTimeMillis());
+ contentValues.put("update_time", System.currentTimeMillis());
+ resolver.insert(Uri.parse(FZDMessageProvider.MESSAGES), contentValues);
+ }
+
+ private static byte[] byteMerger(byte[]... byteList) {
+ int lengthByte = 0;
+ //求出总的长度
+ for (int i = 0; i < byteList.length; i++) {
+ lengthByte += byteList[i].length;
+ }
+ //创建总的数组
+ byte[] allByte = new byte[lengthByte];
+ int countLength = 0;
+ for (int i = 0; i < byteList.length; i++) {
+ byte[] b = byteList[i];
+ System.arraycopy(b, 0, allByte, countLength, b.length);
+ countLength += b.length;
+ }
+ return allByte;
+ }
+
private static String getHexLen(int len) {
StringBuilder sb = new StringBuilder();
int v = len & 0xFFFF;
//解析数据
String textData = Util.decodeUnicode2Utf8(data);
ICLogger.d("message data == > " + textData);
- ContentResolver resolver = mRuntime.getContextProxy().getResolver();
- ContentValues values = new ContentValues();
- //路径
- values.put("content", textData);
- //类型为2表示的是文本
- values.put("type", 2);
- //状态:0表示未读
- values.put("state", 0);
- //接受还是发送,1表示来信
- values.put("in_or_out", 1);
- //对方号码是没有的
- values.put("remote_num", "");
- values.put("create_time", System.currentTimeMillis());
- values.put("update_time", System.currentTimeMillis());
- //字段:内容,类型,来源,分类,是否已读,联系人ID
- resolver.insert(Uri.parse(FZDMessageProvider.MESSAGES), values);
+ voiceIn2Db(textData, FZDDatabaseHelper.MessageType.TEXT);
//入数据库
mConnection.send(MESSAGE());
}
+ private StringMessage TKOne(String result) {
+ return genFZDCMD(cmdMap.get(CMD_TYPE.TKOne), result);
+ }
+
private StringMessage TK(String result) {
return genFZDCMD(cmdMap.get(CMD_TYPE.TK), result);
}