Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- protected void onDestroy() {
- NotificationManager notificationManager = ((NotificationManager)getSystemService( Context.NOTIFICATION_SERVICE));
- notificationManager.cancelAll();
- super.onDestroy();
- }
- public class Notificacion extends Service {
- public Notificacion() {
- }
- @Override
- public IBinder onBind(Intent intent) {
- // TODO: Return the communication channel to the service.
- throw new UnsupportedOperationException( "Not yet implemented" );
- }
- private PendingIntent pendingIntent;
- private final static String CHANNEL_ID = "NOTIFICACION";
- private final static int NOTIFICACION_ID = 0;
- private Resources mResources;
- @Override
- public void onCreate() {
- super.onCreate();
- createNotificationChannel();
- createNotification();
- mResources = getResources();
- }
- private void createNotificationChannel(){
- if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
- CharSequence name = "Noticacion";
- NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, name, NotificationManager.IMPORTANCE_HIGH);
- NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
- notificationManager.createNotificationChannel(notificationChannel);
- }
- }
- private void createNotification(){
- NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID);
- Intent resultIntent = new Intent(this, MainActivity.class);
- PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 1, resultIntent, PendingIntent.FLAG_ONE_SHOT);
- builder.setSmallIcon(R.drawable.logo);
- builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.logo));
- builder.setContentTitle("Notificacion Android");
- builder.setContentText("ESTA ES MI APP");
- builder.setColor( Color.WHITE);
- builder.setPriority(NotificationCompat.PRIORITY_HIGH);
- builder.setDefaults( Notification.DEFAULT_SOUND);
- builder.setContentIntent(resultPendingIntent);
- NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext());
- notificationManagerCompat.notify(NOTIFICACION_ID, builder.build());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement