현제 푸시알람이 오면 Notification을 이용해서 알려주는 소스를 이것 저것 찾아보면서 하고있는데
지금 현상이 그 푸시 알람을 받는 옙을 화면에 켜놓은 상태이면 소리, 진동이 잘 울리고 반응을 하는데
화면이 꺼진상태에서도 하고 싶은데 일단은 옙을 접어두면 상태바에 뜨기는 뜨나 메세지가 왔다고 진동이나 소리가 나지 않습니다. 이것저것 찾아 봤을때는 세로운 액티비티를 띄우는것도 있으나 잘 못따라해서...
현제는 알람이 오면 옙 밖에서도 소리와 진동, 화면이 꺼진 상태라면은 화면도 꺠우는 방향으로 만들고 싶은데 어느부분을 고치거나 추가해야될지 여쭤 봅니다.
푸시메세지를 받는 부분 코드입니다.
public class MessagingService extends FirebaseMessagingService {
private static final String TAG = "Test";
private String msg;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// Not getting messages here? See why this may be: https://goo.gl/39bRNJ
Log.d(TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
msg = remoteMessage.getNotification().getBody();
notiMake(msg);
}
public void notiMake(String msg){
PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0,
new Intent(getApplicationContext(), LogInPage.class), 0);
//알림창 설정빌더
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext()).setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("e편한카페")
.setContentText(msg)
.setAutoCancel(true)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setVibrate(new long[]{1, 1000}
);
mBuilder.setProgress(100, 50, false);
mBuilder.setWhen(System.currentTimeMillis());
mBuilder.setDefaults(Notification.DEFAULT_ALL);
NotificationManager notificationManager =
(NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, mBuilder.build());
mBuilder.setContentIntent(contentIntent);
}
}
현제는 그냥 알림창만 띄우게 해놨습니다. 외부에서 소리나 진동을 울리려면 어떻게 해야될까요?.