안녕하세요,
FCM을 이용해서 등록된 앱들에게 메시지, 이미지 등 보내는 것은 해결했는데요.
만약 해당 이미지, 푸시 메시지를 눌렀을 때, 지정한 웹페이지를 열려고하는데요.
웹에서 푸시서버로 메시지를 보낼 때는,
...
$imgsrc ="이미지경로;
$link = "푸시 눌렀을 때 이동할 페이지주소";
$message = "푸시메시지";
$message = array("message" => $message, "imgsrc" => $imgsrc, "link" => $link);
$message_result = send_notification($tokens, $message);
...
이런식으로 message 배열을 통해서 링크 페이지 주소도 같이 보냅니다.
그리고 안드로이드에서 받는 onMessageReceived 함수에서
...
imgsrc = remoteMessage.getData().get("imgsrc");
link = remoteMessage.getData().get("link");
sendNotification(remoteMessage.getData().get("message"));
...
문자열 변수 두 개 앞에 선언해서 푸시에서 받은 변수에 저장된 값들을 받아 저장시킨뒤에..
sendNotification 함수에서
....
// 기존용 : Intent intent = new Intent(this, MainActivity.class);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
Log.d("Link", link);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
....
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setStyle(style)
.setContentTitle("알림이 도착했습니다.")
.setContentText("밑으로 드래그해주세요.")
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setDefaults(NotificationCompat.DEFAULT_VIBRATE)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0
// ID of notification
, notificationBuilder.build());
...
이런식으로 실행하면 메시지를 눌러도 페이지가 열리거나 하지는 않더라구요. startActivity(intent)를 하게 되면 어플이 꺼져버리구요..
그래서 기존에 있던 템플릿을 보니 PendingIntent를 사용해서 NotificationCompat.Builder에 setContentIntent(PendingIntent)로 설정해두던데.. 이 부분이 클릭했을 때 동작 부분을 설정할 수 있는 부분이 맞나요..?
해당 푸시메시지를 클릭했을 때 웹페이지를 새로 열려면 어떤 방식으로 가야하는지 궁금합니다 (__)
이런 경우에도 어플이 먼저 실행된 다음 웹페이지를 열어야하나요? 웹으로 바로 연결은 없는건지.. 둘 다 가능한지 궁금합니다 :D