Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Implement FCM from Android Studio GUI

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 294
    Comment on it

    This blog is about how to implement FCM(Firebase Cloud messaging) from Android Studio.

    Android studio gives you tools to implement  Firebase tools in very easy way.

    1. Open Android Studio. (Make sure Android Studio is up to date)

    2. Click on Tools from menu.

    3. Select Firebase. This will open side window of Firebase tools.

    4. Select Cloud Messaging and click on setuo Firebase cloud messaging.

    5. Now click to Connect to Firebase. this will open login page in browser.

    6. Give allow to permissions.

    7. If you have already created project in Firebase then select that one or Create new project.

    8. Connect to Firebase.

    9. Click on Add FCM to app.

    10. Create class which extends FirebaseInstanceIdService.

    11. Override onTokenRefresh() method in class. You will get device token from this method.

    @Override
    public void onTokenRefresh() {
        // Get updated InstanceID token.
        String token = FirebaseInstanceId.getInstance().getToken();
      
    }

    12. Add this service class also in manifest.

    <service
        android:name="SERVICE_NAME_HERE">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
    </service>

    13. Create new service class which extends FirebaseMessagingService.

    14. Override onMessageReceived() of class.

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
     
        Log.d(TAG, "Notification Message" + remoteMessage.getNotification().getBody());
    }

    15. Register Service to Manifest also.

    <service
        android:name="SERVICE_CLASS_NAME">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT"/>
        </intent-filter>
    </service>

    16. Now you can test your notification from https://console.firebase.google.com.

     

    Happy Coding :D

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: