https://medium.com/techsuzu/android-push-notification-using-fcm-firebase-cloud-messaging-c37d165b8320

 

Android Push notification using FCM (Firebase Cloud Messaging)

What is FCM (Firebase Cloud Messaging) ?

medium.com

Start : https://firebase.google.com/?authuser=0

add the following : 

classpath 'com.google.gms:google-services:4.0.1'

apply plugin: 'com.google.gms.google-services'

implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.android.gms:play-services-auth:16.0.1'

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package com.example.calculatorfeb03;
 
 
 
 
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
 
 
    @Override
    public void onTokenRefresh() {
 
        //For registration of token
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
 
        //To displaying token on logcat
        Log.d("TOKEN: ", refreshedToken);
 
    }
 
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.example.calculatorfeb03;
 
import android.content.Context;
 
 
 
 
public class MyFirebaseMessagingService extends FirebaseMessagingService {
 
    @Override
    public void onMessageReceived(RemoteMessage message) {
        sendMyNotification(message.getNotification().getBody());
    }
 
 
    private void sendMyNotification(String message) {
 
        //On click of notification it redirect to this Activity
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this0, intent, PendingIntent.FLAG_ONE_SHOT);
 
        Uri soundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("My Firebase Push notification")
                .setContentText(message)
                .setAutoCancel(true)
                .setSound(soundUri)
                .setContentIntent(pendingIntent);
 
        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
 
        notificationManager.notify(0notificationBuilder.build());
    }
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

'ETC' 카테고리의 다른 글

Android Studio notes1(02/13/20 cudo notes)  (0) 2020.02.13
REGEX  (0) 2020.02.12
Regular Expressions  (0) 2020.02.10
es6  (0) 2020.02.10
JSON APIs and Ajax  (0) 2020.02.10

+ Recent posts