首页 > 解决方案 > 杀死我的应用程序后广播接收器不起作用

问题描述

{
  public void CustomNotification() {
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.layout_reminder_notification);
    Intent intent = new Intent(context, HomeActivity.class);
    intent.putExtra("notification", "reminder");
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    createNotificationChannel();
    PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
       .setSmallIcon(R.mipmap.ic_pzizz)
       .setTicker(context.getString(R.string.about))
       .setTimeoutAfter(3000)
       .setContentIntent(pIntent)
       .setContent(remoteViews)
       .setAutoCancel(true);

   remoteViews.setTextViewText(R.id.txtTitle, sharedPreferencesHelper.getReminderNotificationName());
   NotificationManager notificationmanager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
   notificationmanager.notify(0, builder.build());
 }

 private void createNotificationChannel() {
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
      @SuppressLint("WrongConstant") 
      NotificationChannel serviceChannel = new NotificationChannel(
          CHANNEL_ID,
          context.getString(R.string.app_name),
          NotificationManager.IMPORTANCE_DEFAULT
      );
      serviceChannel.setSound(null, null);
      manager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
      manager.createNotificationChannel(serviceChannel);
   }
 }
}

标签: java

解决方案


推荐阅读