Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. @Override
  2. public int onStartCommand(Intent intent, int flags, int startId) {
  3.  
  4.  
  5. Log.e("InBackground", "Serviço em background iniciado");
  6.  
  7. Intent newIntent = new Intent(getBaseContext(),Service.class);
  8. newIntent.putExtra("comando","AtualizaInBackground");
  9.  
  10. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  11. String CHANNEL_ID = "my_channel_01";
  12.  
  13. NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "Atualizações em Background.", NotificationManager.IMPORTANCE_NONE);
  14.  
  15. ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(channel);
  16.  
  17. Notification notification = new NotificationCompat.Builder(getBaseContext(), CHANNEL_ID)
  18. .setContentTitle("")
  19. .setContentText("").build();
  20. startForeground(1, notification);
  21. }
  22. startService(newIntent);
  23.  
  24.  
  25. return START_STICKY;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement