mirror of
https://github.com/balzack/databag.git
synced 2025-04-21 09:05:13 +00:00
issuing notification when received
This commit is contained in:
parent
ecf9152865
commit
7c05d1e4fc
@ -159,6 +159,8 @@ dependencies {
|
||||
// The version of react-native is set by the React Native Gradle Plugin
|
||||
implementation("com.facebook.react:react-android")
|
||||
|
||||
implementation 'androidx.core:core:1.8.0'
|
||||
|
||||
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0")
|
||||
|
||||
implementation 'com.github.UnifiedPush:android-connector:2.1.1'
|
||||
|
@ -3,6 +3,17 @@ package com.databag;
|
||||
import android.content.Context;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.unifiedpush.android.connector.MessagingReceiver;
|
||||
import android.util.Log;
|
||||
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Intent;
|
||||
|
||||
import android.os.Build;
|
||||
import android.net.Uri;
|
||||
import android.media.RingtoneManager;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
public class CustomReceiver extends MessagingReceiver {
|
||||
public CustomReceiver() {
|
||||
@ -10,6 +21,9 @@ public class CustomReceiver extends MessagingReceiver {
|
||||
}
|
||||
@Override
|
||||
public void onNewEndpoint(@NotNull Context context, @NotNull String endpoint, @NotNull String instance) {
|
||||
|
||||
Log.i("UNIFIED", "onNewEndpoint:instance=" + instance + " endpoint=" + endpoint);
|
||||
|
||||
// Called when a new endpoint be used for sending push messages
|
||||
}
|
||||
|
||||
@ -25,6 +39,31 @@ public class CustomReceiver extends MessagingReceiver {
|
||||
|
||||
@Override
|
||||
public void onMessage(@NotNull Context context, @NotNull byte[] message, @NotNull String instance) {
|
||||
|
||||
Intent intent = new Intent(context, MainActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0 /* Request code */, intent,
|
||||
PendingIntent.FLAG_IMMUTABLE);
|
||||
|
||||
String channelId = "fcm_default_channel";
|
||||
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
||||
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context,
|
||||
channelId)
|
||||
.setSmallIcon(R.mipmap.ic_launcher)
|
||||
.setContentTitle("FCM Message").setContentText("ROLO?").setAutoCancel(true).setSound(
|
||||
defaultSoundUri).setContentIntent(pendingIntent);
|
||||
|
||||
NotificationManager notificationManager = (NotificationManager) context.getSystemService(
|
||||
Context.NOTIFICATION_SERVICE);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
NotificationChannel channel = new NotificationChannel(channelId, "Channel human readable title",
|
||||
NotificationManager.IMPORTANCE_DEFAULT);
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
}
|
||||
|
||||
notificationManager.notify(0, notificationBuilder.build());
|
||||
|
||||
// Called when a new message is received. The message contains the full POST body of the push message
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user