Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit dafbaf7

Browse files
Use notification channel on Android (#4)
This is required for Android Oreo. Hard-code channel parameters for now.
1 parent e60fbd9 commit dafbaf7

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

android/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ allprojects {
1616
apply plugin: 'com.android.library'
1717

1818
android {
19-
compileSdkVersion 23
20-
buildToolsVersion "23.0.1"
19+
compileSdkVersion 26
20+
buildToolsVersion "26.0.3"
2121

2222
defaultConfig {
2323
minSdkVersion 16
24-
targetSdkVersion 23
24+
targetSdkVersion 28
2525
versionCode 1
2626
versionName "1.0"
2727
ndk {
@@ -39,7 +39,7 @@ android {
3939
dependencies {
4040
compile fileTree(dir: 'libs', include: ['*.jar'])
4141
testCompile 'junit:junit:4.12'
42-
compile 'com.android.support:appcompat-v7:23.1.1'
42+
compile 'com.android.support:appcompat-v7:26.1.+'
4343
compile 'com.facebook.react:react-native:+'
4444
compile 'com.google.android.gms:play-services-gcm:+'
4545
compile 'me.leolin:ShortcutBadger:1.1.8@aar'

android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import android.app.Activity;
44
import android.app.Application;
5+
import android.app.NotificationChannel;
56
import android.app.NotificationManager;
67
import android.content.BroadcastReceiver;
78
import android.content.Context;
89
import android.content.Intent;
910
import android.content.IntentFilter;
11+
import android.os.Build;
1012
import android.os.Bundle;
1113
import android.support.v4.content.LocalBroadcastManager;
1214

@@ -27,7 +29,15 @@
2729
import java.util.Random;
2830

2931
public class RNPushNotification extends ReactContextBaseJavaModule implements ActivityEventListener {
30-
public static final String LOG_TAG = "RNPushNotification";// all logging should use this tag
32+
public static final String LOG_TAG = "RNPushNotification"; // all logging should use this tag
33+
34+
// Hardcode these channel parameters for now; ideally, we'd be
35+
// able to plumb this through from PushNotification.configure.
36+
37+
public static final String CHANNEL_ID = "keybase_channel_all";
38+
39+
private static final String CHANNEL_NAME = "Keybase";
40+
private static final int CHANNEL_IMPORTANCE = NotificationManager.IMPORTANCE_DEFAULT;
3141

3242
private RNPushNotificationHelper mRNPushNotificationHelper;
3343
private final Random mRandomNumberGenerator = new Random(System.currentTimeMillis());
@@ -45,6 +55,13 @@ public RNPushNotification(ReactApplicationContext reactContext) {
4555
mJsDelivery = new RNPushNotificationJsDelivery(reactContext);
4656

4757
registerNotificationsRegistration();
58+
59+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
60+
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, CHANNEL_IMPORTANCE);
61+
NotificationManager manager =
62+
(NotificationManager) reactContext.getSystemService(reactContext.NOTIFICATION_SERVICE);
63+
manager.createNotificationChannel(channel);
64+
}
4865
}
4966

5067
@Override

android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public void sendToNotificationCentre(Bundle bundle) {
158158
title = context.getPackageManager().getApplicationLabel(appInfo).toString();
159159
}
160160

161-
NotificationCompat.Builder notification = new NotificationCompat.Builder(context)
161+
NotificationCompat.Builder notification = new NotificationCompat.Builder(context, RNPushNotification.CHANNEL_ID)
162162
.setContentTitle(title)
163163
.setTicker(bundle.getString("ticker"))
164164
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)

0 commit comments

Comments
 (0)