To change the small notification icon or enable foreground push, you'll need to change the AndroidManifest.xml file from Cordova.
To do so you'll need to install the cordova custom config plugin using these instructions: https://github.com/dpa99c/cordova-custom-config#installation
Once that is done, you'll be able to add manifest entry in your plugin's config.xml. Here's an example:
<?xml version='1.0' encoding='utf-8'?> <widget [...] xmlns:android="http://schemas.android.com/apk/res/android"> [...] <platform name="android"> [...] <custom-config-file target="AndroidManifest.xml" parent="./application"> <meta-data android:name="com.batch.android.push.foreground_push_handling" android:value="true" /> </custom-config-file> </platform> </widget>
Small icons appear in the Android notification bar and allow users to recognize your app when they receive a notification. Before releasing a new version of your app on the Store, you should make sure you've set a custom small icon for your notifications.
If you use a colored small icon, Android will display it as a white square:
In order to set it up with Batch Push, you have to do three things:
Put your small icon drawables in the Android project's
res folder, for all screen densities. Your projet folder architecture should look like that:
res ├── drawable-hdpi │ └── ic_notification_icon.png ├── drawable-mdpi │ └── ic_notification_icon.png ├── drawable-xhdpi │ └── ic_notification_icon.png └── drawable-xxhdpi └── ic_notification_icon.png
Once you did that, add the following in your manifests'
<meta-data android:name="com.batch.android.push.smallicon" android:resource="@drawable/ic_notification_icon" />
Your notifications will now automatically use that icon. Please note that you are not forced to use
ic_notification_icon for the icon's name. The name in the manifest simply needs to match the filenames.
For your Android 5.0 users (and newer), you should set a color to your notification, which will be shown behind the small icon.
Simply add this in your manifest, just like the small icon metadata:
<meta-data android:name="com.batch.android.push.color" android:value="#FF00FF00" />
You can also use
android:resource instead of
android:value and point to a color defined in an XML ressource file.
Batch's Cordova plugin acts differently when the app is in foreground depending on the platform:
batchPushReceivedevent. When in the background, notifications will be displayed by the OS and your app will get
batchPushReceivedwhen the user taps on a notification
Starting with Batch 1.7, you can change the plugin behaviour on Android to match iOS'. Simply add the following to your manifest:
<meta-data android:name="com.batch.android.push.foreground_push_handling" android:value="true" />
Note: You'll need to set this in your
config.xml. Please see higher up in this documentation how to correctly set this property.
You can restrict notification display on Android with several parameters such as disabling sound, vibration, or simply disabling notifications for that user if you have a way to ask for opt-in.
Batch Push provides you with an enum with the interactions a notification can have via:
batch.push.AndroidNotificationTypes. This enum contains ALERT, SOUND, LIGHTS, NONE and VIBRATE. By default, everything is activated.
Call batch.push.setAndroidNotificationTypes whenever you want in the runtime of your application.
batch.push.setAndroidNotificationTypes(batch.push.AndroidNotificationTypes.ALERT | batch.push.AndroidNotificationTypes.LIGHTS | batch.push.AndroidNotificationTypes.VIBRATE );
Just like Android, you can set the notification types you want on iOS.
The enum is
batch.push.iOSNotificationTypes, and contains BADGE, SOUND, ALERT.
For example, if you want to disable sound:
batch.push.setiOSNotificationTypes(batch.push.iOSNotificationTypes.ALERT | batch.push.iOSNotificationTypes.BADGE);
Since this setting affects what the user will be asked to allow in the iOS notification request popup, this should be done before you call