|
package varunon9.me.dynamicwallpaper; |
|
|
|
import android.app.Notification; |
|
import android.app.NotificationChannel; |
|
import android.app.NotificationManager; |
|
import android.app.PendingIntent; |
|
import android.app.Service; |
|
import android.content.Intent; |
|
import android.os.Build; |
|
import android.os.IBinder; |
|
import android.util.Log; |
|
|
|
import androidx.core.app.NotificationCompat; |
|
|
|
public class MyService extends Service { |
|
private String TAG = "MyService"; |
|
public static boolean isServiceRunning; |
|
private String CHANNEL_ID = "NOTIFICATION_CHANNEL"; |
|
|
|
public MyService() { |
|
Log.d(TAG, "constructor called"); |
|
isServiceRunning = false; |
|
} |
|
|
|
@Override |
|
public void onCreate() { |
|
super.onCreate(); |
|
Log.d(TAG, "onCreate called"); |
|
createNotificationChannel(); |
|
isServiceRunning = true; |
|
} |
|
|
|
@Override |
|
public IBinder onBind(Intent intent) { |
|
return null; |
|
} |
|
|
|
@Override |
|
public int onStartCommand(Intent intent, int flags, int startId) { |
|
Log.d(TAG, "onStartCommand called"); |
|
Intent notificationIntent = new Intent(this, MainActivity.class); |
|
PendingIntent pendingIntent = PendingIntent.getActivity(this, |
|
0, notificationIntent, 0); |
|
Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID) |
|
.setContentTitle("Service is Running") |
|
.setContentText("Listening for Screen Off/On events") |
|
.setSmallIcon(R.drawable.ic_wallpaper_black_24dp) |
|
.setContentIntent(pendingIntent) |
|
.setColor(getResources().getColor(R.color.colorPrimary)) |
|
.build(); |
|
|
|
startForeground(1, notification); |
|
return START_STICKY; |
|
} |
|
|
|
private void createNotificationChannel() { |
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
|
String appName = getString(R.string.app_name); |
|
NotificationChannel serviceChannel = new NotificationChannel( |
|
CHANNEL_ID, |
|
appName, |
|
NotificationManager.IMPORTANCE_DEFAULT |
|
); |
|
NotificationManager manager = getSystemService(NotificationManager.class); |
|
manager.createNotificationChannel(serviceChannel); |
|
} |
|
} |
|
|
|
@Override |
|
public void onDestroy() { |
|
Log.d(TAG, "onDestroy called"); |
|
isServiceRunning = false; |
|
stopForeground(true); |
|
|
|
// call MyReceiver which will restart this service via a worker |
|
Intent broadcastIntent = new Intent(this, MyReceiver.class); |
|
sendBroadcast(broadcastIntent); |
|
|
|
super.onDestroy(); |
|
} |
|
} |
The fact that it will appear again in a few seconds after being killed can indicate that is using Android Alarm Manager that executes periodically and checks if it needs to be relaunched. I do something similar but I'm not sure that the application that you mentioned is doing that after seeing his Android Manifest file.
You can see here the second service has an intent filter related with Firebase, so maybe it is restarted via FCM.