show activity after notification Android

后端 未结 1 1234
无人共我
无人共我 2020-12-22 03:13

I´m trying to open an activity after recieiving a PUSH notification.

I recieive the notification, but when i select it nothing happens!

The problem trace is:

相关标签:
1条回答
  • 2020-12-22 03:54

    Implement this :

    private void generateNotification(Context context, String message) {
    
    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    String appname = context.getResources().getString(R.string.app_name);
    NotificationManager notificationManager = (NotificationManager) context
    .getSystemService(Context.NOTIFICATION_SERVICE);
    
    Notification notification;
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
    new Intent(context, myactivity.class), 0);
    
    
     NotificationCompat.Builder builder = new NotificationCompat.Builder(
     context);
     notification = builder.setContentIntent(contentIntent)
     .setSmallIcon(icon).setTicker(appname).setWhen(0)
     .setAutoCancel(true).setContentTitle(appname)
     .setContentText(message).build();
    
     notificationManager.notify(0 , notification);
    
      }
    
    0 讨论(0)
提交回复
热议问题