1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| Intent it = new Intent(context, MemoListActivity.class); PendingIntent pi = PendingIntent.getActivity(context, 0, it, PendingIntent.FLAG_CANCEL_CURRENT); Resources res = context.getResources(); Bitmap bmp = BitmapFactory.decodeResource(res, R.mipmap.ic_launcher); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "你的渠道id"); builder.setContentTitle("备忘录通知") .setSmallIcon(R.mipmap.ic_launcher) .setLargeIcon(bmp) .setContentText(content + "") .setTicker("备忘录通知") .setSound(Uri.parse("android.resource://您的包名/" + R.raw.hint)) .setVibrate(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400}) .setAutoCancel(true) .setContentIntent(pi);
if (notificationManager != null) { notificationManager.notify(1, builder.build()); }
|