fcm 을 통해서
코드를 문서에 있는 것 거의 그대로 사용했습니다.
푸시 알림이 오는것 까진 잘 됩니다. 그런데, 푸시 알림이 와도 화면도 안켜지고, 아무런 소리, 진동도 울리지 않는 것이 문제네요..
소리, 진동, 화면켜짐 기능까지 넣으려면 추가적인 코드를 작성해야 하나요??
일단 setDefaults(NotificationCompat.DEFAULT_VIBRATE) 코드는 넣었고,
퍼미션에서 vibrate 도 추가했습니다.
다음은 코드입니다..
private void sendPushNotification(String message) {
System.out.println("received message : " + message);
// 클래스...
Intent intent = new Intent(this, Activity_Login_Main.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)
.setSmallIcon(R.drawable.backicon).setLargeIcon
(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher) )
.setContentTitle("Push Title ")
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri).setDefaults(NotificationCompat.DEFAULT_VIBRATE)
.setLights(000000255,500,2000)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakelock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
wakelock.acquire(5000);
notificationManager.notify(0 // ID of notification
, notificationBuilder.build());
}
}