2
I fixed my app to work in the background with android 8 however many customers came to uninstall the application because of the permanent notification "App is running in background". I need my Intent Service running every x period without the notification appearing to the user.
In my Service I have the following code
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.e("InBackground", "Serviço em background iniciado");
Intent newIntent = new Intent(getBaseContext(),Service.class);
newIntent.putExtra("comando","AtualizaInBackground");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String CHANNEL_ID = "my_channel_01";
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "Atualizações em Background.", NotificationManager.IMPORTANCE_NONE);
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(channel);
Notification notification = new NotificationCompat.Builder(getBaseContext(), CHANNEL_ID)
.setContentTitle("")
.setContentText("").build();
startForeground(1, notification);
}
startService(newIntent);
return START_STICKY;
}
This might help https://answall.com/a/299957/2541
– ramaral