问题描述
我已经实现了前台服务和广播侦听器来处理通知。当应用程序在前台或在最近的应用程序中但是一旦应用程序被杀死时,它可以完美地工作。它停止工作。请帮忙。这是我启动前台服务的代码。
//get values
String theTitle = remoteMessage.getData().get("title");
String theMessage = remoteMessage.getData().get("message");
String callerName = remoteMessage.getData().get("sender_name");
String callerAvatar = remoteMessage.getData().get("sender_avatar");
String callerId = remoteMessage.getData().get("sender_uid");
String roomId = remoteMessage.getData().get("room_name");
String sessionId = remoteMessage.getData().get("call_session_id");
int notificationId = buildNotificationId(callerId);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
Intent serviceIntent = new Intent(getApplicationContext(),HeadsUpNotificationService.class);
Bundle mBundle = new Bundle();
mBundle.putString(Common.CALL_NAME_INTENT,callerName);
mBundle.putString(Common.CALL_AVATAR_INTENT,callerAvatar);
mBundle.putString(Common.CALL_USER_ID_INTENT,callerId);
mBundle.putString(Common.CALL_TYPE_INTENT,dataType);
mBundle.putString(Common.CALL_SESSION_INTENT,sessionId);
mBundle.putString(Common.CALL_ROOM_INTENT,roomId);
serviceIntent.putExtras(mBundle);
ContextCompat.startForegroundService(getApplicationContext(),serviceIntent);
} else {
//build notification
Intent notificationIntent = new Intent(getApplicationContext(),CallCustomringer.class);
//add flags and get extras from payload
notificationIntent.putExtra(Common.CALL_USER_ID_INTENT,callerId);
notificationIntent.putExtra(Common.CALL_NAME_INTENT,callerName);
notificationIntent.putExtra(Common.CALL_AVATAR_INTENT,callerAvatar);
notificationIntent.putExtra(Common.CALL_ROOM_INTENT,roomId);
notificationIntent.putExtra(Common.CALL_SESSION_INTENT,sessionId);
notificationIntent.putExtra(Common.CALL_TYPE_INTENT,dataType);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(notificationIntent);
}
还有什么我应该做的。请帮忙。让我发疯了
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)