Firebase Cloud Message
- To integrate Firebase push notifications, configure
strings.xml, add the required permissions to the<manifest>root node ofmanifest.xml, and add the required component declarations to the<application>node. These declarations have already been configured in the delivered SDK, as shown below.
Configure strings.xml
- Enable Firebase push notifications in strings.xml:
xml
<!--Whether Firebase push notifications are integrated: 1 = integrated, 0 = not integrated (default)-->
<string name="is_access_firebase">1</string>Configure manifest.xml
- Add the permission declarations. Add each permission only once in either the SDK or the game; otherwise, an error will occur at runtime:
xml
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="{package name}.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="{package name}.permission.C2D_MESSAGE" />- Add the related component declaration:
xml
<service
android:name="com.gd.fcmpush.GDFirebaseMessagingService"
android:exported="false" >
<intent-filter android:priority="-500" >
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>- If the game also uses Firebase push notifications, register a broadcast receiver with the
com.gd.fcm.actionaction in the manifest, then obtain the RemoteMessage object from the intent parameter of the receiver's onReceive method, as shown below: - Register the broadcast receiver:
xml
<receiver android:name="{your custom broadcast receiver}">
<intent-filter>
<action android:name="com.gd.fcm.action" />
</intent-filter>
</receiver>- FcmReceiver class:
java
public class "{your custom broadcast receiver}" extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
RemoteMessage remoteMessage = (RemoteMessage) intent.getExtras().get("remoteMessage");
// TODO Handle the game's Firebase push notification logic.
}
}