마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

Notification으로 푸시메세지를 띄우고싶은데 소리,진동,화면 범위?설정 질문드립니다.

0 추천

현제 푸시알람이 오면 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);
    }

}

현제는 그냥 알림창만 띄우게 해놨습니다. 외부에서 소리나 진동을 울리려면 어떻게 해야될까요?.

햇병아리안드로이드개발희망자 (120 포인트) 님이 2017년 7월 9일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...