Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static final int NOTIFY_ID = 101;//идентификатор уведомления
- static void openUrlNotify(final Context context, String title, String msg, String url)
- {
- Intent notificationIntent = new Intent(Intent.ACTION_VIEW,
- Uri.parse(url));
- PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
- notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
- Notification.Builder builder = new Notification.Builder(context);
- builder.setContentIntent(pendingIntent)
- .setSmallIcon(R.drawable.ic_delete)//иконка обязательна
- .setContentTitle(title)//заголовок
- .setContentText(msg) // Текст уведомления
- .setAutoCancel(true);
- Notification notification;
- if (Build.VERSION.SDK_INT <= 16) {
- notification = builder.getNotification(); // до API 16
- } else {
- notification = builder.build();// API выше
- }
- NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
- notificationManager.notify(NOTIFY_ID, notification);
- }
- //событие на кнопку
- public void onPush(View view) {
- Context context = getApplicationContext();
- openUrlNotify(context, "Перейти на сайт блеать", "жми", "https://www.google.ru/");
- //notificationManager.cancel(NOTIFY_ID);//если надо убить уведомление программно
- }
Advertisement
Add Comment
Please, Sign In to add comment