Page 914 - 완) I MDP 프로젝트 작품 보고서(전체과 1학년)1.6
P. 914

//  [START  receive_message]
                 @Override
                    //메시지가  FCM서버에서  스마트폰으로  보내지게  된다면  이  클래스로              오게  된다.
                    public  void  onMessageReceived(RemoteMessage  remoteMessage)  {


                            sendNotification(remoteMessage.getData().get("message"));
                 }


                    private  void  sendNotification(String  messageBody)  {
                            Intent  intent  =  new  Intent(this,  MainActivity.class);

                       intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            PendingIntent  pendingIntent  =  PendingIntent.getActivity(this, 0 /*  Request  code
            */,  intent,
                                 PendingIntent.FLAG_ONE_SHOT);



                       Uri  defaultSoundUri=
            RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                       NotificationCompat.Builder  notificationBuilder = new
            NotificationCompat.Builder(this)
                               //이곳에서  Push 알림의 디자인을 정해줄 수 있다.

                                 .setSmallIcon(R.mipmap.ic_launcher)
                                 .setContentTitle("FCM Push  Test")
                                 .setContentText(messageBody)
                                 .setAutoCancel(true)
                                 .setSound(defaultSoundUri)

                                 .setContentIntent(pendingIntent);


                       NotificationManager  notificationManager  =
                                 (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);



                       notificationManager.notify(0 /*  ID of  notification */,  notificationBuilder.build());
                 }


            }









                                                         -  907  -
   909   910   911   912   913   914   915   916   917   918   919