The code to open application upon receiving notification is working till Android 9 but not in 10. Android has some major security changes in Android 10 as per their document. I don't know how this can be done in the Android 10.
This is my code.
FirebaseNotificationService.class
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
dataMap = remoteMessage.getData();
if (dataMap == null) {
return;
}
if (dataMap.get("title").equalsIgnoreCase("video_call")) {
Intent intent = new Intent(AppConstants.INCOMING_CALL_BROADCAST_ACTION);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("title", remoteMessage.getData().get("title"));
intent.putExtra("sender", remoteMessage.getData().get("sender"));
sendImplicitBroadcast(FirebaseNotificationService.this, intent);
}
}
private static void sendImplicitBroadcast(Context ctxt, Intent i) {
PackageManager pm = ctxt.getPackageManager();
List<ResolveInfo> matches = pm.queryBroadcastReceivers(i, 0);
for (ResolveInfo resolveInfo : matches) {
Intent explicit = new Intent(i);
ComponentName cn =
new ComponentName(resolveInfo.activityInfo.applicationInfo.packageName,
resolveInfo.activityInfo.name);
explicit.setComponent(cn);
ctxt.sendBroadcast(explicit);
}
}
This i'm receiving in my Service receiver class and open an activity.
VideoCallReceiver.class
@Override
public void onReceive(Context context, Intent intent) {
if (Objects.requireNonNull(intent.getAction()).equalsIgnoreCase(AppConstants.INCOMING_CALL_BROADCAST_ACTION)) {
context.startActivity(new Intent(context, ReceiveCallActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.setAction(Intent.ACTION_ANSWER)
.putExtra("title", intent.getStringExtra("title"))
.putExtra("sender", intent.getStringExtra("sender"))
}
}
The declaration of receiver in manifest is as such
AndroidManifest.xml
<receiver
android:name=".services.VideoCallReceiver"
android:excludeFromRecents="true"
android:showWhenLocked="true"
android:turnScreenOn="true">
<intent-filter>
<action android:name="call_from_user" />
</intent-filter>
</receiver>
This code has been tested till Android 9. All working fine.
Any help would be appreciated.