32 private static final String CHANNEL_ID =
"rdp_print";
33 private static final AtomicInteger notifId =
new AtomicInteger(1000);
35 public static void ensureChannel(Context ctx)
37 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
39 NotificationManager nm = ctx.getSystemService(NotificationManager.class);
40 if (nm.getNotificationChannel(CHANNEL_ID) !=
null)
42 NotificationChannel ch =
43 new NotificationChannel(CHANNEL_ID, ctx.getString(R.string.print_notif_channel),
44 NotificationManager.IMPORTANCE_HIGH);
45 nm.createNotificationChannel(ch);
48 public static void notify(Context ctx, File pdfFile)
52 Uri uri = FileProvider.getUriForFile(ctx, ctx.getPackageName() +
".fileprovider", pdfFile);
54 PendingIntent openIntent = PendingIntent.getActivity(
56 new Intent(Intent.ACTION_VIEW)
57 .setDataAndType(uri,
"application/pdf")
58 .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION),
59 PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
62 printLaunch.setData(uri);
63 printLaunch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION);
64 PendingIntent printIntent = PendingIntent.getActivity(
65 ctx, notifId.get() + 1, printLaunch,
66 PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
68 Notification notif =
new NotificationCompat.Builder(ctx, CHANNEL_ID)
69 .setSmallIcon(android.R.drawable.ic_dialog_info)
70 .setContentTitle(ctx.getString(R.string.print_notif_title))
71 .setContentText(pdfFile.getName())
72 .setContentIntent(openIntent)
73 .addAction(android.R.drawable.ic_menu_view,
74 ctx.getString(R.string.print_notif_open), openIntent)
75 .addAction(android.R.drawable.ic_menu_send,
76 ctx.getString(R.string.print_notif_print), printIntent)
80 NotificationManager nm =
81 (NotificationManager)ctx.getSystemService(Context.NOTIFICATION_SERVICE);
82 nm.notify(notifId.getAndIncrement(), notif);