From 770be306e31f447b91d31b2b74c452cd7d714ccf Mon Sep 17 00:00:00 2001 From: Matan Navon Date: Mon, 12 Jul 2021 09:30:39 +0300 Subject: [PATCH 1/5] Adding full screnn intent support --- .../modules/RNPushNotificationHelper.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java b/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java index dc6c67491..1f71dd3bf 100644 --- a/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java +++ b/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java @@ -493,6 +493,9 @@ public void sendToNotificationCentreWithPicture(Bundle bundle, Bitmap largeIconB notification.setChannelId(channel_id); notification.setContentIntent(pendingIntent); + if (bundle.getBoolean("fullScreenIntent")) + notification.setFullScreenIntent(pendingIntent, true); + JSONArray actionsArray = null; try { actionsArray = bundle.getString("actions") != null ? new JSONArray(bundle.getString("actions")) : null; From 920d319c5b2b987e73b0550b750cd658cbcb10fd Mon Sep 17 00:00:00 2001 From: mateyFromTheBlock Date: Sat, 31 Jul 2021 11:19:13 +0300 Subject: [PATCH 2/5] Update README.md --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/README.md b/README.md index 5c341253f..0ea0d38df 100644 --- a/README.md +++ b/README.md @@ -333,6 +333,8 @@ PushNotification.localNotification({ actions: ["Yes", "No"], // (Android only) See the doc for notification actions to know more invokeApp: true, // (optional) This enable click on actions to bring back the application to foreground or stay in background, default: true + fullScreenIntent: false, // (optional) Specifies to whether or not to launch an intent instead of posting the notification to the status bar. + /* iOS only properties */ category: "", // (optional) default: empty string @@ -781,3 +783,43 @@ RNPushNotification.IntentHandlers.add(new RNPushNotification.RNIntentHandler() { ## iOS Only Methods `PushNotification.getApplicationIconBadgeNumber(callback: Function)` Get badge number + +## Full screen intents + +(Android Only) + +In order to launch an intent instead of posting the notification to the status bar you will have to specify `fullScreenIntent: true` while configuring the local notification. + +**NOTE: Apps targeting Build.VERSION_CODES#Q and above will have to request a permission in order to use full screen intents.** +```xml + +```` + +**NOTE: To be able to view the intent launched by the app when the device is locked you will have to add the following properties the the MainActivity as follows** +```xml + +```` + +Additionally you will have to add the following code to the `MainActivity.java` file. +```java +@Override +protected void onStart() { + super.onStart(); + ... + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { + setShowWhenLocked(true); + setTurnScreenOn(true); + } else { + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON); + } + ... +} +``` + From bde864a58702ed51f89806f052100a3c46ef94e2 Mon Sep 17 00:00:00 2001 From: mateyFromTheBlock Date: Wed, 22 Sep 2021 23:41:45 +0300 Subject: [PATCH 3/5] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3e1f42f31..52f3caef3 100644 --- a/README.md +++ b/README.md @@ -826,7 +826,7 @@ In order to launch an intent instead of posting the notification to the status b ```` -**NOTE: To be able to view the intent launched by the app when the device is locked you will have to add the following properties the the MainActivity as follows** +**NOTE: To be able to view the intent launched by the app when the device is locked you will have to add the following properties to the MainActivity as follows** ```xml ```` From 6e782baefb809e631feb44b97294fe6aee75fd2b Mon Sep 17 00:00:00 2001 From: Matan Navon Date: Sun, 17 Oct 2021 20:39:59 +0300 Subject: [PATCH 4/5] fix(support) adding support for android 6.0 + adding full screen intent to the example app --- example/App.js | 13 +++++++--- example/NotifService.js | 9 ++++--- .../android/app/src/main/AndroidManifest.xml | 6 ++++- .../main/java/com/example/MainActivity.java | 25 +++++++++++++++++++ example/package.json | 2 +- 5 files changed, 46 insertions(+), 9 deletions(-) diff --git a/example/App.js b/example/App.js index eb08ef637..286ef16d9 100644 --- a/example/App.js +++ b/example/App.js @@ -14,6 +14,7 @@ import { View, TouchableOpacity, Alert, + ScrollView } from 'react-native'; import NotifService from './NotifService'; @@ -30,7 +31,7 @@ export default class App extends Component { render() { return ( - + Example app react-native-push-notification @@ -133,13 +134,20 @@ export default class App extends Component { }}> popInitialNotification + { + this.notif.scheduleNotif(null, true); + }}> + Full screen intent notification in 30s + {this.state.fcmRegistered && FCM Configured !} - + ); } @@ -158,7 +166,6 @@ export default class App extends Component { const styles = StyleSheet.create({ container: { - flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', diff --git a/example/NotifService.js b/example/NotifService.js index 6935285c1..79ac3dc86 100644 --- a/example/NotifService.js +++ b/example/NotifService.js @@ -17,7 +17,7 @@ export default class NotifService { PushNotification.setApplicationIconBadgeNumber(0); } }); - + PushNotification.getChannels(function(channels) { console.log(channels); }); @@ -107,7 +107,7 @@ export default class NotifService { }); } - scheduleNotif(soundName) { + scheduleNotif(soundName, fullScreenIntent) { this.lastId++; PushNotification.localNotificationSchedule({ date: new Date(Date.now() + 30 * 1000), // in 30 secs @@ -133,10 +133,10 @@ export default class NotifService { when: null, // (optionnal) Add a timestamp pertaining to the notification (usually the time the event occurred). For apps targeting Build.VERSION_CODES.N and above, this time is not shown anymore by default and must be opted into by using `showWhen`, default: null. usesChronometer: false, // (optional) Show the `when` field as a stopwatch. Instead of presenting `when` as a timestamp, the notification will show an automatically updating display of the minutes and seconds since when. Useful when showing an elapsed time (like an ongoing phone call), default: false. timeoutAfter: null, // (optional) Specifies a duration in milliseconds after which this notification should be canceled, if it is not already canceled, default: null - + /* iOS only properties */ category: '', // (optional) default: empty string - + /* iOS and Android properties */ id: this.lastId, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID title: 'Scheduled Notification', // (optional) @@ -145,6 +145,7 @@ export default class NotifService { playSound: !!soundName, // (optional) default: true soundName: soundName ? soundName : 'default', // (optional) Sound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played) number: 10, // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero) + fullScreenIntent, }); } diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 8a88f01e5..b7df03fe4 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -6,6 +6,7 @@ + + android:windowSoftInputMode="adjustResize" + android:showOnLockScreen="true" + android:showWhenLocked="true" + android:turnScreenOn="true"> diff --git a/example/android/app/src/main/java/com/example/MainActivity.java b/example/android/app/src/main/java/com/example/MainActivity.java index 5e57fb914..e72af6fe4 100644 --- a/example/android/app/src/main/java/com/example/MainActivity.java +++ b/example/android/app/src/main/java/com/example/MainActivity.java @@ -1,5 +1,10 @@ package com.example; +import android.annotation.SuppressLint; +import android.os.Build; +import android.os.PowerManager; +import android.view.WindowManager; + import com.facebook.react.ReactActivity; public class MainActivity extends ReactActivity { @@ -12,4 +17,24 @@ public class MainActivity extends ReactActivity { protected String getMainComponentName() { return "example"; } + + @Override + protected void onStart() { + super.onStart(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { + setShowWhenLocked(true); + setTurnScreenOn(true); + } else { + PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); + PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "myapp:wakeLock"); + wl.acquire(); + + getWindow().addFlags( + WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON + | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON + | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON + | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED + ); + } + } } diff --git a/example/package.json b/example/package.json index 867a10807..3dcaf4642 100644 --- a/example/package.json +++ b/example/package.json @@ -14,7 +14,7 @@ "@react-native-community/push-notification-ios": "^1.7.0", "react": "16.13.1", "react-native": "0.63.3", - "react-native-push-notification": "zo0r/react-native-push-notification#dev" + "react-native-push-notification": "https://github.com/mateyFromTheBlock/react-native-push-notification.git#adding-full-screen-intent-support" }, "devDependencies": { "@babel/core": "^7.9.0", From f41b8c8142313778c2a23f5542689a02b5529cf5 Mon Sep 17 00:00:00 2001 From: Matan Navon Date: Sun, 17 Oct 2021 20:52:51 +0300 Subject: [PATCH 5/5] fix(support) adding support for android 6.0 + adding full screen intent to the example app --- example/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/example/package.json b/example/package.json index 3dcaf4642..f69111910 100644 --- a/example/package.json +++ b/example/package.json @@ -14,6 +14,7 @@ "@react-native-community/push-notification-ios": "^1.7.0", "react": "16.13.1", "react-native": "0.63.3", + "react-native-push-notification": "Change line below back to 'zo0r/react-native-push-notification#dev' once this brnach is merged to the dev branch.", "react-native-push-notification": "https://github.com/mateyFromTheBlock/react-native-push-notification.git#adding-full-screen-intent-support" }, "devDependencies": {