From: TrillGates Date: Mon, 5 Apr 2021 02:47:14 +0000 (+0800) Subject: observer voice message data insert to db to send X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=fe50a76afa659cfc53f3dd68a8a32420bf2173be;p=protocol_srv.git observer voice message data insert to db to send --- diff --git a/app/src/main/java/com/enqualcomm/support/Config.java b/app/src/main/java/com/enqualcomm/support/Config.java index 043da9d8..4a537554 100644 --- a/app/src/main/java/com/enqualcomm/support/Config.java +++ b/app/src/main/java/com/enqualcomm/support/Config.java @@ -613,7 +613,8 @@ public class Config { ret = true; } - isUsingCustomServer = ret; + //isUsingCustomServer = ret; + isUsingCustomServer = false; String serverip = ""; int serverport = 0; diff --git a/app/src/main/java/com/enqualcomm/support/CoreService.java b/app/src/main/java/com/enqualcomm/support/CoreService.java index 8ca7752a..befd41c5 100644 --- a/app/src/main/java/com/enqualcomm/support/CoreService.java +++ b/app/src/main/java/com/enqualcomm/support/CoreService.java @@ -5,10 +5,12 @@ import android.app.Notification; import android.app.PendingIntent; import android.app.Service; import android.content.BroadcastReceiver; +import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.media.AudioManager; +import android.net.Uri; import android.os.Handler; import android.os.HandlerThread; import android.os.IBinder; @@ -26,6 +28,7 @@ import com.enqualcomm.support.bean.SleepInfo; import com.enqualcomm.support.bean.SleepRecord; import com.enqualcomm.support.bean.StringMessage; import com.enqualcomm.support.bean.heartRateStatus; +import com.enqualcomm.support.provider.FZDMessageProvider; import com.enqualcomm.support.service.AntiMonitorService; import com.enqualcomm.support.service.CheckSIM; import com.enqualcomm.support.service.Deliver; @@ -33,6 +36,7 @@ import com.enqualcomm.support.service.HeartRateManager; import com.enqualcomm.support.service.KeepAlive; import com.enqualcomm.support.service.SendChatMessage; import com.enqualcomm.support.service.SilentManager; +import com.enqualcomm.support.service.WeTalkMsgObserver; import com.enqualcomm.support.service.base.AbstractConnectionService; import com.enqualcomm.support.service.base.AbstractInvokeHandlerService; import com.enqualcomm.support.utils.AlarmHelper; @@ -980,6 +984,13 @@ public class CoreService extends Service { //设置断网状态 Util.setSystemProperties("persist.sys.server_connected", "false"); + //观察微聊消息变化 + //有新消息就发送出去 + ContentResolver resolver = runtime.getContextProxy().getResolver(); + WeTalkMsgObserver weTalkMsgObserver = new WeTalkMsgObserver(null, resolver); + resolver.registerContentObserver( + Uri.parse(FZDMessageProvider.MESSAGES_SEND), true, weTalkMsgObserver + ); //启动结束设置标志位,让心率和体温检测可以正常执行。 server_starting = false; @@ -1726,7 +1737,7 @@ public class CoreService extends Service { @Override public void test() { //触发测试 - // StringMessage MEMBERS = protocol_fzd.MEMBERS(); + // StringMessage MEMBERS = protocol_fzd.MEMBERS(); //Deliver.sendLocationMSG(MEMBERS); } diff --git a/app/src/main/java/com/enqualcomm/support/bean/BLEInfo.java b/app/src/main/java/com/enqualcomm/support/bean/BLEInfo.java index 38363971..3b08924e 100644 --- a/app/src/main/java/com/enqualcomm/support/bean/BLEInfo.java +++ b/app/src/main/java/com/enqualcomm/support/bean/BLEInfo.java @@ -1,9 +1,8 @@ package com.enqualcomm.support.bean; import java.util.ArrayList; -import java.util.List; -public class BLEInfo { +public class BLEInfo { public String ble_area_id=""; public ArrayList btMacList=new ArrayList<>(); diff --git a/app/src/main/java/com/enqualcomm/support/provider/FZDDatabaseHelper.java b/app/src/main/java/com/enqualcomm/support/provider/FZDDatabaseHelper.java index 493fc49d..efa59c8f 100644 --- a/app/src/main/java/com/enqualcomm/support/provider/FZDDatabaseHelper.java +++ b/app/src/main/java/com/enqualcomm/support/provider/FZDDatabaseHelper.java @@ -35,6 +35,7 @@ public class FZDDatabaseHelper extends SQLiteOpenHelper { public static final String mType = "type"; public static final String mState = "state"; public static final String mInOrOut = "in_or_out"; + public static final String mCategory = "category"; public static final String mRemoteNum = "remote_num"; public static final String mCreateTime = "create_time"; public static final String mUpdateTime = "update_time"; @@ -63,20 +64,22 @@ public class FZDDatabaseHelper extends SQLiteOpenHelper { tMessage + " (" + mId + - " integer primary key, " + + " integer primary key autoincrement, " + mContent + " text, " + mType + " integer, " + + mCategory + + " integer, " + mState + " integer, " + mInOrOut + - " integer "+ + " integer, " + mRemoteNum + - " text, "+ + " text, " + mCreateTime + " date, " + - mUpdateTime+ + mUpdateTime + " date)"; ICLogger.d(createMsg); db.execSQL(createMsg); diff --git a/app/src/main/java/com/enqualcomm/support/provider/FZDMessageProvider.java b/app/src/main/java/com/enqualcomm/support/provider/FZDMessageProvider.java index cc231aa1..5b9ee2eb 100644 --- a/app/src/main/java/com/enqualcomm/support/provider/FZDMessageProvider.java +++ b/app/src/main/java/com/enqualcomm/support/provider/FZDMessageProvider.java @@ -9,12 +9,17 @@ import android.net.Uri; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import com.enqualcomm.support.utils.ICLogger; + +import java.util.Objects; + public class FZDMessageProvider extends ContentProvider { //添加规则 - private static final String PATH = "message"; - private static final String AUTHORITY = "com.ic.fzd.we-talk"; - private static final String MESSAGES = "content://" + AUTHORITY + "/" + PATH; + public static final String PATH = "message"; + public static final String AUTHORITY = "com.ic.fzd.we-talk"; + public static final String MESSAGES = "content://" + AUTHORITY + "/" + PATH; + public static final String MESSAGES_SEND = "content://" + AUTHORITY + ".send" + "/" + PATH; private FZDDatabaseHelper mDatabase; @@ -64,14 +69,29 @@ public class FZDMessageProvider extends ContentProvider { @Nullable ContentValues values) { int match = sUriMatcher.match(uri); if (match == MATH_CODE_TABLE) { - //TODO:通知观察者数据更新了 //观察的地方根据来源,如果是UI,则观察来源是收到的信息 //如果是发送的地方则观察来源是发送的信息 SQLiteDatabase writableDatabase = mDatabase.getWritableDatabase(); //处理插入 - long insert = writableDatabase.insert(FZDDatabaseHelper.tMessage, null, values); + long id = writableDatabase.insert(FZDDatabaseHelper.tMessage, null, values); + //通知观察者数据更新了 + Uri parse = Uri.parse(MESSAGES + "/" + id); + //如果是发送的,那么就发出此条通知 + if (values != null) { + int out = values.getAsInteger("in_or_out"); + ////状态:0表示未读,1表示未读,2表示未发送,3表示发送中,4表示发送失败,5表示发送成功 + int state = values.getAsInteger("state"); + //往外发送 + if (out == 2 && state == 2) { + Uri sendNotify = Uri.parse(MESSAGES_SEND + "/" + id); + //发出通知 + Objects.requireNonNull(getContext()).getContentResolver().notifyChange(sendNotify, null); + } + } + ICLogger.d("notify other observer..." + parse); + Objects.requireNonNull(getContext()).getContentResolver().notifyChange(parse, null); writableDatabase.close(); - return Uri.parse(AUTHORITY + "/" + PATH + "/" + insert); + return parse; } return null; } @@ -92,9 +112,11 @@ public class FZDMessageProvider extends ContentProvider { } @Override - public int update(@NonNull Uri uri, @Nullable ContentValues values, @Nullable String selection, @Nullable String[] selectionArgs) { + public int update(@NonNull Uri uri, @Nullable ContentValues values, + @Nullable String selection, @Nullable String[] selectionArgs) { int match = sUriMatcher.match(uri); if (match == MATH_CODE_TABLE) { + //TODO:通知UI更新 //更新数据 SQLiteDatabase writableDatabase = mDatabase.getWritableDatabase(); int update = writableDatabase.update(FZDDatabaseHelper.tMessage, values, selection, selectionArgs); diff --git a/app/src/main/java/com/enqualcomm/support/service/AudioService.java b/app/src/main/java/com/enqualcomm/support/service/AudioService.java index 942f9f33..ee11e51d 100644 --- a/app/src/main/java/com/enqualcomm/support/service/AudioService.java +++ b/app/src/main/java/com/enqualcomm/support/service/AudioService.java @@ -11,127 +11,134 @@ import java.io.IOException; public class AudioService implements MediaPlayer.OnErrorListener, MediaPlayer.OnCompletionListener { - private MediaPlayer mMediaPlayer; - - private static AudioService mAudioService=null; - private static MediaRecorder mRecorder=null; - public AudioService() { initMediaPlayer(); } - - public static AudioService getInstance(){ - if (mAudioService==null) - mAudioService=new AudioService(); - return mAudioService; - } - private void initMediaPlayer() { - release(); - this.mMediaPlayer = new MediaPlayer(); - this.mMediaPlayer.setOnCompletionListener(this); - this.mMediaPlayer.setOnErrorListener(this); - } - - public void onCompletion(MediaPlayer paramMediaPlayer) { release(); } - - public boolean onError(MediaPlayer paramMediaPlayer, int paramInt1, int paramInt2) { - release(); - return false; - } - - public void pause() { - if (this.mMediaPlayer != null) - this.mMediaPlayer.pause(); - } - - public void play(AssetManager paramAssetManager, String paramString) { - ICLogger.i("mMediaPlayer play"); - if (this.mMediaPlayer == null) - initMediaPlayer(); - this.mMediaPlayer.reset(); - try { - AssetFileDescriptor assetFileDescriptor = paramAssetManager.openFd(paramString); - this.mMediaPlayer.setDataSource(assetFileDescriptor.getFileDescriptor(), assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength()); - assetFileDescriptor.close(); - this.mMediaPlayer.prepare(); - this.mMediaPlayer.start(); - return; - } catch (Exception e) { - e.printStackTrace(); - return; - } - } - - public void play(String paramString) { - if (this.mMediaPlayer == null) - initMediaPlayer(); - this.mMediaPlayer.reset(); - try { - this.mMediaPlayer.setDataSource(paramString); - this.mMediaPlayer.prepare(); - this.mMediaPlayer.start(); - return; - } catch (Exception e) { - e.printStackTrace(); - return; - } - } - - public void play(String paramString, boolean paramBoolean) { - if (this.mMediaPlayer == null) - initMediaPlayer(); - this.mMediaPlayer.reset(); - try { - this.mMediaPlayer.setDataSource(paramString); - this.mMediaPlayer.prepareAsync(); - this.mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { - public void onPrepared(MediaPlayer param1MediaPlayer) { AudioService.this.mMediaPlayer.start(); } - }); - return; - } catch (Exception e) { - e.printStackTrace(); - return; - } - } - - public void rePlay() { - if (this.mMediaPlayer != null) - this.mMediaPlayer.start(); - } - - public void release() { - if (this.mMediaPlayer != null) { - this.mMediaPlayer.setOnCompletionListener(null); - this.mMediaPlayer.setOnErrorListener(null); - this.mMediaPlayer.release(); - this.mMediaPlayer = null; - } - } - - public void stop() { - if (this.mMediaPlayer != null && this.mMediaPlayer.isPlaying()) - this.mMediaPlayer.stop(); - } - - - - public void startRecord(String FileName) { - if (mRecorder==null) - mRecorder = new MediaRecorder(); - mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); - mRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB); - mRecorder.setOutputFile(FileName); - mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); - try { - mRecorder.prepare(); - } catch (IOException e) { - ICLogger.e( "prepare() failed"); + private MediaPlayer mMediaPlayer; + + private static AudioService mAudioService = null; + private static MediaRecorder mRecorder = null; + + public AudioService() { + initMediaPlayer(); + } + + public static AudioService getInstance() { + if (mAudioService == null) + mAudioService = new AudioService(); + return mAudioService; + } + + private void initMediaPlayer() { + release(); + this.mMediaPlayer = new MediaPlayer(); + this.mMediaPlayer.setOnCompletionListener(this); + this.mMediaPlayer.setOnErrorListener(this); + } + + public void onCompletion(MediaPlayer paramMediaPlayer) { + release(); + } + + public boolean onError(MediaPlayer paramMediaPlayer, int paramInt1, int paramInt2) { + release(); + return false; + } + + public void pause() { + if (this.mMediaPlayer != null) + this.mMediaPlayer.pause(); + } + + public void play(AssetManager paramAssetManager, String paramString) { + ICLogger.i("mMediaPlayer play"); + if (this.mMediaPlayer == null) + initMediaPlayer(); + this.mMediaPlayer.reset(); + try { + AssetFileDescriptor assetFileDescriptor = paramAssetManager.openFd(paramString); + this.mMediaPlayer.setDataSource(assetFileDescriptor.getFileDescriptor(), assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength()); + assetFileDescriptor.close(); + this.mMediaPlayer.prepare(); + this.mMediaPlayer.start(); + return; + } catch (Exception e) { + e.printStackTrace(); + return; + } + } + + public void play(String paramString) { + if (this.mMediaPlayer == null) + initMediaPlayer(); + this.mMediaPlayer.reset(); + try { + this.mMediaPlayer.setDataSource(paramString); + this.mMediaPlayer.prepare(); + this.mMediaPlayer.start(); + return; + } catch (Exception e) { + e.printStackTrace(); + return; + } + } + + public void play(String paramString, boolean paramBoolean) { + if (this.mMediaPlayer == null) + initMediaPlayer(); + this.mMediaPlayer.reset(); + try { + this.mMediaPlayer.setDataSource(paramString); + this.mMediaPlayer.prepareAsync(); + this.mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { + public void onPrepared(MediaPlayer param1MediaPlayer) { + AudioService.this.mMediaPlayer.start(); + } + }); + return; + } catch (Exception e) { + e.printStackTrace(); + return; + } + } + + public void rePlay() { + if (this.mMediaPlayer != null) + this.mMediaPlayer.start(); + } + + public void release() { + if (this.mMediaPlayer != null) { + this.mMediaPlayer.setOnCompletionListener(null); + this.mMediaPlayer.setOnErrorListener(null); + this.mMediaPlayer.release(); + this.mMediaPlayer = null; + } + } + + public void stop() { + if (this.mMediaPlayer != null && this.mMediaPlayer.isPlaying()) + this.mMediaPlayer.stop(); + } + + + public void startRecord(String FileName) { + if (mRecorder == null) + mRecorder = new MediaRecorder(); + mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); + mRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB); + mRecorder.setOutputFile(FileName); + mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); + try { + mRecorder.prepare(); + } catch (IOException e) { + ICLogger.e("prepare() failed"); + } + mRecorder.start(); } - mRecorder.start(); - } - public void stopRecord( ) { - if (mRecorder!=null ) { - mRecorder.stop(); - mRecorder.release(); + public void stopRecord() { + if (mRecorder != null) { + mRecorder.stop(); + mRecorder.release(); + } } - } } diff --git a/app/src/main/java/com/enqualcomm/support/service/Deliver.java b/app/src/main/java/com/enqualcomm/support/service/Deliver.java index bdbca64c..88531f5c 100644 --- a/app/src/main/java/com/enqualcomm/support/service/Deliver.java +++ b/app/src/main/java/com/enqualcomm/support/service/Deliver.java @@ -104,7 +104,7 @@ public class Deliver extends AbstractConnectionService { sendloopruning = true; if (getAndSendMsgFromQueue()) { //数据发送成功,则5秒后进行下一轮发送(while 循环用sleep会很占资源造成死锁 - mSendMSGHandler.postDelayed(delaySendMSG, 5000L); + mSendMSGHandler.postDelayed(this, 5000L); } else { //没有数据可以发送,则退出sendLoop sendloopruning = false; @@ -211,9 +211,7 @@ public class Deliver extends AbstractConnectionService { //尝试次数大于5 ,可能是还没有发送过数据,或者超过重试次数,暂停提取queue中数据进,下次心跳再开始发送 if (CheckCount > 5) { ICLogger.i("checkSrvResponse CheckCount=" + CheckCount + " Timeout or cmd is null, skip "); - //C5要的临时版本,去掉盲点续传。 - if (Config.discard_cmd_after_retryfailed) { if (msgWait.getIndex() >= 0) { //有些协议需要对盲点数据进行修改(盲点数据可能是不同的topic),在此对数据修改后更新数据库 @@ -278,7 +276,7 @@ public class Deliver extends AbstractConnectionService { } str = stringBuilder.toString(); ICLogger.i("send cached cmd : \n" + str); - }else{ //如果网络服务器未链接,则表示数据不需要传, + } else { //如果网络服务器未链接,则表示数据不需要传, //但是有些协议要求此数据 需要转变为 盲点续传数据(已经是盲点的跳过) mRuntime.getDbHelper().updateCMDRecordForUD2(0, msgSent); //重发时无网络 //把UD改为UD2 保存到数据库 } @@ -289,6 +287,7 @@ public class Deliver extends AbstractConnectionService { mLock.unlock(); } } + ICLogger.d("getAndSendMsgFromQueue == > ret == > " + ret); return ret; } @@ -327,11 +326,10 @@ public class Deliver extends AbstractConnectionService { long id = mRuntime.getDbHelper().insertCMDRecord(Msg); Msg.setIndex((int) id); dumpMessage(Msg); - if(checkNetwork()) { + if (checkNetwork()) { triggerSendThread(); - }else{ - - mRuntime.getDbHelper().updateCMDRecordForUD2(0, Msg); //把UD改为UD2 保存到数据库 + } else { + mRuntime.getDbHelper().updateCMDRecordForUD2(0, Msg); //把UD改为UD2 保存到数据库 } } else { @@ -613,35 +611,24 @@ public class Deliver extends AbstractConnectionService { String recordfilepath = Util.getRecordfilePath(mRuntime, TimeUtil.getSystemTime3()); int recordtime = Integer.parseInt(paramStringMessage.isFromCache().trim()); - mSendMSGHandler.post(new Runnable() { - @Override - public void run() { - AudioService.getInstance().startRecord(recordfilepath); - } - }); - mSendMSGHandler.postDelayed(new Runnable() { - @Override - public void run() { - AudioService.getInstance().stopRecord(); - ICLogger.i("Monitor Record to send " + recordfilepath); - //创建voiceConent并添加到数据 - /** - * * * 1 语音—— 1.监听语音 * 2.SOS语音 * 3.扩展 - * * * 2 图片—— 1.签到图片 * 2.指令图片 * 3.设备图片 * 4.扩展 - */ - final VoiceContent voiceContent = VoiceContent.placeHolderOut(CONTACT_CATEGORY_GROUP, "123", recordfilepath, 1, 1); - - // 把voiceContent拆解成1024的分包 - Util.parseToVoicePacketSent(voiceContent); - //trigger 分包发送 - if (CoreService.getInstance().getConnection() != null) - CoreService.getInstance().getConnection().DeliverCMDMessageToSystem("SentVoicePacket", ""); - } + mSendMSGHandler.post(() -> AudioService.getInstance().startRecord(recordfilepath)); + mSendMSGHandler.postDelayed(() -> { + AudioService.getInstance().stopRecord(); + ICLogger.i("Monitor Record to send " + recordfilepath); + //创建voiceConent并添加到数据 + /** + * * * 1 语音—— 1.监听语音 * 2.SOS语音 * 3.扩展 + * * * 2 图片—— 1.签到图片 * 2.指令图片 * 3.设备图片 * 4.扩展 + */ + final VoiceContent voiceContent = VoiceContent.placeHolderOut(CONTACT_CATEGORY_GROUP, "123", recordfilepath, 1, 1); + // 把voiceContent拆解成1024的分包 + Util.parseToVoicePacketSent(voiceContent); + //trigger 分包发送 + if (CoreService.getInstance().getConnection() != null) + CoreService.getInstance().getConnection().DeliverCMDMessageToSystem("SentVoicePacket", ""); }, recordtime * 1000); - return true; } - return false; } diff --git a/app/src/main/java/com/enqualcomm/support/service/WeTalkMsgObserver.java b/app/src/main/java/com/enqualcomm/support/service/WeTalkMsgObserver.java new file mode 100644 index 00000000..06f62545 --- /dev/null +++ b/app/src/main/java/com/enqualcomm/support/service/WeTalkMsgObserver.java @@ -0,0 +1,43 @@ +package com.enqualcomm.support.service; + +import android.content.ContentResolver; +import android.database.ContentObserver; +import android.database.Cursor; +import android.net.Uri; +import android.os.Handler; + +import com.enqualcomm.support.provider.FZDMessageProvider; +import com.enqualcomm.support.utils.ICLogger; + +public class WeTalkMsgObserver extends ContentObserver { + private final ContentResolver mResolver; + + /** + * Creates a content observer. + * + * @param handler The handler to run {@link #onChange} on, or null if none. + * @param resolver + */ + public WeTalkMsgObserver(Handler handler, ContentResolver resolver) { + super(handler); + this.mResolver = resolver; + } + + @Override + public void onChange(boolean selfChange, Uri uri) { + super.onChange(selfChange, uri); + ICLogger.d("on message insert to send == > " + uri); + //查询到数据,给到fzd协议上传数据 + String lastPathSegment = uri.getLastPathSegment(); + ICLogger.d("lastPathSegment == > " + lastPathSegment); + Cursor query = mResolver.query(Uri.parse(FZDMessageProvider.MESSAGES), null, "_id=?", + new String[]{lastPathSegment}, null, null); + if (query != null && query.moveToNext()) { + String content = query.getString(query.getColumnIndex("content")); + ICLogger.d("content --- > " + content); + query.close(); + //交给fzd协议吧,让它去发送消息 + //TODO: + } + } +} diff --git a/app/src/main/java/com/ic/protocols/protocol_fzd.java b/app/src/main/java/com/ic/protocols/protocol_fzd.java index 0c1eafa5..3356ed2e 100644 --- a/app/src/main/java/com/ic/protocols/protocol_fzd.java +++ b/app/src/main/java/com/ic/protocols/protocol_fzd.java @@ -22,6 +22,7 @@ import com.enqualcomm.support.bean.Runtime; import com.enqualcomm.support.bean.Silent; import com.enqualcomm.support.bean.StringMessage; import com.enqualcomm.support.provider.FZDMembersProvider; +import com.enqualcomm.support.provider.FZDMessageProvider; import com.enqualcomm.support.service.HeartRateManager; import com.enqualcomm.support.utils.Connection; import com.enqualcomm.support.utils.ICLogger; @@ -306,7 +307,7 @@ public class protocol_fzd { if (regexUtil.isFZDCMD(cmdMap.get(key), cmd)) { ICLogger.d("key is == > " + key); if (key == CMD_TYPE.TK) { - handlerVoiceContent(totalByte); + handlerGroupChatVoiceContent(totalByte); } else { String data = content.replace(CMDHEADER, "").replace(cmd, "").replace(CMDEND, ""); if (data.startsWith(CMDSPLIT)) { @@ -338,7 +339,7 @@ public class protocol_fzd { return allByte; } - private void handlerVoiceContent(byte[] bytes) { + private void handlerGroupChatVoiceContent(byte[] bytes) { try { ICLogger.d("voice length == > " + bytes.length); String cmdStr = new String(bytes); @@ -366,7 +367,22 @@ public class protocol_fzd { } catch (IOException e) { ICLogger.d("playVoice: ERROR "); } - //TODO: + //包存到数据库中,这是群聊的内容,没有联系人的 + 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); //回复服务器状态 mConnection.send(TK("1")); } catch (Exception e) { @@ -1013,7 +1029,22 @@ public class protocol_fzd { //解析数据 String textData = Util.decodeUnicode2Utf8(data); ICLogger.d("message data == > " + textData); - //TODO: + 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); //入数据库 mConnection.send(MESSAGE()); }