Search code examples
androidsinchandroid-sinch-api

When app is killed activity appear for some second then disappear in android (SINCH )


When i receive the notification from sinch, i first check if app is in background or not if app is in background

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);

then onIncomingCall method is called in sinch service

@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);


    }
}

Solution

  • i am resolve this issue by adding powerManager code on FirebaseMessagingService

    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);
    
                                }