FFireBase Notifiction firebase notifiction:  sing Firebase Cloud Messaging you can send three types of messages i.e  Notification Message ,...

Android Push Notifications using Firebase Cloud Messaging

09:15 0 Comments

FFireBase Notifiction

firebase notifiction: sing Firebase Cloud Messaging you can send three types of messages i.e Notification MessageData Message and message with both Notification & Data Payload.






DOWNLOAD CODE


Let go start :




Add the Dependencies


Add FIREBASE nofiction dependencies

implementation 'com.google.firebase:firebase-messaging:11.8.0'



Updating the Android Manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.main.projects.neo_istone.phone.neo_istone">

     <uses-permission android:name="android.permission.INTERNET"/>
   <application 
        android:allowBackup="true"
        android:icon="@mipmap/app_icon"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/app_icon_round"
        android:supportsRtl="true" 
        android:theme="@style/AppTheme">

   <activity android:name=".MainActivity">
       <intent-filter>
          <action 
             android:name="android.intent.action.MAIN"/>
          <category 
             android:name="android.intent.category.LAUNCHER"/>
         </intent-filter>
       </activity>
       <service android:name=".MessagingService">
       <intent-filter>
       <action android:name="com.google.firebase.MESSAGING_EVENT"/>
       </intent-filter>
       </service>
       <meta-data 
            android:name="com.google.firebase.messaging.default_notification_icon" 
            android:resource="@drawable/app_icon_round"/>
       <meta-data 
            android:name="com.google.firebase.messaging.defult_notification_color" 
            android:resource="@color/colorAccent"/>
</application>
</manifest>

Creata java class MessagingService.class

Messaging.java


package com.main.projects.neo_istone.phone.neo_istone;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

import java.net.URI;

public class MessagingService extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage ){
        final Uri uri = null;
       showNotification(remoteMessage.getNotification().getBody(),uri.toString());
    }
    public void showNotification(String message,String uri) {
        Intent intent = new Intent();
        intent.putExtra("url",uri);
        startActivity(intent);
        PendingIntent pi = PendingIntent.getActivity(this, 0,
                new Intent(this, MainActivity.class), 0);
        Notification notification = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.app_icon_round)
                .setContentTitle("Neo-istone-code")
                .setContentText(message)
                .setContentIntent(pi)
                .setAutoCancel(true)
                .build();

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(0, notification);
    }
}

0 Comments: