How to monitor SIM state change

The Intent android.intent.action.SIM_STATE_CHANGED is broadcast when the SIM state changes. For example, on my HTC Desire with a T-Mobile SIM card, if I put the device into flight mode the following Intent is broadcast: Intent: android.intent.action.SIM_STATE_CHANGED with extras: ss = NOT_READY, reason = null If I then take it out of flight mode, the following … Read more

The process of the service is killed after the application is removed from the application tray

Here is a workaround I came across and works well for re-starting a service if its process is killed on closing the application. In your service, add the following code. I came across this workaround in this thread. @Override public void onTaskRemoved(Intent rootIntent){ Intent restartServiceIntent = new Intent(getApplicationContext(), this.getClass()); restartServiceIntent.setPackage(getPackageName()); PendingIntent restartServicePendingIntent = PendingIntent.getService(getApplicationContext(), 1, … Read more

Permission Denial: startForeground requires android.permission.FOREGROUND_SERVICE

This will happen if you have set targetSdkVersion = 28 (Android 9 / Pie) or above and have not declared the usage of the FOREGROUND_SERVICE permission. From the migration notes for Android 9: Apps wanting to use foreground services must now request the FOREGROUND_SERVICE permission first. This is a normal permission, so the system automatically … Read more

How to run an android app in background?

You can probably start a Service here if you want your Application to run in Background. This is what Service in Android are used for – running in background and doing longtime operations. UDPATE You can use START_STICKY to make your Service running continuously. @Override public int onStartCommand(Intent intent, int flags, int startId) { handleCommand(intent); … Read more

Android RuntimeException: Unable to instantiate the service

In your concrete implementation you have to declare a default constructor which calls the public IntentService (String name) super constructor of the abstract IntentService class you extend: public MyService () { super(“MyServerOrWhatever”); } You do not need to overwrite onStartCommand if the super implementation fits for you (what I expect). In your current case you … Read more

How to simulate touch from background service with sendevent or other way?

I can’t execute the “sendevent” command, but found another way for myself, hope it will be helpfull for somebody. For simulate touch I used sendPointerSync() from android.app.Instrumentation, that work only with “android.permission.INJECT_EVENTS” permission. For use it you should compile your app as a system app. To do it you should follow next steps: Getting files … Read more

Launch Android application without main Activity and start Service on launching application

You said you didn’t want to use a translucent Activity, but that seems to be the best way to do this: In your Manifest, set the Activity theme to Theme.Translucent.NoTitleBar. Don’t bother with a layout for your Activity, and don’t call setContentView(). In your Activity’s onCreate(), start your Service with startService(). Exit the Activity with … Read more