I integrated the push notification system with Firebase in my project and it's working well. Few clarficiation
Steps to follow the integration of Firebase
Dependency compile lib added in my build.gradel ( root as well as inside of app)
AndroidManifest.xml added the following server.
<service
android:name="com.myfirebase.myfirebasemsgservice"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
Inside of the "myfirebasemsgservice" added the following line and proceeding and working well.
public void onMessageReceived(RemoteMessage fcmMessage)
{
Log.d(TAG, "From: " + fcmMessage.getFrom());
if (fcmMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + fcmMessage.getData());
Log.d(TAG, "Message data payload: " + fcmMessage.getData().toString());
I checked and got an notification if sending from firebase console as well as ARC (Advanced REST CLIENT). I tried Notification Payload and Data Payload both are working well.
My clarification and how we need to integrate in firebase same like below code. How we did previously means?. Any idea and how we need to integrate like this?.
AndroidManifest.xml - added previously.
<receiver
android:name="com.mygcm.gcmbroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
<service android:name="com.mygcm.gcmIntentService" />
gcmbroadcastReceiver added the below code.
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent) {
ComponentName comp = new ComponentName(context.getPackageName(),
GCMIntentService.class.getName());
startWakefulService(context, (intent.setComponent(comp)));
}
}
gcmIntentService added the below code.
public class gcmIntentService extends IntentService {
@Override
protected void onHandleIntent(Intent intent)
{
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
try
{
if (!extras.isEmpty())
{
if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType))
{
Log.d("LogData",intent.getStringExtra(Constants.PAYLOAD));
}
else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType))
{
Log.d("LogData",intent.getStringExtra(Constants.PAYLOAD));
}
else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType))
{
Log.d("LogData",intent.getStringExtra(Constants.PAYLOAD));
}
}
}
catch(Exception ignored)
{
ExceptionTrack exe_track=ExceptionTrack.getInstance();
}
finally {
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
}
<service
android:name=".fcm.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service
android:name=".fcm.FireBaseInstanceID_Service">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
App Gradle
compile 'com.google.firebase:firebase-messaging:9.4.0' apply plugin: 'com.google.gms.google-services'
Project Gradle classpath 'com.google.gms:google-services:3.0.0'
Log.e("token_id", FirebaseInstanceId.getInstance().getToken());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With