房间通知适配
This commit is contained in:
@@ -51,16 +51,6 @@ public class DaemonService extends Service {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
//8.0系统适配
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
createNotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
RoomInfo roomInfo = AvRoomDataManager.get().mCurrentRoomInfo;
|
||||
@@ -72,11 +62,25 @@ public class DaemonService extends Service {
|
||||
builder.setContentText("点击返回房间");
|
||||
builder.setTicker("正在房间内");
|
||||
Intent clickIntent = new Intent(this, NotificationClickReceiver.class);
|
||||
PendingIntent contentIntent = PendingIntent.getBroadcast(this.getApplicationContext(), (int) System.currentTimeMillis(), clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
int flag = PendingIntent.FLAG_UPDATE_CURRENT;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
||||
flag = flag | PendingIntent.FLAG_IMMUTABLE;
|
||||
}
|
||||
PendingIntent contentIntent = PendingIntent.getBroadcast(
|
||||
this.getApplicationContext(),
|
||||
(int) (System.currentTimeMillis() / 100000),
|
||||
clickIntent,
|
||||
flag);
|
||||
builder.setContentIntent(contentIntent);
|
||||
//8.0系统适配
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
builder.setChannelId(CHANNEL_ID);
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
String channelID = getPackageName() + "1";
|
||||
String channelName = "进入房间通知";
|
||||
NotificationChannel channel = new NotificationChannel(channelID, channelName, NotificationManager.IMPORTANCE_HIGH);
|
||||
channel.setSound(null, null);
|
||||
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
manager.createNotificationChannel(channel);
|
||||
builder.setChannelId(channelID);
|
||||
}
|
||||
startForeground(NOTICE_ID, builder.build());
|
||||
isStartForeground = true;
|
||||
@@ -96,13 +100,6 @@ public class DaemonService extends Service {
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.O)
|
||||
private void createNotificationChannel(String channelId, String channelName, int importance) {
|
||||
NotificationChannel channel = new NotificationChannel(channelId, channelName, importance);
|
||||
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
Reference in New Issue
Block a user