firebase를 이용한 앱 푸시알림 클릭시 원하는 화면으로 전환

firebase를 이용한 앱 푸시알림 클릭시 원하는 화면으로 전환

QA

firebase를 이용한 앱 푸시알림 클릭시 원하는 화면으로 전환

본문

스마트폰에서 앱 푸시알림을 클릭하면 앱이 켜져서 DeliveryManagement.class 화면으로 이동하도록 구현하고 싶은데 앱이 켜지는것까지는 실행이 되는데 화면 이동이 되지 않습니다.

 

이동 구현에 대해 조언 부탁드립니다.

 

혹시 참고할만한 사이트가 있다면 링크 부탁드립니다.

 



public class MyFirebaseMessagingService extends FirebaseMessagingService {
    private static final String TAG = "MyFirebaseMsgService";
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.d(TAG, "From: " + remoteMessage.getFrom());
        if (remoteMessage.getData().size() > 0) {
            Log.d(TAG, "Message data payload: " + remoteMessage.getData());
            if (/* Check if data needs to be processed by long running job */ true) {// For long-running tasks (10 seconds or more) use Firebase Job Dispatcher.
            } else {
                // Handle message within 10 seconds
                handleNow();
            }
        }
        if (remoteMessage.getNotification() != null) {
            Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
            sendNotification(remoteMessage.getNotification().getBody(), remoteMessage.getNotification().getTitle());
        }
    }

    /**
     * Handle time allotted to BroadcastReceivers.
     */
    private void handleNow() {
        Log.d(TAG, "Short lived task is done.");
    }

    /**
     * Create and show a simple notification containing the received FCM message.
     *
     *  messageBody FCM message body received.
     */
    private void sendNotification(String messageBody, String messageTitle) {

        Intent intent = new Intent(this, DeliveryManagement.class);

        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

        String channelId = "MARS_D";
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);



        NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(this, channelId)
                        .setSmallIcon(R.drawable.b_logo)
                        .setContentTitle(messageTitle)
                        .setContentText(messageBody)
                        .setAutoCancel(true)
                        .setSound(defaultSoundUri)
                        .setContentIntent(pendingIntent);

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

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            String channelName = "D";
            NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_HIGH);
            notificationManager.createNotificationChannel(channel);
        }
        notificationManager.notify(0, notificationBuilder.build());
    }
}

이 질문에 댓글 쓰기 :

답변 1

자바는 잘 모르지만.. 

 

혹시 이것이라도 참조해보세요.

 

https://stackoverflow.com/questions/40718155/open-specific-activity-when-notification-clicked-in-fcm

 

정확한 답이 아니라도,  이 것을 근거로 찾아 보세요

답변을 작성하시기 전에 로그인 해주세요.
전체 19
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT