Start Service on boot without activity (but with root) - android

I want to create an app only for my phone, that runs all the time in background - and you should never stop that service from running.
My goal is, that this app is sending the current location data to my computer at home - to get it back, when it has been stolen for example, or when I lost it.
The problem is, that it is not possible to start a service without having an activity and/or launcher icon (because the thief should not know this).
But: My phone is rooted, so is it possible to start the service anyway?
And also: When I place my APK into the /system/app partition, will the APK persist after doing a factory reset?

Yes, you can. Rooting your phone doesn't matter for what you want to do, and if anyone tried to factory reset your phone, your app will still not be deleted, if you put your apk in /system/app partition as you said. It will react as if it was a normal system app. But of course, you must also set the correct permissions for your app when moving it to the system folder to be able to work.
And to prevent the thief from knowing your app, you can just name your app with an ambiguous name and without an icon that describes what your app does, because your app will still be visible in your application manager from your phone settings. Along with that, you can do the following:
To create an app that does not have an icon in the Home Launcher, just remove the intent filter android.intent.category.LAUNCHER of your activity from the AppManifest.xml.
To implement your background application, it strongly depends on what you want to do. You can create a Service for long running tasks, BroadcastReceiver to react to specific events or activities with intent filters.
Edit:
In order to let your app work automatically, you must put your app in this folder /system/priv-app. This way, your app will be started everytime you boot your device.

Related

I need to prevent users from altering settings of my app

I want to prevent users altering settings of my app by throwing up a splash screen to block interactions whenever they go into the device settings and open the settings page for my app.
Here's a video of another app that does this: https://inversatechnosoft.com/wp-content/uploads/2021/03/WhatsApp-Video-2021-03-05-at-7.40.24-AM.mp4
This isn't possible (at least for apps that aren't part of the system image), for good reason: that's the sort of thing malware does to take over a system.
Even if you could do that, that isn't sufficient: an app could also be uninstalled from the launcher, or other apps. You could make it harder through various tricks, but ultimately the user could simply reboot the device into safe mode and do it there.
The only cases where you could have this level of control are managed devices or within a work profile.
I don't think there is an incredibly clean way to do this, but you could start a service which regularly checks the foreground task.
You can then use the ActivityManager to get a list of all running app processes with ActivityManager.getRunningAppProcesses() and then check their importance against IMPORTANCE_FOREGROUND.

Android: launch any activity to start in the background?

If I'm writing my own Android app, I know how to structure it as a Service so it will start running in the background.
However, is there a way to launch an existing app (for example, any random .apk from the Play Store) so that it starts up in the background, without its screen taking over the display?
Alternatively, I'd be willing to launch the app, force it into the background, and redisplay the window of the previous app (whatever it might have been) that was running in the foreground. I don't know how to programmatically put the current app in the background and then determine the previous app and bring it back to the foreground.
I'm willing to do this any way possible: via Java, via one or more command-line utilities, via a Tasker plugin, via an Xposed module, or whatever.
Thank you in advance for any pointers to docs or any suggestions.
I discovered that the #0 entry of "dumpsys activity recents" gives the currently displayed activity ... at least on my rooted Marshmallow device. This gives me what I need.

Can I install an app from an other app and then launch its intent immediately when opening it?

Background: I have an app which needs to use an intent from an other app. If this other app is not installed when its intent is needed, I would like to offer it for download and install.
Question: If the downloaded app is opened (by the user) immediately after installing it, I would need it to open the specific intent the first app needs instead of opening it as normal. See image below.
What options do I have available, is there a common pattern for this? Thanks in advance.
If the downloaded app is opened (by the user) immediately after installing it, I would need it to open the specific intent the first app needs instead of opening it as normal.
That is not possible, strictly speaking. There is nothing stopping the user from pressing Open, and that will behave as normal -- you cannot change this.
If you are the author of the, um, "Monkey Trampoline" app, you could work out various hacks to recognize that it is being opened after an install from, um, "Animal Olympics", so it can route its logic accordingly (use a custom sticky broadcast, have the second app use some IPC to ask the first app "yo, am I supposed to do something special?", etc.).
It is also conceivable that ACTION_PACKAGE_ADDED will be broadcast before the user clicks either Done or Open (or HOME or BACK or whatever). In that case, you could listen for that broadcast, determine that, indeed, the app just installed does involve simian somersaults, and call startActivity(). This will be a bit jarring for the user, insofar as all of a sudden they'd be transported from the install process into this new app. And, since the precise timing of ACTION_PACKAGE_ADDED is undocumented, your mileage may vary (e.g., the user could still get a chance to tap Open before the broadcast winds its way to your app).

How to prevent launching other application from my application

I want to write an application that can prevent some application from launching. My requirement is to block some application for some period. So what is the way to block or prevent others application from starting or launching through my application.
My question is -- Is it possible to prevent launching other application from my application? If yes then what is the way.
I tried killing the running application. But it only kills when the application is in the background. When the application is in opened state(displayed on the screen) the killing of the application is not working.
So what is the way to block or prevent others application from starting or launching through my application.
Write your own home screen, so you are the one doing the launching, and implement your launching rules there.
This will cover basic scenarios. It will not help with:
Stopping apps that are launched via notifications (e.g., in response to an incoming SMS)
Stopping apps that are launched via other things in the system bar on tablets (e.g., some tablets let you get to the Settings app from there)
Stopping the user from rebooting their device in safe mode and getting rid of your home screen
The only way to handle those scenarios is to create your own ROM mod with adjustments to the operating system, then distribute that ROM mod (e.g., on your own devices).

Android: Prevent users from launching apps or using the OS

Is it possible to have an application run on a device in such a way that it is the only application that can ever run and also prevent the user from using the operating system at all? Tapping on the Home key or Back button would not exit the application and allow the user to have access to anything. If the device boots up, only this application would run.
This would be desirable in situations where devices are installed at a business for point of sales purpose or possibly where the device acts like a terminal in public places.
You can achieve what you're describing by writing your app to replace the home screen (Launcher). From there, you control what other apps will run.
The Android SDK has a working Launcher project you can start from.
Be careful to allow some method of running a more powerful app (even if it's just enabling ADB access) -- otherwise you could leave your device in a state of needing a factory reset before it can be modified.
Yes, you can override the back and home button behaviour.
Start app, override all buttons, and the user cant exit the app, evil, but should work in your scenario.
info here

Categories

Resources