Page 315 - 2020학년도 MDP과제발표회 자료집 (통신과) (3)
P. 315

private  void  scheduleJob()  {
                             //  [START  dispatch_job]
                             FirebaseJobDispatcher   dispatcher   =    new      FirebaseJobDispatcher(new
             GooglePlayDriver(this));
                             Job  myJob  =  dispatcher.newJobBuilder()
                                             .setService(MyJobService.class)
                                             .setTag("my-job-tag")
                                             .build();
                             dispatcher.schedule(myJob);
                     }


                     private  void  handleNow()  {
                             Log.d(TAG,  "Short  lived  task  is  done.");
                     }


                     private  void  sendNotification()  {
                             Intent  intent  =  new  Intent(Intent.ACTION_VIEW,  Uri.parse(link));


                             PendingIntent  pendingIntent  =  PendingIntent.getActivity(this,  0,  intent,
                                             PendingIntent.FLAG_ONE_SHOT);
                             String  channelId  =  getString(R.string.default_notification_channel_id);
                             Uri                         defaultSoundUri                                 =
             RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                             NotificationCompat.Builder  notificationBuilder  =
                                             new  NotificationCompat.Builder(this)
                                                             .setSmallIcon(R.mipmap.smarthome2)
                                                             .setContentTitle(title)
                                                             .setContentText(body)
                                                             .setChannelId(channelId)
                                                             .setSound(defaultSoundUri)
                                                             .setVibrate(new  long[]{1,  1000})
                                                             .setContentIntent(pendingIntent)
                                                             .setPriority(Notification.PRIORITY_HIGH)
                                                             .setAutoCancel(true);


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


                             if  (Build.VERSION.SDK_INT  >=  Build.VERSION_CODES.O)  {
                                     String  channelName  =  getString(R.string.default_notification_channel_name);
                                     NotificationChannel  channel  =  new  NotificationChannel(channelId,  channelName,
             NotificationManager.IMPORTANCE_HIGH);
                                     notificationManager.createNotificationChannel(channel);
                             }
                             notificationManager.notify(0,  notificationBuilder.build());
                     }
             }                                           -  327  -
   310   311   312   313   314   315   316   317   318   319   320