diff --git a/README.md b/README.md index 224b8b80c..52f3caef3 100644 --- a/README.md +++ b/README.md @@ -339,6 +339,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 @@ -813,3 +815,41 @@ PushNotification.checkPermissions(callback: Function) //Check permissions 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 to 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); + } + ... +} + 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 248ff0825..1c4b9c9a0 100644 --- a/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java +++ b/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java @@ -498,6 +498,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; 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..f69111910 100644 --- a/example/package.json +++ b/example/package.json @@ -14,7 +14,8 @@ "@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": "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": { "@babel/core": "^7.9.0",