int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); Notification noti = new Notification(icon, contentTitle, when); noti.flags |= flag; PackageManager pm = context.getPackageManager(); Intent notificationIntent = pm.getLaunchIntentForPackage(context.getPackageName()); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); notificationIntent.putExtra("notificationTag", tag); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); noti.setLatestEventInfo(context, contentTitle, contentText, contentIntent); 上面的方法解决不了 notificationIntent.setAction(Intent.ACTION_MAIN); notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER); 这样就可以了
时间: 2024-10-16 17:04:04