How to set click listener for notification?

后端 未结 3 1065
别那么骄傲
别那么骄傲 2020-12-01 09:06

I am using the following code to launch a notification when a Service is started Via AlarmManager:

nm = (NotificationManager) this.getSystemService(Context.N         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 10:02

    As for yoshi24's comment, you may be able to set extras like this.

    final Intent intent = new Intent(this, MyActivity.class);
    intent.setData(data);
    intent.putExtra("key", "value");
    final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
    

    You need to be aware of this as well before going for pending intents

    https://stackoverflow.com/questions/1198558/how-to-send-parameters-from-a-notification-click-to-an-activity

    UPDATE some thing like this will work for you

    int your mainfest

    
    

    in your activity

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        processIntent(getIntent());
    }
    
    @Override
    protected void onNewIntent(Intent intent) {     
        processIntent(intent);
    };
    
    private void processIntent(Intent intent){
        //get your extras
    }
    

提交回复
热议问题