안녕하세요.
현재 파이어베이스 클라우드 메시징에서 고급옵션> KEY&VALUE 에서
key 에는 url, value 에는 웹페이지 주소를 주고 notification 을 받아서 클릭하면 mainActivity에서 loadUrl을 통해
웹페이지를 표시하려고 합니다.
그런데 암만 해봐도 잘 안되더군요.. 혹시 도와주시면 감사하겠습니다.
현재는 url을 보내도 기본으로 설정해둔 페이지만 뜨는 상태입니다.
------FirebaseMessagingService.class---------
public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {
private static final String TAG = "FirebaseMsgService";
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
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());
}
Log.d(TAG, "onMessageReceived DATA: "+ remoteMessage.getData().get("message"));
String url = remoteMessage.getData().get("url");
sendPushNotification(remoteMessage.getData().get("message"), url);
}
private void sendPushNotification(String message, String url) {
// String Title
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("url", url);
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, "default")
.setSmallIcon(R.drawable.artkorea_iconimage)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.artkorea_iconimage))
.setContentTitle("Push Title")
.setColor(Color.RED)
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setLights(000000255,500,2000)
.setContentIntent(pendingIntent);
// 알림 매니저
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// 오레오에서는 알림 채널을 매니저에 생성해야 한다
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
notificationManager.createNotificationChannel(new NotificationChannel("default", "기본 채널", NotificationManager.IMPORTANCE_DEFAULT));
}
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
}
------MainActivity.class 에서---------
public class MainActivity extends AppCompatActivity {
WebView mWebView;
private static String originalURL = "https://www.google.com/";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(MainActivity.this, "데이터를 불러오고 있습니다.",Toast.LENGTH_LONG).show();
mWebView = (WebView) findViewById(R.id.webView_mainActivity);
// ----글자수때문에 중략했습니다---
mWebView.loadUrl(originalURL);
Intent intent = getIntent();
if(intent.getStringExtra("url") != null) {
String targetURL = intent.getStringExtra("url");
Log.d("targetURL : ", targetURL);
Toast.makeText(MainActivity.this, "targetURL" + targetURL, Toast.LENGTH_SHORT).show();
mWebView.loadUrl(targetURL);
}
// FCM
FirebaseMessaging.getInstance().subscribeToTopic("notice");
}
}