android sdk 适配 android14

This commit is contained in:
远方夕阳 2023-10-05 16:40:35 +08:00
parent 6a02c58d4e
commit cfac26b7ad
3 changed files with 24 additions and 6 deletions

View File

@ -189,5 +189,5 @@ https://www.yuque.com/yuanfangxiyang/ma4ytb/vvy3iz/edit#nnzKN
android端sdk引用 android端sdk引用
``` ```
implementation "com.farsunset:cim-android-sdk:4.2.11" implementation "com.farsunset:cim-android-sdk:4.2.12"
``` ```

View File

@ -6,7 +6,7 @@
<groupId>com.farsunset</groupId> <groupId>com.farsunset</groupId>
<artifactId>cim-android-sdk</artifactId> <artifactId>cim-android-sdk</artifactId>
<version>4.2.11</version> <version>4.2.12</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>${project.groupId}:${project.artifactId}</name> <name>${project.groupId}:${project.artifactId}</name>

View File

@ -26,6 +26,7 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.ServiceInfo;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.Network; import android.net.Network;
import android.os.Build; import android.os.Build;
@ -69,7 +70,7 @@ public class CIMPushService extends Service {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
keepAliveReceiver = new KeepAliveBroadcastReceiver(); keepAliveReceiver = new KeepAliveBroadcastReceiver();
registerReceiver(keepAliveReceiver, keepAliveReceiver.getIntentFilter(),Context.RECEIVER_EXPORTED); registerReceiver(keepAliveReceiver, keepAliveReceiver.getIntentFilter());
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
@ -111,6 +112,23 @@ public class CIMPushService extends Service {
} }
}; };
@Override
public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
return super.registerReceiver(keepAliveReceiver, keepAliveReceiver.getIntentFilter(),Context.RECEIVER_EXPORTED);
}else {
return super.registerReceiver(keepAliveReceiver, keepAliveReceiver.getIntentFilter());
}
}
private void startForegroundNotification(int id, Notification notification) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
startForeground(id,notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_REMOTE_MESSAGING);
}else {
startForeground(id,notification);
}
}
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
@ -260,7 +278,7 @@ public class CIMPushService extends Service {
Notification notification = makeNotification(PERSIST_NTC_CHANNEL_ID,icon,title,message); Notification notification = makeNotification(PERSIST_NTC_CHANNEL_ID,icon,title,message);
startForeground(NOTIFICATION_ID, notification); startForegroundNotification(NOTIFICATION_ID, notification);
return; return;
} }
@ -275,7 +293,7 @@ public class CIMPushService extends Service {
Notification notification = makeNotification(TRANSIENT_NTC_CHANNEL_ID,0,CIMPushService.class.getSimpleName(),null); Notification notification = makeNotification(TRANSIENT_NTC_CHANNEL_ID,0,CIMPushService.class.getSimpleName(),null);
startForeground(NOTIFICATION_ID, notification); startForegroundNotification(NOTIFICATION_ID, notification);
} }
@ -297,7 +315,7 @@ public class CIMPushService extends Service {
Notification notification = makeNotification(PERSIST_NTC_CHANNEL_ID,icon,channelName,message); Notification notification = makeNotification(PERSIST_NTC_CHANNEL_ID,icon,channelName,message);
startForeground(NOTIFICATION_ID,notification); startForegroundNotification(NOTIFICATION_ID,notification);
} }