2016-11-18 136 views
0

我需要在通知上设置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()); 
    } 
} 

谢谢您的帮助

回答

1

我需要设置一个onclicklistener上的通知

这是不可能直接。

,这样我可以调用PHP文件,并从我的数据库获取数据,然后将其设置成由我通知intented活动

当用户点击您的通知,用户将被带到ActivityRestaurantHistoryReservations活动,使用您现有的代码。所以,无论是:

  • 把你的“调用PHP文件”及相关逻辑ActivityRestaurantHistoryReservations,或

  • 更改PendingIntent到别的东西,将执行这项工作,或

  • 添加一个单独的动作(addAction()),在通知中放入另一个按钮,并让其PendingIntent转到执行此项工作的其他任何项目(在这种情况下,只有在用户特意点击该动作按钮时才会执行此项工作)

+0

谢谢您unswer,我想试试。 –