Open application after clicking on Notification

后端 未结 11 2122
南笙
南笙 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:46

    Use below code for create notification for open activity. It works for me. For full code

     Intent myIntent = new Intent(context, DoSomething.class);
     PendingIntent pendingIntent = PendingIntent.getActivity(
            context, 
            0, 
            myIntent, 
            Intent.FLAG_ACTIVITY_NEW_TASK);
    
     myNotification = new NotificationCompat.Builder(context)
       .setContentTitle("Exercise of Notification!")
       .setContentText("Do Something...")
       .setTicker("Notification!")
       .setWhen(System.currentTimeMillis())
       .setContentIntent(pendingIntent)
       .setDefaults(Notification.DEFAULT_SOUND)
       .setAutoCancel(true)
       .setSmallIcon(R.drawable.ic_launcher)
       .build();
    
     notificationManager = 
       (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
     notificationManager.notify(MY_NOTIFICATION_ID, myNotification);
    

提交回复
热议问题