Last active
September 2, 2020 11:30
-
-
Save gryzzly/d026be33c56f30f8cf2455b84757f258 to your computer and use it in GitHub Desktop.
Revisions
-
gryzzly revised this gist
Sep 2, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ package com.foo.bar; import android.util.Log; -
gryzzly created this gist
Sep 2, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,85 @@ package com.mad.dance; import android.util.Log; import android.content.Context; import android.provider.Settings; import java.lang.System; import android.app.Notification; import androidx.core.app.NotificationCompat; import android.app.NotificationManager; import android.app.NotificationChannel; import android.content.Intent; import android.app.PendingIntent; import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.ReadableMap; public class Notifications extends ReactContextBaseJavaModule { private static ReactApplicationContext reactContext; Notifications(ReactApplicationContext context) { super(context); reactContext = context; } @Override public String getName() { return "Notifications"; } @ReactMethod public void show(ReadableMap details) { Log.v("my-debug", "notifications show start"); Intent notificationIntent = new Intent( reactContext, MainActivity.class ); PendingIntent pendingIntent = PendingIntent.getActivity( reactContext, 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK ); NotificationCompat.Builder b = new NotificationCompat.Builder(reactContext); b .setContentIntent(pendingIntent) .setContentText("Body text not working") .setSmallIcon(R.mipmap.ic_launcher) .setAutoCancel(true) .setChannelId("10000"); if (details.hasKey("body")) { b.setContentText(details.getString("body")); } NotificationManager notificationManager = (NotificationManager) reactContext.getSystemService(Context.NOTIFICATION_SERVICE); // It's safe to call this repeatedly because creating an existing notification // channel performs no operation. // https://developer.android.com/training/notify-user/build-notification NotificationChannel notificationChannel = new NotificationChannel( "10000", "NOTIFICATION_CHANNEL_NAME", NotificationManager.IMPORTANCE_HIGH ); notificationManager.createNotificationChannel(notificationChannel) ; notificationManager.notify(1, b.build()); Log.v("my-debug", "notifications show reached end"); } }