Android: Click event for Status bar notification

前端 未结 2 1114
春和景丽
春和景丽 2021-02-07 17:38

I\'ve got the following code to create a status bar notification:

public void txtNotification(int id, String msg){
    NotificationManager manager = (Notificatio         


        
2条回答
  •  太阳男子
    2021-02-07 18:35

    For dummies like myself: Getting this yourpackage.notifyId at MainActivity:

        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            Bundle intent_extras = getIntent().getExtras();
            if (intent_extras != null && intent_extras.containsKey("yourpackage.notifyId"))
            {
              //Do the codes
            }
    
    }
    

    In my case - used it to determine who is opening my mainactivity, user or a call from notification, cteated by GcmIntentService... P.S. I've used names without "youpackage", works fine too.

提交回复
热议问题