2016-11-18 51 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,我想試試。 –