[Fix] Open app on push notification tap (#16136)

Signed-off-by: Mohamed Javid <19339952+smohamedjavid@users.noreply.github.com>
This commit is contained in:
Mohamed Javid 2023-06-02 20:33:27 +08:00 committed by GitHub
parent c5e6bd790d
commit c5166ac48e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 22 deletions

View File

@ -67,8 +67,8 @@ public class PushNotificationHelper {
private static final long DEFAULT_VIBRATION = 300L; private static final long DEFAULT_VIBRATION = 300L;
private static final String CHANNEL_ID = "status-im-notifications"; private static final String CHANNEL_ID = "status-im-notifications";
public static final String ACTION_DELETE_NOTIFICATION = "im.status.ethereum.module.DELETE_NOTIFICATION"; public static final String ACTION_DELETE_NOTIFICATION = "im.status.ethereum.module.DELETE_NOTIFICATION";
public static final String ACTION_TAP_NOTIFICATION = "im.status.ethereum.module.TAP_NOTIFICATION";
public static final String ACTION_TAP_STOP = "im.status.ethereum.module.TAP_STOP"; public static final String ACTION_TAP_STOP = "im.status.ethereum.module.TAP_STOP";
final int flag = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_MUTABLE : PendingIntent.FLAG_CANCEL_CURRENT;
private NotificationManager notificationManager; private NotificationManager notificationManager;
@ -119,13 +119,8 @@ public class PushNotificationHelper {
private final BroadcastReceiver notificationActionReceiver = new BroadcastReceiver() { private final BroadcastReceiver notificationActionReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (intent.getAction() == ACTION_TAP_NOTIFICATION || if (intent.getAction() == ACTION_DELETE_NOTIFICATION) {
intent.getAction() == ACTION_DELETE_NOTIFICATION) {
String deepLink = intent.getExtras().getString("im.status.ethereum.deepLink");
String groupId = intent.getExtras().getString("im.status.ethereum.groupId"); String groupId = intent.getExtras().getString("im.status.ethereum.groupId");
if (intent.getAction() == ACTION_TAP_NOTIFICATION) {
context.startActivity(getOpenAppIntent(deepLink));
}
if (groupId != null) { if (groupId != null) {
cleanGroup(groupId); cleanGroup(groupId);
} }
@ -141,7 +136,6 @@ public class PushNotificationHelper {
private void registerBroadcastReceiver() { private void registerBroadcastReceiver() {
IntentFilter filter = new IntentFilter(); IntentFilter filter = new IntentFilter();
filter.addAction(ACTION_DELETE_NOTIFICATION); filter.addAction(ACTION_DELETE_NOTIFICATION);
filter.addAction(ACTION_TAP_NOTIFICATION);
filter.addAction(ACTION_TAP_STOP); filter.addAction(ACTION_TAP_STOP);
context.registerReceiver(notificationActionReceiver, filter); context.registerReceiver(notificationActionReceiver, filter);
Log.e(LOG_TAG, "Broadcast Receiver registered"); Log.e(LOG_TAG, "Broadcast Receiver registered");
@ -701,37 +695,31 @@ public class PushNotificationHelper {
private StatusMessage createMessage(Bundle data) { private StatusMessage createMessage(Bundle data) {
Person author = getPerson(data.getBundle("notificationAuthor")); Person author = getPerson(data.getBundle("notificationAuthor"));
return new StatusMessage(data.getString("id"), author, data.getLong("timestamp"), data.getString("message")); long timeStampLongValue = (long) data.getDouble("timestamp");
return new StatusMessage(data.getString("id"), author, timeStampLongValue, data.getString("message"));
} }
private PendingIntent createGroupOnDismissedIntent(Context context, int notificationId, String groupId, String deepLink) { private PendingIntent createGroupOnDismissedIntent(Context context, int notificationId, String groupId, String deepLink) {
Intent intent = new Intent(ACTION_DELETE_NOTIFICATION); Intent intent = new Intent(ACTION_DELETE_NOTIFICATION);
intent.putExtra("im.status.ethereum.deepLink", deepLink); intent.putExtra("im.status.ethereum.deepLink", deepLink);
intent.putExtra("im.status.ethereum.groupId", groupId); intent.putExtra("im.status.ethereum.groupId", groupId);
return PendingIntent.getBroadcast(context.getApplicationContext(), notificationId, intent, return PendingIntent.getBroadcast(context.getApplicationContext(), notificationId, intent, flag);
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_MUTABLE);
} }
private PendingIntent createGroupOnTapIntent(Context context, int notificationId, String groupId, String deepLink) { private PendingIntent createGroupOnTapIntent(Context context, int notificationId, String groupId, String deepLink) {
Intent intent = new Intent(ACTION_TAP_NOTIFICATION); Intent intent = getOpenAppIntent(deepLink);
intent.putExtra("im.status.ethereum.deepLink", deepLink); return PendingIntent.getActivity(context.getApplicationContext(), notificationId, intent, flag);
intent.putExtra("im.status.ethereum.groupId", groupId);
return PendingIntent.getBroadcast(context.getApplicationContext(), notificationId, intent,
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_MUTABLE);
} }
private PendingIntent createOnTapIntent(Context context, int notificationId, String deepLink) { private PendingIntent createOnTapIntent(Context context, int notificationId, String deepLink) {
Intent intent = new Intent(ACTION_TAP_NOTIFICATION); Intent intent = getOpenAppIntent(deepLink);
intent.putExtra("im.status.ethereum.deepLink", deepLink); return PendingIntent.getActivity(context.getApplicationContext(), notificationId, intent, flag);
return PendingIntent.getBroadcast(context.getApplicationContext(), notificationId, intent,
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_MUTABLE);
} }
private PendingIntent createOnDismissedIntent(Context context, int notificationId, String deepLink) { private PendingIntent createOnDismissedIntent(Context context, int notificationId, String deepLink) {
Intent intent = new Intent(ACTION_DELETE_NOTIFICATION); Intent intent = new Intent(ACTION_DELETE_NOTIFICATION);
intent.putExtra("im.status.ethereum.deepLink", deepLink); intent.putExtra("im.status.ethereum.deepLink", deepLink);
return PendingIntent.getBroadcast(context.getApplicationContext(), notificationId, intent, return PendingIntent.getBroadcast(context.getApplicationContext(), notificationId, intent, flag);
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_MUTABLE);
} }
public void removeStatusMessage(Bundle bundle) { public void removeStatusMessage(Bundle bundle) {