Commit 3ec485c4 authored by Libin Lu's avatar Libin Lu

add instruction for android click notification

parent 8ffcac97
......@@ -3,7 +3,7 @@
- Run `npm install react-native-fcm --save`
- Run rnpm link
### Android Configuration
## Android Configuration
- In `android/build.gradle`
```gradle
......@@ -39,8 +39,40 @@ android:theme="@style/AppTheme">
</service>
...
```
### Config for notification and `click_action` in Android
To allow android to respond to `click_action`, you need to define Activities and filter on specific intent. Since all javascript is running in MainActivity, you can have MainActivity to handle actions.
```xml
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTop" <--add this line to reuse MainActivity
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter> <--add this line
<action android:name="fcm.ACTION.HELLO" /> <--add this line, name should match click_action
<category android:name="android.intent.category.DEFAULT" /> <--add this line
</intent-filter> <--add this line
</activity>
```
and pass intent into package, change MainActivity.java
```java
@Override <--add this line
protected void onNewIntent(Intent intent){ <--add this line
setIntent(intent); <--add this line to update intent on notification click
} <--add this line
@Override
protected List<ReactPackage> getPackages() {
...
new FIRMessagingPackage(getIntent()), <--add getIntent()
...
```
### IOS Configuration
## IOS Configuration
install pod 'Firebase/Messaging'
......@@ -105,56 +137,26 @@ this.fcmTokenLsnr.remove();
}
```
### Response to `click_action` in Android
To allow android to respond to `click_action`, you need to define Activities and filter on specific intent. Since everything is running in MainActivity, you can have MainActivity to handle actions.
```xml
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter> <--add this line
<action android:name="fcm.ACTION.HELLO" /> <--add this line, name should match click_action
<category android:name="android.intent.category.DEFAULT" /> <--add this line
</intent-filter> <--add this line
</activity>
```
and pass intent into package, change MainActivity.java
```java
new FIRMessagingPackage(getIntent()), <--add getIntent()
```
### Behaviour when sending `click_action` and `data` in notification
### Behaviour when sending `notification` and `data` payload through GCM
- When app is not running when user clicks notification, notification data will be passed into
- `FCM.initialAction`(contains `click_action` in notification payload
- `FCM.initialData` (contains `data` payload if you send together with notification)
- When app is running in background
- IOS will receive notificaton from `FCMNotificationReceived` event
- Android will reload the whole react app
- App will receive notificaton from `FCMNotificationReceived` event when user click on notification
- When app is running in foreground
- Both will receive notificaton from `FCMNotificationReceived` event
- IOS will receive notification and android **won't** (better not to do anything in foreground for hybrid and send a seprate data message.)
NOTE: it is recommend not to rely on `data` payload for click_action as it can be overwritten. check [this](http://stackoverflow.com/questions/33738848/handle-multiple-notifications-with-gcm)
## Q & A
#### My android build is failing
Try update your SDK and google play service
#### I can't get notification data when app is killed?
#### I can't get notification when app is killed
If you send notification with `data` only, you can only get the data message when app is in foreground or background. Killed app doesn't trigger FCMNotificationReceived. Seems that is how FCM works today
#### App running in background doesn't trigger `FCMNotificationReceived` when receiving hybrid notification [Android]
These is [an issue opened for that](https://github.com/google/gcm/issues/63). You will received data payload in FCM.initialData if you click on the notification. But if you just open the app, the data is lost.
#### I can't get `notification` payload when my android app is in foreground
It is better to use data payload if you need to pass data into application. I haven't implemented notification payload bridging in android module and am not planning to (the SDK should post notification for you)
#### Notification payload and data payload are mixed in iOS app.
I'm not doing any filtering. Try to add some `type` attributes to differentiate data payload from APN notification
#### App reloads when notification is clicked [Android]
Preserve app status with asyncStorage should get around this. Still looking for solution
### It is missing some features
These is [an issue opened for that](https://github.com/google/gcm/issues/63). Behavior is not consistent between 2 platforms
#### It is missing some features
Issues and pull requests are welcomed. Let's make this thing better!
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment