当应用程序被杀死时 activity 出现几秒钟然后消失 android (SINCH)
When app is killed activity appear for some second then disappear in android (SINCH )
当我收到来自sinch的通知时,我首先检查应用程序是否在后台
如果应用程序在后台
if(isAppIsInBackground(context)) {
relayMessageData(data);
}
public void relayMessageData(Map<String, String> data) {
payload = data;
createNotificationChannel(NotificationManager.IMPORTANCE_MAX);
getApplicationContext().bindService(new Intent(getApplicationContext(), SinchService.class), this, BIND_AUTO_CREATE);
}
}.relayMessageData(data);
然后在sinch服务中调用onIncomingCall方法
@Override public void onIncomingCall(CallClient callClient, Call call) {
Log.d(TAG, "sinch onIncomingCall: " + call.getCallId());
Intent intent = new Intent(SinchService.this, IncomingCallScreenActivity.class);
intent.putExtra(EXTRA_ID, MESSAGE_ID);
intent.putExtra(CALL_ID, call.getCallId());
boolean inForeground = isAppOnForeground(SinchService.this);
if (!inForeground) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
//intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !inForeground) {//Q
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(MESSAGE_ID, createIncomingCallNotification(call.getRemoteUserId(), intent));
} else {
//((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(MESSAGE_ID, createIncomingCallNotification(call.getRemoteUserId(), intent));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
SinchService.this.startActivity(intent);
}
}
我通过在 FirebaseMessagingService 上添加 powerManager 代码解决了这个问题
if(isAppIsInBackground(context)){
Log.e("sinch data","isAppIsInBackground");
//relayMessageData(data);
Intent intent = new Intent(context, IncomingCallScreenActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("CALL_ID",result.getCallResult().getCallId());
//intent.putExtra("id",result.getMessageResult().getMessageId());
startActivity(intent);
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP, "ReplaceTag");
wl.acquire(15000);
}
当我收到来自sinch的通知时,我首先检查应用程序是否在后台 如果应用程序在后台
if(isAppIsInBackground(context)) {
relayMessageData(data);
}
public void relayMessageData(Map<String, String> data) {
payload = data;
createNotificationChannel(NotificationManager.IMPORTANCE_MAX);
getApplicationContext().bindService(new Intent(getApplicationContext(), SinchService.class), this, BIND_AUTO_CREATE);
}
}.relayMessageData(data);
然后在sinch服务中调用onIncomingCall方法
@Override public void onIncomingCall(CallClient callClient, Call call) {
Log.d(TAG, "sinch onIncomingCall: " + call.getCallId());
Intent intent = new Intent(SinchService.this, IncomingCallScreenActivity.class);
intent.putExtra(EXTRA_ID, MESSAGE_ID);
intent.putExtra(CALL_ID, call.getCallId());
boolean inForeground = isAppOnForeground(SinchService.this);
if (!inForeground) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
//intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !inForeground) {//Q
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(MESSAGE_ID, createIncomingCallNotification(call.getRemoteUserId(), intent));
} else {
//((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(MESSAGE_ID, createIncomingCallNotification(call.getRemoteUserId(), intent));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
SinchService.this.startActivity(intent);
}
}
我通过在 FirebaseMessagingService 上添加 powerManager 代码解决了这个问题
if(isAppIsInBackground(context)){
Log.e("sinch data","isAppIsInBackground");
//relayMessageData(data);
Intent intent = new Intent(context, IncomingCallScreenActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("CALL_ID",result.getCallResult().getCallId());
//intent.putExtra("id",result.getMessageResult().getMessageId());
startActivity(intent);
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP, "ReplaceTag");
wl.acquire(15000);
}