如何在通知上设置onclicklistener android
我需要在通知上设置onclicklistener,以便我可以调用PHP文件并从我的数据库获取数据,然后将其设置为我的通知所打算的活动,你能给我一些线索吗?
我抬头看着其他问题,但我真的不明白如何做到这一点。 这里是我的代码时,我设置了通知:如何在通知上设置onclicklistener android
public class FirebaseMessagingService extends
com.google.firebase.messaging.FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
showNotification(remoteMessage.getData().get("message"));
}
private void showNotification(String message) {
Intent i = new Intent(this, ActivityRestaurantHistoryReservations.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setContentTitle("You have a new reservation !")
.setContentText(message)
.setSmallIcon(R.drawable.common_google_signin_btn_icon_dark)
.setContentIntent(pendingIntent);
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(0, builder.build());
}
}
谢谢您的帮助
我需要设置一个onclicklistener上的通知
这是不可能直接。
,这样我可以调用PHP文件,并从我的数据库获取数据,然后将其设置成由我通知intented活动
当用户点击您的通知,用户将被带到ActivityRestaurantHistoryReservations
活动,使用您现有的代码。所以,无论是:
把你的“调用PHP文件”及相关逻辑
ActivityRestaurantHistoryReservations
,或更改
PendingIntent
到别的东西,将执行这项工作,或添加一个单独的动作(
addAction()
),在通知中放入另一个按钮,并让其PendingIntent
转到执行此项工作的其他任何项目(在这种情况下,只有在用户特意点击该动作按钮时才会执行此项工作)
我建议你检查这Add list item in RecyclerView Adapter on receiving Firebase message文章搞明白如何从FirebaseMessagingService
数据发送到Activity
谢谢你的帮助! –
谢谢您unswer,我想试试。 –