Open application after clicking on Notification

后端 未结 11 2113
南笙
南笙 2020-11-22 13:52

I have a notification in my app with the following code:

//Notification Start

   notificationManager = (NotificationManager) getSystemService(Context.NOTIFI         


        
11条回答
  •  执念已碎
    2020-11-22 14:40

    Use my example...

     public void createNotification() {
            NotificationManager notificationManager = (NotificationManager) 
                  getSystemService(NOTIFICATION_SERVICE);
            Notification notification = new Notification(R.drawable.icon,
                "message", System.currentTimeMillis());
            // Hide the notification after its selected
            notification.flags |= Notification.FLAG_AUTO_CANCEL;
            Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
            long[] pattern = { 0, 100, 600, 100, 700};
            vibrator.vibrate(pattern, -1);
         Intent intent = new Intent(this, Main.class);
         PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 0);
         String sms = getSharedPreferences("SMSPREF", MODE_PRIVATE).getString("incoming", "EMPTY");
            notification.setLatestEventInfo(this, "message" ,
                sms, activity);
            notification.number += 1;
            notificationManager.notify(0, notification);
    
          }
    

提交回复
热议问题