diff --git a/README.md b/README.md
index a6f3eb0..1fdebd1 100644
--- a/README.md
+++ b/README.md
@@ -189,5 +189,5 @@ https://www.yuque.com/yuanfangxiyang/ma4ytb/vvy3iz/edit#nnzKN
android端sdk引用
```
- implementation "com.farsunset:cim-android-sdk:4.2.0"
+ implementation "com.farsunset:cim-android-sdk:4.2.5"
```
\ No newline at end of file
diff --git a/cim-client-sdk-libs/android/cim-android-sdk-4.2.0.jar b/cim-client-sdk-libs/android/cim-android-sdk-4.2.0.jar
deleted file mode 100644
index 02273d2..0000000
Binary files a/cim-client-sdk-libs/android/cim-android-sdk-4.2.0.jar and /dev/null differ
diff --git a/cim-client-sdk/cim-android-sdk/pom.xml b/cim-client-sdk/cim-android-sdk/pom.xml
index bb485ca..a51bc2b 100755
--- a/cim-client-sdk/cim-android-sdk/pom.xml
+++ b/cim-client-sdk/cim-android-sdk/pom.xml
@@ -6,7 +6,7 @@
com.farsunset
cim-android-sdk
- 4.2.0
+ 4.2.5
jar
${project.groupId}:${project.artifactId}
diff --git a/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/CIMConnectorManager.java b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/CIMConnectorManager.java
index 8bd4640..095f6b0 100644
--- a/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/CIMConnectorManager.java
+++ b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/CIMConnectorManager.java
@@ -27,6 +27,7 @@ import android.os.Handler;
import com.farsunset.cim.sdk.android.coder.ClientMessageDecoder;
import com.farsunset.cim.sdk.android.coder.ClientMessageEncoder;
import com.farsunset.cim.sdk.android.constant.CIMConstant;
+import com.farsunset.cim.sdk.android.constant.IntentAction;
import com.farsunset.cim.sdk.android.logger.CIMLogger;
import com.farsunset.cim.sdk.android.model.*;
@@ -95,7 +96,7 @@ class CIMConnectorManager {
Intent intent = new Intent();
intent.setPackage(context.getPackageName());
- intent.setAction(CIMConstant.IntentAction.ACTION_CONNECT_FAILED);
+ intent.setAction(IntentAction.ACTION_CONNECT_FAILED);
context.sendBroadcast(intent);
return;
@@ -205,7 +206,7 @@ class CIMConnectorManager {
Intent intent = new Intent();
intent.setPackage(context.getPackageName());
- intent.setAction(CIMConstant.IntentAction.ACTION_CONNECT_FINISHED);
+ intent.setAction(IntentAction.ACTION_CONNECT_FINISHED);
context.sendBroadcast(intent);
}
@@ -218,7 +219,7 @@ class CIMConnectorManager {
Intent intent = new Intent();
intent.setPackage(context.getPackageName());
- intent.setAction(CIMConstant.IntentAction.ACTION_CONNECTION_CLOSED);
+ intent.setAction(IntentAction.ACTION_CONNECTION_CLOSED);
context.sendBroadcast(intent);
}
@@ -237,7 +238,7 @@ class CIMConnectorManager {
Intent intent = new Intent();
intent.setPackage(context.getPackageName());
- intent.setAction(CIMConstant.IntentAction.ACTION_MESSAGE_RECEIVED);
+ intent.setAction(IntentAction.ACTION_MESSAGE_RECEIVED);
intent.putExtra(Message.class.getName(), (Message) obj);
context.sendBroadcast(intent);
@@ -246,7 +247,7 @@ class CIMConnectorManager {
Intent intent = new Intent();
intent.setPackage(context.getPackageName());
- intent.setAction(CIMConstant.IntentAction.ACTION_REPLY_RECEIVED);
+ intent.setAction(IntentAction.ACTION_REPLY_RECEIVED);
intent.putExtra(ReplyBody.class.getName(), (ReplyBody) obj);
context.sendBroadcast(intent);
}
@@ -260,7 +261,7 @@ class CIMConnectorManager {
if (message instanceof SentBody) {
Intent intent = new Intent();
intent.setPackage(context.getPackageName());
- intent.setAction(CIMConstant.IntentAction.ACTION_SEND_FINISHED);
+ intent.setAction(IntentAction.ACTION_SEND_FINISHED);
intent.putExtra(SentBody.class.getName(), (SentBody) message);
context.sendBroadcast(intent);
}
@@ -288,7 +289,7 @@ class CIMConnectorManager {
Intent intent = new Intent();
intent.setPackage(context.getPackageName());
- intent.setAction(CIMConstant.IntentAction.ACTION_CONNECT_FAILED);
+ intent.setAction(IntentAction.ACTION_CONNECT_FAILED);
intent.putExtra("interval", interval);
context.sendBroadcast(intent);
diff --git a/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/CIMEventBroadcastReceiver.java b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/CIMEventBroadcastReceiver.java
index 5945434..7ab04e8 100644
--- a/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/CIMEventBroadcastReceiver.java
+++ b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/CIMEventBroadcastReceiver.java
@@ -25,8 +25,10 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
-import android.os.Build;
+import com.farsunset.cim.sdk.android.constant.BundleKey;
import com.farsunset.cim.sdk.android.constant.CIMConstant;
+import com.farsunset.cim.sdk.android.constant.IntentAction;
+import com.farsunset.cim.sdk.android.constant.ServiceAction;
import com.farsunset.cim.sdk.android.model.Message;
import com.farsunset.cim.sdk.android.model.ReplyBody;
import com.farsunset.cim.sdk.android.model.SentBody;
@@ -38,7 +40,6 @@ public abstract class CIMEventBroadcastReceiver extends BroadcastReceiver {
protected Context context;
- @SuppressWarnings("deprecation")
@Override
public void onReceive(Context context, Intent intent) {
@@ -50,6 +51,7 @@ public abstract class CIMEventBroadcastReceiver extends BroadcastReceiver {
* 操作事件广播,用于提高service存活率
*/
if (Intent.ACTION_USER_PRESENT.equals(action)
+ || Intent.ACTION_BOOT_COMPLETED.equals(action)
|| Intent.ACTION_POWER_CONNECTED.equals(action)
|| Intent.ACTION_POWER_DISCONNECTED.equals(action)) {
startPushService();
@@ -58,7 +60,7 @@ public abstract class CIMEventBroadcastReceiver extends BroadcastReceiver {
/*
* 设备网络状态变化事件
*/
- if (CIMConstant.IntentAction.ACTION_NETWORK_CHANGED.equals(action)
+ if (IntentAction.ACTION_NETWORK_CHANGED.equals(action)
|| ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) {
onDevicesNetworkChanged();
@@ -67,14 +69,14 @@ public abstract class CIMEventBroadcastReceiver extends BroadcastReceiver {
/*
* cim断开服务器事件
*/
- if (CIMConstant.IntentAction.ACTION_CONNECTION_CLOSED.equals(action)) {
+ if (IntentAction.ACTION_CONNECTION_CLOSED.equals(action)) {
onInnerConnectionClosed();
}
/*
* cim连接服务器失败事件
*/
- if (CIMConstant.IntentAction.ACTION_CONNECT_FAILED.equals(action)) {
+ if (IntentAction.ACTION_CONNECT_FAILED.equals(action)) {
long interval = intent.getLongExtra("interval", CIMConstant.RECONNECT_INTERVAL_TIME);
onInnerConnectFailed(interval);
}
@@ -82,21 +84,21 @@ public abstract class CIMEventBroadcastReceiver extends BroadcastReceiver {
/*
* cim连接服务器成功事件
*/
- if (CIMConstant.IntentAction.ACTION_CONNECT_FINISHED.equals(action)) {
+ if (IntentAction.ACTION_CONNECT_FINISHED.equals(action)) {
onInnerConnectFinished();
}
/*
* 收到推送消息事件
*/
- if (CIMConstant.IntentAction.ACTION_MESSAGE_RECEIVED.equals(action)) {
+ if (IntentAction.ACTION_MESSAGE_RECEIVED.equals(action)) {
onInnerMessageReceived((Message) intent.getSerializableExtra(Message.class.getName()), intent);
}
/*
* 获取收到replyBody成功事件
*/
- if (CIMConstant.IntentAction.ACTION_REPLY_RECEIVED.equals(action)) {
+ if (IntentAction.ACTION_REPLY_RECEIVED.equals(action)) {
onReplyReceived((ReplyBody) intent.getSerializableExtra(ReplyBody.class.getName()));
}
@@ -104,27 +106,26 @@ public abstract class CIMEventBroadcastReceiver extends BroadcastReceiver {
/*
* 获取sendBody发送成功事件
*/
- if (CIMConstant.IntentAction.ACTION_SEND_FINISHED.equals(action)) {
+ if (IntentAction.ACTION_SEND_FINISHED.equals(action)) {
onSentSucceed((SentBody) intent.getSerializableExtra(SentBody.class.getName()));
}
/*
* 重新连接,如果断开的话
*/
- if (CIMConstant.IntentAction.ACTION_CONNECTION_RECOVERY.equals(action)) {
+ if (IntentAction.ACTION_CONNECTION_RECOVERY.equals(action)) {
connect(0);
}
}
private void startPushService() {
- Intent intent = new Intent(context, CIMPushService.class);
- intent.setAction(CIMPushManager.ACTION_ACTIVATE_PUSH_SERVICE);
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- context.startForegroundService(intent);
- } else {
- context.startService(intent);
+ try {
+ Intent intent = new Intent(context, CIMPushService.class);
+ intent.setAction(ServiceAction.ACTION_ACTIVATE_PUSH_SERVICE);
+ CIMPushManager.startService(context,intent);
+ }catch (Exception ignore){
+ context.sendBroadcast(new Intent(IntentAction.ACTION_CONNECTION_RECOVERY));
}
}
@@ -167,8 +168,8 @@ public abstract class CIMEventBroadcastReceiver extends BroadcastReceiver {
private void connect(long delay) {
Intent serviceIntent = new Intent(context, CIMPushService.class);
- serviceIntent.putExtra(CIMPushService.KEY_DELAYED_TIME, delay);
- serviceIntent.setAction(CIMPushManager.ACTION_CREATE_CIM_CONNECTION);
+ serviceIntent.putExtra(BundleKey.KEY_DELAYED_TIME, delay);
+ serviceIntent.setAction(ServiceAction.ACTION_CREATE_CIM_CONNECTION);
CIMPushManager.startService(context, serviceIntent);
}
@@ -181,12 +182,11 @@ public abstract class CIMEventBroadcastReceiver extends BroadcastReceiver {
}
private boolean isForceOfflineMessage(String action) {
- return CIMConstant.MessageAction.ACTION_999.equals(action);
+ return CIMConstant.ACTION_999.equals(action);
}
/**
* 接收消息实现方法
- *
* @param message
* @param intent
*/
diff --git a/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/CIMPushManager.java b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/CIMPushManager.java
index 130bc18..970478b 100644
--- a/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/CIMPushManager.java
+++ b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/CIMPushManager.java
@@ -30,7 +30,9 @@ import android.net.NetworkInfo;
import android.os.Build;
import android.os.LocaleList;
import android.text.TextUtils;
-import com.farsunset.cim.sdk.android.constant.CIMConstant;
+import com.farsunset.cim.sdk.android.constant.BundleKey;
+import com.farsunset.cim.sdk.android.constant.RequestKey;
+import com.farsunset.cim.sdk.android.constant.ServiceAction;
import com.farsunset.cim.sdk.android.logger.CIMLogger;
import com.farsunset.cim.sdk.android.model.SentBody;
@@ -43,24 +45,6 @@ import java.util.UUID;
public class CIMPushManager {
- protected static final String ACTION_CREATE_CIM_CONNECTION = "ACTION_CREATE_CIM_CONNECTION";
-
- protected static final String ACTION_DESTROY_CIM_SERVICE = "ACTION_DESTROY_CIM_SERVICE";
-
- protected static final String ACTION_ACTIVATE_PUSH_SERVICE = "ACTION_ACTIVATE_PUSH_SERVICE";
-
- protected static final String ACTION_SEND_REQUEST_BODY = "ACTION_SEND_REQUEST_BODY";
-
- protected static final String ACTION_CLOSE_CIM_CONNECTION = "ACTION_CLOSE_CIM_CONNECTION";
-
- protected static final String ACTION_SET_LOGGER_EATABLE = "ACTION_SET_LOGGER_EATABLE";
-
- protected static final String ACTION_SHOW_PERSIST_NOTIFICATION = "ACTION_SHOW_PERSIST_NOTIFICATION";
-
- protected static final String ACTION_HIDE_PERSIST_NOTIFICATION = "ACTION_HIDE_PERSIST_NOTIFICATION";
-
- protected static final String ACTION_CIM_CONNECTION_PONG = "ACTION_CIM_CONNECTION_PONG";
-
/**
* 初始化,连接服务端,在程序启动页或者 在Application里调用
* @param context
@@ -82,7 +66,7 @@ public class CIMPushManager {
Intent serviceIntent = new Intent(context, CIMPushService.class);
- serviceIntent.setAction(ACTION_CREATE_CIM_CONNECTION);
+ serviceIntent.setAction(ServiceAction.ACTION_CREATE_CIM_CONNECTION);
startService(context, serviceIntent);
}
@@ -94,8 +78,8 @@ public class CIMPushManager {
*/
public static void setLoggerEnable(Context context, boolean enable) {
Intent serviceIntent = new Intent(context, CIMPushService.class);
- serviceIntent.putExtra(CIMPushService.KEY_LOGGER_ENABLE, enable);
- serviceIntent.setAction(ACTION_SET_LOGGER_EATABLE);
+ serviceIntent.putExtra(BundleKey.KEY_LOGGER_ENABLE, enable);
+ serviceIntent.setAction(ServiceAction.ACTION_SET_LOGGER_EATABLE);
startService(context, serviceIntent);
}
@@ -109,10 +93,10 @@ public class CIMPushManager {
*/
public static void startForeground(Context context,int icon, String channel , String message) {
Intent serviceIntent = new Intent(context, CIMPushService.class);
- serviceIntent.putExtra(CIMPushService.KEY_NOTIFICATION_MESSAGE, message);
- serviceIntent.putExtra(CIMPushService.KEY_NOTIFICATION_CHANNEL, channel);
- serviceIntent.putExtra(CIMPushService.KEY_NOTIFICATION_ICON, icon);
- serviceIntent.setAction(ACTION_SHOW_PERSIST_NOTIFICATION);
+ serviceIntent.putExtra(BundleKey.KEY_NOTIFICATION_MESSAGE, message);
+ serviceIntent.putExtra(BundleKey.KEY_NOTIFICATION_CHANNEL, channel);
+ serviceIntent.putExtra(BundleKey.KEY_NOTIFICATION_ICON, icon);
+ serviceIntent.setAction(ServiceAction.ACTION_SHOW_PERSIST_NOTIFICATION);
startService(context, serviceIntent);
}
@@ -122,7 +106,7 @@ public class CIMPushManager {
*/
public static void cancelForeground(Context context) {
Intent serviceIntent = new Intent(context, CIMPushService.class);
- serviceIntent.setAction(ACTION_HIDE_PERSIST_NOTIFICATION);
+ serviceIntent.setAction(ServiceAction.ACTION_HIDE_PERSIST_NOTIFICATION);
startService(context, serviceIntent);
}
@@ -159,7 +143,7 @@ public class CIMPushManager {
public static void setTag(Context context, String tag) {
SentBody sent = new SentBody();
- sent.setKey(CIMConstant.RequestKey.CLIENT_SET_TAG);
+ sent.setKey(RequestKey.CLIENT_SET_TAG);
sent.put("tag", tag);
sendRequest(context, sent);
@@ -172,7 +156,7 @@ public class CIMPushManager {
public static void removeTag(Context context) {
SentBody sent = new SentBody();
- sent.setKey(CIMConstant.RequestKey.CLIENT_REMOVE_TAG);
+ sent.setKey(RequestKey.CLIENT_REMOVE_TAG);
sendRequest(context, sent);
}
@@ -187,7 +171,7 @@ public class CIMPushManager {
}
Intent serviceIntent = new Intent(context, CIMPushService.class);
- serviceIntent.setAction(ACTION_CIM_CONNECTION_PONG);
+ serviceIntent.setAction(ServiceAction.ACTION_CIM_CONNECTION_PONG);
startService(context, serviceIntent);
}
@@ -199,7 +183,7 @@ public class CIMPushManager {
CIMCacheManager.putString(context, CIMCacheManager.KEY_UID, uid);
SentBody sent = new SentBody();
- sent.setKey(CIMConstant.RequestKey.CLIENT_BIND);
+ sent.setKey(RequestKey.CLIENT_BIND);
sent.put("uid", String.valueOf(uid));
sent.put("channel", "android");
sent.put("deviceId", getDeviceId(context));
@@ -237,8 +221,8 @@ public class CIMPushManager {
}
Intent serviceIntent = new Intent(context, CIMPushService.class);
- serviceIntent.putExtra(CIMPushService.KEY_SEND_BODY, body);
- serviceIntent.setAction(ACTION_SEND_REQUEST_BODY);
+ serviceIntent.putExtra(BundleKey.KEY_SEND_BODY, body);
+ serviceIntent.setAction(ServiceAction.ACTION_SEND_REQUEST_BODY);
startService(context, serviceIntent);
}
@@ -255,7 +239,7 @@ public class CIMPushManager {
CIMCacheManager.putBoolean(context, CIMCacheManager.KEY_MANUAL_STOP, true);
Intent serviceIntent = new Intent(context, CIMPushService.class);
- serviceIntent.setAction(ACTION_CLOSE_CIM_CONNECTION);
+ serviceIntent.setAction(ServiceAction.ACTION_CLOSE_CIM_CONNECTION);
startService(context, serviceIntent);
}
@@ -269,7 +253,7 @@ public class CIMPushManager {
CIMCacheManager.remove(context, CIMCacheManager.KEY_UID);
Intent serviceIntent = new Intent(context, CIMPushService.class);
- serviceIntent.setAction(ACTION_DESTROY_CIM_SERVICE);
+ serviceIntent.setAction(ServiceAction.ACTION_DESTROY_CIM_SERVICE);
startService(context, serviceIntent);
}
@@ -337,6 +321,7 @@ public class CIMPushManager {
}
}
+
private static String getVersionName(Context context) {
try {
diff --git a/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/CIMPushService.java b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/CIMPushService.java
index c71e937..565e63e 100644
--- a/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/CIMPushService.java
+++ b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/CIMPushService.java
@@ -32,7 +32,9 @@ import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
-import com.farsunset.cim.sdk.android.constant.CIMConstant;
+import com.farsunset.cim.sdk.android.constant.BundleKey;
+import com.farsunset.cim.sdk.android.constant.IntentAction;
+import com.farsunset.cim.sdk.android.constant.ServiceAction;
import com.farsunset.cim.sdk.android.logger.CIMLogger;
import com.farsunset.cim.sdk.android.model.Pong;
import com.farsunset.cim.sdk.android.model.SentBody;
@@ -46,13 +48,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
*/
public class CIMPushService extends Service {
- static final String KEY_SEND_BODY = "KEY_SEND_BODY";
- static final String KEY_DELAYED_TIME = "KEY_DELAYED_TIME";
- static final String KEY_LOGGER_ENABLE = "KEY_LOGGER_ENABLE";
- static final String KEY_NOTIFICATION_MESSAGE = "KEY_NOTIFICATION_MESSAGE";
- static final String KEY_NOTIFICATION_CHANNEL = "KEY_NOTIFICATION_CHANNEL";
- static final String KEY_NOTIFICATION_ICON = "KEY_NOTIFICATION_ICON";
-
private static final String TRANSIENT_NTC_CHANNEL_ID = "CIM_PUSH_TRANSIENT_NTC_ID";
private static final String PERSIST_NTC_CHANNEL_ID = "CIM_PUSH_PERSIST_NTC_ID";
@@ -89,20 +84,13 @@ public class CIMPushService extends Service {
private final ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(Network network) {
- Intent intent = new Intent();
- intent.setPackage(getPackageName());
- intent.setAction(CIMConstant.IntentAction.ACTION_NETWORK_CHANGED);
- sendBroadcast(intent);
+ sendBroadcast(new Intent(IntentAction.ACTION_NETWORK_CHANGED));
}
@Override
public void onLost(Network network) {
- Intent intent = new Intent();
- intent.setPackage(getPackageName());
- intent.setAction(CIMConstant.IntentAction.ACTION_NETWORK_CHANGED);
- sendBroadcast(intent);
+ sendBroadcast(new Intent(IntentAction.ACTION_NETWORK_CHANGED));
}
-
};
private final Handler connectHandler = new Handler() {
@@ -125,50 +113,52 @@ public class CIMPushService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
- String action = intent == null ? CIMPushManager.ACTION_ACTIVATE_PUSH_SERVICE : intent.getAction();
+ Intent newIntent = intent == null ? new Intent(ServiceAction.ACTION_ACTIVATE_PUSH_SERVICE) : intent;
+
+ String action = newIntent.getAction();
if (!persistHolder.get()) {
createNotification();
}
- if (CIMPushManager.ACTION_CREATE_CIM_CONNECTION.equals(action)) {
- this.prepareConnect(intent.getLongExtra(KEY_DELAYED_TIME, 0));
+ if (ServiceAction.ACTION_CREATE_CIM_CONNECTION.equals(action)) {
+ this.prepareConnect(newIntent.getLongExtra(BundleKey.KEY_DELAYED_TIME, 0));
}
- if (CIMPushManager.ACTION_SEND_REQUEST_BODY.equals(action)) {
- connectorManager.send((SentBody) intent.getSerializableExtra(KEY_SEND_BODY));
+ if (ServiceAction.ACTION_SEND_REQUEST_BODY.equals(action)) {
+ connectorManager.send((SentBody) newIntent.getSerializableExtra(BundleKey.KEY_SEND_BODY));
}
- if (CIMPushManager.ACTION_CLOSE_CIM_CONNECTION.equals(action)) {
+ if (ServiceAction.ACTION_CLOSE_CIM_CONNECTION.equals(action)) {
connectorManager.close();
}
- if (CIMPushManager.ACTION_ACTIVATE_PUSH_SERVICE.equals(action)) {
+ if (ServiceAction.ACTION_ACTIVATE_PUSH_SERVICE.equals(action)) {
handleKeepAlive();
}
- if (CIMPushManager.ACTION_DESTROY_CIM_SERVICE.equals(action)) {
+ if (ServiceAction.ACTION_DESTROY_CIM_SERVICE.equals(action)) {
connectorManager.close();
this.stopSelf();
}
- if (CIMPushManager.ACTION_CIM_CONNECTION_PONG.equals(action)) {
+ if (ServiceAction.ACTION_CIM_CONNECTION_PONG.equals(action)) {
connectorManager.send(Pong.getInstance());
}
- if (CIMPushManager.ACTION_SET_LOGGER_EATABLE.equals(action)) {
- boolean enable = intent.getBooleanExtra(KEY_LOGGER_ENABLE, true);
+ if (ServiceAction.ACTION_SET_LOGGER_EATABLE.equals(action)) {
+ boolean enable = newIntent.getBooleanExtra(BundleKey.KEY_LOGGER_ENABLE, true);
CIMLogger.getLogger().debugMode(enable);
}
- if (CIMPushManager.ACTION_SHOW_PERSIST_NOTIFICATION.equals(action)) {
- createPersistNotification(intent.getStringExtra(KEY_NOTIFICATION_CHANNEL),
- intent.getStringExtra(KEY_NOTIFICATION_MESSAGE),
- intent.getIntExtra(KEY_NOTIFICATION_ICON,0));
+ if (ServiceAction.ACTION_SHOW_PERSIST_NOTIFICATION.equals(action)) {
+ createPersistNotification(newIntent.getStringExtra(BundleKey.KEY_NOTIFICATION_CHANNEL),
+ newIntent.getStringExtra(BundleKey.KEY_NOTIFICATION_MESSAGE),
+ newIntent.getIntExtra(BundleKey.KEY_NOTIFICATION_ICON,0));
persistHolder.set(true);
}
- if (CIMPushManager.ACTION_HIDE_PERSIST_NOTIFICATION.equals(action)) {
+ if (ServiceAction.ACTION_HIDE_PERSIST_NOTIFICATION.equals(action)) {
stopForeground(true);
persistHolder.set(false);
}
@@ -177,7 +167,7 @@ public class CIMPushService extends Service {
notificationHandler.sendEmptyMessageDelayed(0, 200);
}
- return super.onStartCommand(intent,flags,startId);
+ return Service.START_REDELIVER_INTENT;
}
private void prepareConnect(long delayMillis) {
@@ -319,6 +309,8 @@ public class CIMPushService extends Service {
intentFilter.addAction(Intent.ACTION_POWER_CONNECTED);
intentFilter.addAction(Intent.ACTION_POWER_DISCONNECTED);
intentFilter.addAction(Intent.ACTION_USER_PRESENT);
+ intentFilter.addAction(Intent.ACTION_BOOT_COMPLETED);
+ intentFilter.addAction(IntentAction.ACTION_CONNECTION_RECOVERY);
return intentFilter;
}
diff --git a/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/coder/ClientMessageDecoder.java b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/coder/ClientMessageDecoder.java
index feff18e..6eefd0d 100644
--- a/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/coder/ClientMessageDecoder.java
+++ b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/coder/ClientMessageDecoder.java
@@ -22,7 +22,7 @@
package com.farsunset.cim.sdk.android.coder;
-import com.farsunset.cim.sdk.android.constant.CIMConstant;
+import com.farsunset.cim.sdk.android.constant.ProtobufType;
import com.farsunset.cim.sdk.android.model.Message;
import com.farsunset.cim.sdk.android.model.Ping;
import com.farsunset.cim.sdk.android.model.ReplyBody;
@@ -72,11 +72,11 @@ public class ClientMessageDecoder {
/*
消息读取完成后,通过type来解析成对应的消息体
*/
- if (CIMConstant.ProtobufType.PING == type) {
+ if (ProtobufType.PING == type) {
return Ping.getInstance();
}
- if (CIMConstant.ProtobufType.REPLY_BODY == type) {
+ if (ProtobufType.REPLY_BODY == type) {
ReplyBodyProto.Model bodyProto = ReplyBodyProto.Model.parseFrom(bodyBuffer.array());
ReplyBody body = new ReplyBody();
body.setKey(bodyProto.getKey());
diff --git a/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/constant/BundleKey.java b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/constant/BundleKey.java
new file mode 100644
index 0000000..6476c86
--- /dev/null
+++ b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/constant/BundleKey.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2013-2019 Xia Jun(3979434@qq.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ***************************************************************************************
+ * *
+ * Website : http://www.farsunset.com *
+ * *
+ ***************************************************************************************
+ */
+package com.farsunset.cim.sdk.android.constant;
+
+public interface BundleKey {
+
+ String KEY_SEND_BODY = "KEY_SEND_BODY";
+
+ String KEY_DELAYED_TIME = "KEY_DELAYED_TIME";
+
+ String KEY_LOGGER_ENABLE = "KEY_LOGGER_ENABLE";
+
+ String KEY_NOTIFICATION_MESSAGE = "KEY_NOTIFICATION_MESSAGE";
+
+ String KEY_NOTIFICATION_CHANNEL = "KEY_NOTIFICATION_CHANNEL";
+
+ String KEY_NOTIFICATION_ICON = "KEY_NOTIFICATION_ICON";
+
+}
diff --git a/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/constant/CIMConstant.java b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/constant/CIMConstant.java
index 00c7d98..582f1fe 100644
--- a/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/constant/CIMConstant.java
+++ b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/constant/CIMConstant.java
@@ -30,84 +30,9 @@ public interface CIMConstant {
*/
int DATA_HEADER_LENGTH = 3;
- interface ProtobufType {
-
- /*
- 客户端->服务端 发送的心跳响应
- */
- byte PONG = 0;
-
- /*
- 服务端->客户端 发送的心跳请求
- */
- byte PING = 1;
-
- byte MESSAGE = 2;
-
- byte SENT_BODY = 3;
-
- byte REPLY_BODY = 4;
- }
-
- interface RequestKey {
-
- String CLIENT_BIND = "client_bind";
-
- String CLIENT_SET_TAG = "client_set_tag";
-
- String CLIENT_REMOVE_TAG = "client_remove_tag";
-
- }
-
- interface MessageAction {
-
- /*
- 被其他设备登录挤下线消息
- */
- String ACTION_999 = "999";
- }
-
- interface IntentAction {
-
- /*
- 消息广播action
- */
- String ACTION_MESSAGE_RECEIVED = "com.farsunset.cim.MESSAGE_RECEIVED";
-
- /*
- 发送sendBody成功广播
- */
- String ACTION_SEND_FINISHED = "com.farsunset.cim.SEND_FINISHED";
-
- /*
- 链接意外关闭广播
- */
- String ACTION_CONNECTION_CLOSED = "com.farsunset.cim.CONNECTION_CLOSED";
-
- /*
- 链接失败广播
- */
- String ACTION_CONNECT_FAILED = "com.farsunset.cim.CONNECT_FAILED";
-
- /*
- 链接成功广播
- */
- String ACTION_CONNECT_FINISHED = "com.farsunset.cim.CONNECT_FINISHED";
-
- /*
- 发送sendBody成功后获得replayBody回应广播
- */
- String ACTION_REPLY_RECEIVED = "com.farsunset.cim.REPLY_RECEIVED";
-
- /*
- 网络变化广播
- */
- String ACTION_NETWORK_CHANGED = "com.farsunset.cim.NETWORK_CHANGED";
-
- /*
- 重试连接
- */
- String ACTION_CONNECTION_RECOVERY = "com.farsunset.cim.CONNECTION_RECOVERY";
- }
+ /*
+ 被其他设备登录挤下线消息
+ */
+ String ACTION_999 = "999";
}
diff --git a/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/constant/IntentAction.java b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/constant/IntentAction.java
new file mode 100644
index 0000000..b4604a2
--- /dev/null
+++ b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/constant/IntentAction.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2013-2019 Xia Jun(3979434@qq.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ***************************************************************************************
+ * *
+ * Website : http://www.farsunset.com *
+ * *
+ ***************************************************************************************
+ */
+package com.farsunset.cim.sdk.android.constant;
+
+public interface IntentAction {
+
+ /*
+ 消息广播action
+ */
+ String ACTION_MESSAGE_RECEIVED = "com.farsunset.cim.MESSAGE_RECEIVED";
+
+ /*
+ 发送sendBody成功广播
+ */
+ String ACTION_SEND_FINISHED = "com.farsunset.cim.SEND_FINISHED";
+
+ /*
+ 链接意外关闭广播
+ */
+ String ACTION_CONNECTION_CLOSED = "com.farsunset.cim.CONNECTION_CLOSED";
+
+ /*
+ 链接失败广播
+ */
+ String ACTION_CONNECT_FAILED = "com.farsunset.cim.CONNECT_FAILED";
+
+ /*
+ 链接成功广播
+ */
+ String ACTION_CONNECT_FINISHED = "com.farsunset.cim.CONNECT_FINISHED";
+
+ /*
+ 发送sendBody成功后获得replayBody回应广播
+ */
+ String ACTION_REPLY_RECEIVED = "com.farsunset.cim.REPLY_RECEIVED";
+
+ /*
+ 网络变化广播
+ */
+ String ACTION_NETWORK_CHANGED = "com.farsunset.cim.NETWORK_CHANGED";
+
+ /*
+ 重试连接
+ */
+ String ACTION_CONNECTION_RECOVERY = "com.farsunset.cim.CONNECTION_RECOVERY";
+
+}
diff --git a/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/constant/ProtobufType.java b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/constant/ProtobufType.java
new file mode 100644
index 0000000..9ebed58
--- /dev/null
+++ b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/constant/ProtobufType.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2013-2019 Xia Jun(3979434@qq.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ***************************************************************************************
+ * *
+ * Website : http://www.farsunset.com *
+ * *
+ ***************************************************************************************
+ */
+package com.farsunset.cim.sdk.android.constant;
+
+public interface ProtobufType {
+
+ /*
+ 客户端->服务端 发送的心跳响应
+ */
+ byte PONG = 0;
+
+ /*
+ 服务端->客户端 发送的心跳请求
+ */
+ byte PING = 1;
+
+ byte MESSAGE = 2;
+
+ byte SENT_BODY = 3;
+
+ byte REPLY_BODY = 4;
+}
diff --git a/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/constant/RequestKey.java b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/constant/RequestKey.java
new file mode 100644
index 0000000..a8b8e3d
--- /dev/null
+++ b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/constant/RequestKey.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2013-2019 Xia Jun(3979434@qq.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ***************************************************************************************
+ * *
+ * Website : http://www.farsunset.com *
+ * *
+ ***************************************************************************************
+ */
+package com.farsunset.cim.sdk.android.constant;
+
+public interface RequestKey {
+
+ String CLIENT_BIND = "client_bind";
+
+ String CLIENT_SET_TAG = "client_set_tag";
+
+ String CLIENT_REMOVE_TAG = "client_remove_tag";
+
+}
diff --git a/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/constant/ServiceAction.java b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/constant/ServiceAction.java
new file mode 100644
index 0000000..73a5503
--- /dev/null
+++ b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/constant/ServiceAction.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2013-2019 Xia Jun(3979434@qq.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ***************************************************************************************
+ * *
+ * Website : http://www.farsunset.com *
+ * *
+ ***************************************************************************************
+ */
+package com.farsunset.cim.sdk.android.constant;
+
+public interface ServiceAction {
+
+ String ACTION_CREATE_CIM_CONNECTION = "ACTION_CREATE_CIM_CONNECTION";
+
+ String ACTION_DESTROY_CIM_SERVICE = "ACTION_DESTROY_CIM_SERVICE";
+
+ String ACTION_ACTIVATE_PUSH_SERVICE = "ACTION_ACTIVATE_PUSH_SERVICE";
+
+ String ACTION_SEND_REQUEST_BODY = "ACTION_SEND_REQUEST_BODY";
+
+ String ACTION_CLOSE_CIM_CONNECTION = "ACTION_CLOSE_CIM_CONNECTION";
+
+ String ACTION_SET_LOGGER_EATABLE = "ACTION_SET_LOGGER_EATABLE";
+
+ String ACTION_SHOW_PERSIST_NOTIFICATION = "ACTION_SHOW_PERSIST_NOTIFICATION";
+
+ String ACTION_HIDE_PERSIST_NOTIFICATION = "ACTION_HIDE_PERSIST_NOTIFICATION";
+
+ String ACTION_CIM_CONNECTION_PONG = "ACTION_CIM_CONNECTION_PONG";
+
+}
diff --git a/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/model/Pong.java b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/model/Pong.java
index d5ae022..c7534cf 100644
--- a/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/model/Pong.java
+++ b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/model/Pong.java
@@ -21,7 +21,7 @@
*/
package com.farsunset.cim.sdk.android.model;
-import com.farsunset.cim.sdk.android.constant.CIMConstant;
+import com.farsunset.cim.sdk.android.constant.ProtobufType;
import java.io.Serializable;
@@ -56,7 +56,7 @@ public class Pong implements Serializable, BinaryBody {
@Override
public byte getType() {
- return CIMConstant.ProtobufType.PONG;
+ return ProtobufType.PONG;
}
}
diff --git a/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/model/SentBody.java b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/model/SentBody.java
index 65d724c..63ebc7d 100644
--- a/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/model/SentBody.java
+++ b/cim-client-sdk/cim-android-sdk/src/main/java/com/farsunset/cim/sdk/android/model/SentBody.java
@@ -21,7 +21,7 @@
*/
package com.farsunset.cim.sdk.android.model;
-import com.farsunset.cim.sdk.android.constant.CIMConstant;
+import com.farsunset.cim.sdk.android.constant.ProtobufType;
import com.farsunset.cim.sdk.android.model.proto.SentBodyProto;
import java.io.Serializable;
@@ -108,7 +108,7 @@ public class SentBody implements Serializable, BinaryBody {
@Override
public byte getType() {
- return CIMConstant.ProtobufType.SENT_BODY;
+ return ProtobufType.SENT_BODY;
}
}
diff --git a/cim-use-examples/cim-client-android/app/build.gradle b/cim-use-examples/cim-client-android/app/build.gradle
index 30523fe..9662cf6 100644
--- a/cim-use-examples/cim-client-android/app/build.gradle
+++ b/cim-use-examples/cim-client-android/app/build.gradle
@@ -34,11 +34,11 @@ android {
}
dependencies {
- implementation "com.farsunset:cim-android-sdk:4.2.0"
- implementation 'androidx.appcompat:appcompat:1.5.0'
- implementation 'com.google.android.material:material:1.6.1'
- implementation 'androidx.annotation:annotation:1.3.0'
- implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
+ implementation "com.farsunset:cim-android-sdk:4.2.5"
+ implementation 'androidx.appcompat:appcompat:1.2.0'
+ implementation 'com.google.android.material:material:1.2.1'
+ implementation 'androidx.annotation:annotation:1.1.0'
+ implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.protobuf:protobuf-lite:3.0.1'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
diff --git a/cim-use-examples/cim-client-android/app/src/main/java/com/farsunset/cim/activity/LoginActivity.java b/cim-use-examples/cim-client-android/app/src/main/java/com/farsunset/cim/activity/LoginActivity.java
index e47810a..8cec312 100644
--- a/cim-use-examples/cim-client-android/app/src/main/java/com/farsunset/cim/activity/LoginActivity.java
+++ b/cim-use-examples/cim-client-android/app/src/main/java/com/farsunset/cim/activity/LoginActivity.java
@@ -19,6 +19,7 @@ import com.farsunset.cim.sdk.android.CIMEventListener;
import com.farsunset.cim.sdk.android.CIMListenerManager;
import com.farsunset.cim.sdk.android.CIMPushManager;
import com.farsunset.cim.sdk.android.constant.CIMConstant;
+import com.farsunset.cim.sdk.android.constant.RequestKey;
import com.farsunset.cim.sdk.android.model.Message;
import com.farsunset.cim.sdk.android.model.ReplyBody;
import com.farsunset.cim.sdk.android.model.SentBody;
@@ -96,7 +97,7 @@ public class LoginActivity extends AppCompatActivity implements CIMEventListener
/*
*第三步 用户id绑定成功,可以接收消息了
*/
- if (replyBody.getKey().equals(CIMConstant.RequestKey.CLIENT_BIND)) {
+ if (replyBody.getKey().equals(RequestKey.CLIENT_BIND)) {
ballsView.runaway();
Intent intent = new Intent(this,MessageActivity.class);
intent.putExtra("uid",uidEdit.getText().toString().trim());