我已在我的Android應用中實施Firebase通知。當我的應用程序正在運行時,通知將與我的自定義佈局一起顯示,但是當應用程序未運行時,通知將以默認佈局顯示。當應用程序未運行時,如何將通知佈局更改爲我的佈局。此外,我存儲共享首選項以讓用戶切換通知。但是,當應用程序沒有運行時,通知顯示無論如何。怎樣才能做到這一點?應用關閉時的Firebase通知
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if(SettingsFragment.getReceiceNotification()){ //if user wants to receive notification
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
RemoteViews remoteViews = new RemoteViews(getPackageName(),R.layout.push_notification_layout);
remoteViews.setImageViewResource(R.id.push_notif_icon,R.mipmap.ic_bird_black);
Intent intent = new Intent(this,MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder.setContent(remoteViews);
notificationBuilder.setContentTitle("Radyo Türkkuşu");
notificationBuilder.setContentText(remoteMessage.getNotification().getBody());
notificationBuilder.setAutoCancel(true);
notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
notificationBuilder.setContentIntent(pendingIntent);
remoteViews.setTextViewText(R.id.push_title, "Radyo Türkkuşu");
remoteViews.setTextViewText(R.id.push_context, remoteMessage.getNotification().getBody());
//notificationBuilder.setLights (ContextCompat.getColor(MainActivity.context, R.color.pushColor), 5000, 5000);
notificationManager.notify(0,notificationBuilder.build());
}
}
你的代碼在哪裏? –
我在詢問技術資料,不想執行 – orkun
請檢查我的答案先生。 –