Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. @Override
  2. protected void onDestroy() {
  3.  
  4. NotificationManager notificationManager = ((NotificationManager)getSystemService( Context.NOTIFICATION_SERVICE));
  5. notificationManager.cancelAll();
  6.  
  7. super.onDestroy();
  8. }
  9.  
  10. public class Notificacion extends Service {
  11. public Notificacion() {
  12. }
  13.  
  14. @Override
  15. public IBinder onBind(Intent intent) {
  16. // TODO: Return the communication channel to the service.
  17. throw new UnsupportedOperationException( "Not yet implemented" );
  18. }
  19.  
  20. private PendingIntent pendingIntent;
  21. private final static String CHANNEL_ID = "NOTIFICACION";
  22. private final static int NOTIFICACION_ID = 0;
  23. private Resources mResources;
  24.  
  25. @Override
  26. public void onCreate() {
  27. super.onCreate();
  28.  
  29. createNotificationChannel();
  30. createNotification();
  31.  
  32. mResources = getResources();
  33.  
  34. }
  35.  
  36. private void createNotificationChannel(){
  37. if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
  38. CharSequence name = "Noticacion";
  39. NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, name, NotificationManager.IMPORTANCE_HIGH);
  40. NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
  41. notificationManager.createNotificationChannel(notificationChannel);
  42. }
  43. }
  44.  
  45. private void createNotification(){
  46. NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID);
  47.  
  48. Intent resultIntent = new Intent(this, MainActivity.class);
  49. PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 1, resultIntent, PendingIntent.FLAG_ONE_SHOT);
  50.  
  51. builder.setSmallIcon(R.drawable.logo);
  52. builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.logo));
  53. builder.setContentTitle("Notificacion Android");
  54. builder.setContentText("ESTA ES MI APP");
  55. builder.setColor( Color.WHITE);
  56. builder.setPriority(NotificationCompat.PRIORITY_HIGH);
  57. builder.setDefaults( Notification.DEFAULT_SOUND);
  58. builder.setContentIntent(resultPendingIntent);
  59.  
  60.  
  61. NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext());
  62. notificationManagerCompat.notify(NOTIFICACION_ID, builder.build());
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement