Last active
September 21, 2020 06:22
-
-
Save 0x1bitcrack3r/d4d5e99a7f3e691dd466c949abe25598 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FirebaseMessagingService | |
extends FirebaseMessagingService { | |
private static DeviceEventManagerModule.RCTDeviceEventEmitter eventEmitter = null; | |
@Override | |
public void onMessageReceived(RemoteMessage remoteMessage) { | |
try { | |
String notifDataType = remoteMessage.getData().get("type"); | |
String startCallType="incomingcall"; | |
String disconnectCallType="calldisconnected"; | |
if(startCallType.equals(notifDataType)|| disconnectCallType.equals(notifDataType)) { | |
showIncomingCallScreen(remoteMessage,!isAppRunning()); | |
return; | |
} | |
} catch (Exception e) { | |
} | |
} | |
private void showIncomingCallScreen(RemoteMessage remoteMessage,boolean isAppRunning) { | |
String notifDataType = remoteMessage.getData().get("type"); | |
String startCallType="incomingcall"; | |
String disconnectCallType="calldisconnected"; | |
if( startCallType.equals(notifDataType)) { | |
Intent i = new Intent(getApplicationContext(), IncomingCallScreenActivity.class); | |
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); | |
i.putExtra("CALLER_NAME", remoteMessage.getData().get("callerName")); | |
i.putExtra("CALL_TYPE",remoteMessage.getData().get("type")); | |
i.putExtra("APP_STATE",isAppRunning); | |
startActivity(i); | |
}else if(disconnectCallType.equals((notifDataType))){ | |
LocalBroadcastManager localBroadcastManager = LocalBroadcastManager | |
.getInstance(FirebaseMessagingService.this); | |
localBroadcastManager.sendBroadcast(new Intent( | |
"com.incomingcallscreenactivity.action.close")); | |
} | |
} | |
private boolean isAppRunning() { | |
ActivityManager m = (ActivityManager) this.getSystemService( ACTIVITY_SERVICE ); | |
List<ActivityManager.RunningTaskInfo> runningTaskInfoList = m.getRunningTasks(10); | |
Iterator<ActivityManager.RunningTaskInfo> itr = runningTaskInfoList.iterator(); | |
int n=0; | |
while(itr.hasNext()){ | |
n++; | |
itr.next(); | |
} | |
if(n==1){ // App is killed | |
return false; | |
} | |
return true; // App is in background or foreground | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment