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.
Related
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.
I am makin an android application on Emergency communication.I want my application should run all the time and whenever it needs it should be able to run.I want that user should not be able to close it by any means.Like Google Maps application which is restarted again on killing its all activities and even we force close it,it will be restarted.
Seems you are learning app development ... but this is not the way you should pose question here... you should post what you have done and code issues and not ask for an entire class...
But i will try to answer your question are you trying to create an app which when started wont be able to be closed and come back to home screen ???!!!!!
See you are creating an app which will run on android operating system which is similar to linux so you must follow the Activity
LifeCycle
I remember i created an app where there were shortcuts on screen so using that i was directing the user to specific links but you can use for calling etc.. i donno if that is what you are searching for...
You might create a notification bar if you want which cannot be cancelled and you can place the code in the intent which will be called from this...
Also services are there which u can utilized what other users have suggested...
thx
You could use an extra service running in the foreground, but there will be always a notification of this service in the notification bar.
See here: http://developer.android.com/guide/components/services.html#Foreground
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
I am a newbie on android apps development, I want to make a application which can lock any application when started. For eg if someone opens chrome or any other application it simply locks it.
Maybe you will not get any straight forward solution for that.you have to create a service that will run on the background.You can check periodically to find therunning process.Then you can find the package name for the process which you want to kill.Finally use killBackgroundProcess of the ActivityManager to kill the process.This method only kill background process.So if you want to stop browser that starts running simply send that in background(If you bring your activity in foreground it automatically will be back) and run the killBackgroundProcess(pkgName).
Android now allows users to add app widgets to the lock screen form API level 17, i dont know backward comparability supports or not
We want to use Android mobile for dedicated application. Can somebody suggest how can we make it happen.
Here are the requirement:
The phone when started, should launch our application., so the user cannot launch any other application. The application will be a 1D barcode reader.
The application should be live as long as the phone is up and running, user cannot close the application at all.
Thanks for your help.
Regards,
Manish
Android after boot is complete sends a bradcast intent:
android.intent.action.BOOT_COMPLETED
if you listen for this intent, you can launch a service that in turn launch your activity.
In the Activity you have to take care of the user's interactions that explicitly close the activity, like home button, back button and camera button press.
Setting your activity to be full-screen also should prevent the user to use the notification bar to interact with notification like those from market-app that can close your activity.
Finally, your activity can be killed by the system by various and uncatchable reasons: in those cases, the service that first launched your Activity comes in handy, as it can periodically monitor the general state of the application and relaunch components as needed.
Check out the new Android Enterprise solutions for your use case.
https://developers.google.com/android/work/overview
Its well documented. You can either use
Android Management API to provision the devices and apply policies to the device which will be applied to the device using Android's Device Policy Controller (DPC) or,
Use Google Play EMM API and develop your custom DPC
It depends upon your use-case really, but the first solution set should serve your purpose
I'm afraid there's no single answer to this, but you need to work on multiple fronts.
One of these fronts is preventing user from running other applications: for this there are applications sold on Android Market that can put other apps of your choosing behind passcode.
You need to combine this with automatic launch, but I don't yet know how to do that.