Android App Study_31 (Notification with Python (FCM))

Android App Study_31 (Notification with Python (FCM))

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 46 47 48 49 50 51 52 53 54 55 56 57 58

package com.example.smarttrashcanapplication; import ... public class FirebaseInstanceIDService extends FirebaseMessagingService { private static final String TAG = "FirebaseMsgService" ; private String msg, title; @Override public void onNewToken(@NonNull String s) { super .onNewToken(s); Log.d( "NEW_TOKEN" , s); } @Override public void onMessageReceived(@NonNull RemoteMessage remoteMessage) { if (remoteMessage.getData() = = null ) return ; sendNotification(remoteMessage.getData().get( "title" ), remoteMessage.getData().get( "content" )); } private void sendNotification( String title, String content) { Intent intent = new Intent( this , MainActivity. class ); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); final String CHANNEL_ID = "채널 아이디" ; NotificationManager mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT > = Build.VERSION_CODES.O) { final String CHANNEL_NAME = "채널 이름" ; final String CHANNEL_DESCRIPTION = "채널 " ; final int importance = NotificationManager.IMPORTANCE_HIGH; NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, importance); mChannel.setDescription(CHANNEL_DESCRIPTION); mChannel.enableLights( true ); mChannel.enableVibration( true ); mChannel.setVibrationPattern( new long []{ 100 , 200 , 100 , 200 }); mChannel.setSound(defaultSoundUri, null ); mChannel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); mManager.createNotificationChannel(mChannel); } NotificationCompat.Builder builder = new NotificationCompat.Builder( this , CHANNEL_ID); builder.setAutoCancel( true ); builder.setDefaults(Notification.DEFAULT_ALL); builder.setWhen( System .currentTimeMillis()); builder.setSmallIcon(R.mipmap.ic_launcher); builder.setContentText(content); builder.setContentText(title); builder.setSound(defaultSoundUri); builder.setVibrate( new long []{ 500 , 500 }); mManager. notify ( 0 , builder.build()); } } Colored by Color Scripter

from http://yunseong.tistory.com/56 by ccl(A) rewrite - 2021-12-21 00:27:36