31 private static final String CHANNEL_ID =
"rdp_print";
32 private static final String AUTHORITY =
"com.freerdp.afreerdp.fileprovider";
33 private static final AtomicInteger notifId =
new AtomicInteger(1000);
35 public static void ensureChannel(Context ctx)
37 NotificationManager nm = ctx.getSystemService(NotificationManager.class);
38 if (nm.getNotificationChannel(CHANNEL_ID) !=
null)
40 NotificationChannel ch =
41 new NotificationChannel(CHANNEL_ID, ctx.getString(R.string.print_notif_channel),
42 NotificationManager.IMPORTANCE_HIGH);
43 nm.createNotificationChannel(ch);
46 public static void notify(Context ctx, File pdfFile)
50 Uri uri = FileProvider.getUriForFile(ctx, AUTHORITY, pdfFile);
52 PendingIntent openIntent = PendingIntent.getActivity(
54 new Intent(Intent.ACTION_VIEW)
55 .setDataAndType(uri,
"application/pdf")
56 .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION),
57 PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
60 printLaunch.setData(uri);
61 printLaunch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION);
62 PendingIntent printIntent = PendingIntent.getActivity(
63 ctx, notifId.get() + 1, printLaunch,
64 PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
66 Notification notif =
new NotificationCompat.Builder(ctx, CHANNEL_ID)
67 .setSmallIcon(android.R.drawable.ic_dialog_info)
68 .setContentTitle(ctx.getString(R.string.print_notif_title))
69 .setContentText(pdfFile.getName())
70 .setContentIntent(openIntent)
71 .addAction(android.R.drawable.ic_menu_view,
72 ctx.getString(R.string.print_notif_open), openIntent)
73 .addAction(android.R.drawable.ic_menu_send,
74 ctx.getString(R.string.print_notif_print), printIntent)
78 NotificationManager nm =
79 (NotificationManager)ctx.getSystemService(Context.NOTIFICATION_SERVICE);
80 nm.notify(notifId.getAndIncrement(), notif);