bsod_keks

Untitled

Jan 9th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. private static final int NOTIFY_ID = 101;//идентификатор уведомления
  2.  
  3. static void openUrlNotify(final Context context, String title, String msg, String url)
  4.  
  5. {
  6.  
  7. Intent notificationIntent = new Intent(Intent.ACTION_VIEW,
  8.  
  9. Uri.parse(url));
  10.  
  11. PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
  12.  
  13. notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
  14.  
  15. Notification.Builder builder = new Notification.Builder(context);
  16.  
  17. builder.setContentIntent(pendingIntent)
  18.  
  19. .setSmallIcon(R.drawable.ic_delete)//иконка обязательна
  20.  
  21. .setContentTitle(title)//заголовок
  22.  
  23. .setContentText(msg) // Текст уведомления
  24.  
  25. .setAutoCancel(true);
  26.  
  27. Notification notification;
  28.  
  29. if (Build.VERSION.SDK_INT <= 16) {
  30.  
  31. notification = builder.getNotification(); // до API 16
  32.  
  33. } else {
  34.  
  35. notification = builder.build();// API выше
  36.  
  37. }
  38.  
  39. NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
  40.  
  41. notificationManager.notify(NOTIFY_ID, notification);
  42.  
  43. }
  44.  
  45.  
  46. //событие на кнопку
  47. public void onPush(View view) {
  48.  
  49. Context context = getApplicationContext();
  50.  
  51. openUrlNotify(context, "Перейти на сайт блеать", "жми", "https://www.google.ru/");
  52.  
  53. //notificationManager.cancel(NOTIFY_ID);//если надо убить уведомление программно
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment