我希望 Android 專家知道如何幫助我。我正在使用推送通知(我使用 FCM 服務從郵遞員發送它們),重點是當應用程式在后臺時一切正常(我的意思是它們顯示正確并重定向到我想要的頁面),但是當應用程式處于前臺時,它們看起來很棒,但是當您觸摸它們時,它們完全沒有任何作用。我對 Android Studio 很陌生,因為它是一個作業專案,我一直在學習,非常感謝任何幫助或解釋。我在下面向您展示了一些我的代碼。
當應用程式處于后臺時,這可以正常作業
這會在應用程式處于前臺時向我顯示通知,但是當我單擊時它什么也不做
編輯:實際代碼
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.d("msg", "onMessageReceived: " remoteMessage.getData().get("message"));
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
String channelId = "Default";
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(remoteMessage.getNotification().getBody()).setAutoCancel(true).setContentIntent(pendingIntent);;
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId, "Default channel", NotificationManager.IMPORTANCE_DEFAULT);
manager.createNotificationChannel(channel);
}
manager.notify(23, builder.build());
}
}
但是我認為問題的一部分來自這個代碼塊從未執行過的事實,但奇怪的是執行了 pushNotificationActionPerformed 偵聽器
不作業:
PushNotifications.addListener(
'pushNotificationReceived',
(notification: PushNotificationSchema) => {
alert('Llegó una notificación!!!');
if (notification && Capacitor.getPlatform() === 'android') {
this.createLocalNotification(notification);
}
}
);
作業:
PushNotifications.addListener(
'pushNotificationActionPerformed',
(notification: ActionPerformed) => {
alert('Llegó una notificación!!!');
const data = notification.notification.data;
if (data.ticket) {
const ticketParsed = JSON.parse(data.ticket);
this.store.dispatch(new StoreSelectedTicket(ticketParsed));
this.router.navigate(['/support/ticket-status']);
}
if (data.statement) {
const parsedStatement = JSON.parse(data.statement);
this.downloadStatements(parsedStatement.link);
}
if (data.deposit) {
const parsedDeposit = JSON.parse(data.deposit);
this.store.dispatch(new StoreSelectedDeposit(parsedDeposit));
this.router.navigate(['/deposits/daily-detail/detail-by-reference-number']);
}
}
);
}
uj5u.com熱心網友回復:
我想可能有以下原因:
首先,在待定意圖中傳遞的意圖示志必須是Intent.FLAG_ACTIVITY_NEW_TASK或Intent.FLAG_ACTIVITY_CLEAR_TASK
其次,如果您不需要特定的東西,則pendingIntent可以使用最后一個引數。0FLAG_ONE_SHOT
第三,使用非零唯一整數 manager.notify(non-zero-integer,builder.build)
您可以在官方檔案中查看更多資訊
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/312547.html
上一篇:離子反應閃屏顯示兩次與電容器
