When android device power on, is it possible to load one specific application without launching home screen?
How to make this change?
Where to change code
Setting permission as boot_completed works but before my application is loaded, the homescreen is shown for 5 seconds. How to disable android from showing any homescreen launcher before my application
This mode is called kiosk mode, and android has provision for running devices in Kiosk mode, you can refer to this guide for the complete set up. Basically what you do is set up your app to listen to the RECEIVE_BOOT_COMPLETED broadcast and disable all actions such as back button home button minimize buttons etc. Also don't forget to set up an exit mechanism. Just follow the guide and you should be fine.
In your manifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
And add Intent filter:
<receiver android:name=".BootReciever">
<intent-filter >
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
And then Now you can start your application's first activity from onReceive method of Receiver class:
https://stackoverflow.com/questions/10428510/how-to-start-launch-application-at-boot-time-android
For more information you can check this url How to start/ launch application at boot time Android
if your device has been rooted, uninstall system applications on your device, but be careful that every app can not be uninstalled. install "Root-Uninstaller-Pro-8.3" app and do this. you must uninstall important system apps one by one and any time restart your device to see result until Achieve goal. if you uninstall an app that make your device Messed up, you should flash your device to restore apps and retry uninstallations. by this uninstallations, your boot time become too short and that 5 second will be disappear. good luck!
Related
Tested on Pixel 3a (both emulator and physical device (my used device)) API 30 (11.0).
Repo:
https://github.com/amdreallyfast/AndroidStartOnBootExample
Goal:
I'm trying to launch an android app on startup, but failing.
Note: I am well aware that this should not be done for apps designed for the general public. This is not that. At the moment, this is just concept exploration for a personal project. The larger goal is to tinker with a used Pixel 3a and turn it into a home utility device. I don't want to start the app manually every time I need to turn it on and would rather have it starting automatically, so I'm trying to find a way to launch the app at startup.
Also Note: Because this is a project to start on boot, I can't use the debugger for most of this and have to rely on notifications instead to detect progress.
Progress:
I've got a BroadcastReceiver that responds to the BOOT_COMPLETED intent by launching a Service. The service's onCreate(...) function creates a simple intent to start another app (at the moment, just Google Maps, which is readily available without additional software installation).
I've also got MainActivity, a simple program that has a button that uses an intent to launch the same Service. I use this to compare behavior between starting the service at startup and starting the service from an already-running activity.
Already tried setting the intent flag Intent.FLAG_ACTIVITY_NEW_TASK.
Problem:
Google Maps does not launch from the service when called during startup. I know that the service's code is correctly set up to launch the map intent because launching the MainActivity and pressing the button will launch the service and then start Google Maps just fine. I also know that the code running on startup got through to the point where it launched the map intent because notifications indicate as such.
The only difference that I'm noticing between not working and working seems to be the manner in which the service is started.
Documentation:
I found this android docs page: https://developer.android.com/guide/components/activities/background-starts. It says (in part):
Apps running on Android 10 or higher can start activities only when one or more of the following conditions are met:
The app has a visible window, such as an activity in the foreground.
<other possible conditions>
Why doesn't this start? Am I misunderstanding this? Google Maps most certainly has a visible window, so I am expecting to be able to start it.
Note: Again, I'm not planning on releasing my app to the general public. This is just for me.
The larger goal is to tinker with a used Pixel 3a and turn it into a home utility device
Write a launcher app (i.e., have your activity respond to ACTION_VIEW/CATEGORY_HOME) and set it as your default launcher. It will automatically start when the phone starts, just as your current default launcher does. And, you can put a button or something in your own launcher that launches the real launcher via an explicit Intent.
This would allow you to skip the on-boot receiver and the service.
Why doesn't this start?
You do not qualify for a background activity start.
Google Maps most certainly has a visible window, so I am expecting to be able to start it.
First, presumably it does not have a visible window right after boot.
Second, you are not writing the Google Maps app, and Google Maps is not trying to start an activity from the background. You are writing your own app, and your own app is trying to start an activity from the background. And, since your own app does not have a visible window right after boot, it does not qualify for a background activity start under the "app has a visible window" rule.
Following up on the answer by #CommonsWare, here is my activity's configuration in my app's manifest file (just for the sake of completeness):
<activity
android:name="com.example.androidstartonboot.MainActivity"
android:launchMode="singleTask"
android:stateNotNeeded="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Note: Strictly speaking, launchMode and stateNotNeeded are not necessary for MainActivity to successfully launch on startup, but my understanding is that it is good practice to add them to a launcher. Documentation: https://developer.android.com/guide/topics/manifest/activity-element
To enable:
Run the app (or run the debugger) to install.
Press the "Home" button (solid dot on Android 11). Android should present an option for which app to use to respond to the LAUNCHER intent. There should be two options: "Pixel Launcher" (the Android default) and the app who's MainActivity is configured as above.
Select your app and choose "Always use this app".
Now, every time you press the "Home" button, your app should run.
Note: To restore the "Pixel Launcher" as the default launcher:
Swipe down from top
-> Settings
-> Apps & Notifications
-> All Apps
-> Pixel Launcher
-> Advanced
-> Home (should say "No" at this point)
-> <choose "Pixel Launcher">
This was tested on Android Studio Bumblebee | 2021.1.1 Patch 2, in a Kotlin project.
Note: This does not work if there is also a BroadcastReceiver that the manifest is configuring to respond to the intent filter <action android:name="android.intent.action.BOOT_COMPLETED". I tried it. Disabling the BroadcastReceiver allowed this to work. Re-enabling it prevented MainActivity from launching on startup. So that needs to be commented out/removed before this launcher will work.
I have noticed than whenever I manually kill my application by longpressing the back button of my cellphone my broadcast receiver stops working. The receiver is in charge of displaying a notification every time the user hangs up a phone call and the same is registered in the manifest.xml.
Is this the normal/expected behaviour? I thought the receiver should continue to work even if the user decides to kill my application... Is there a way to prevent this?
Thanks.
Edit
Here's the manifest entry for the receiver:
<receiver android:name=".BroadcastReceivers.CallReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
There are ~7 billion people on the planet. Only you know what you mean by "kill".
The symptoms that you are describing, though, are consistent with a "force stop". A user normally force-stops an application by going to Settings, finding your app in the list of installed apps, and tapping on the "Force Stop" button for your app. There are some devices and firmware builds that make "Force Stop" more readily accessible than this -- such devices and firmware builds were written by drooling idiots IMHO.
If your app is force-stopped, your code will never run again, until something uses an explicit Intent to start one of your components. Usually, the user does this by tapping on your app's icon in the home screen's launcher. Until the user does this, your BroadcastReceiver will not work, and there is nothing you can do about it.
Rather than using some on-device feature to "kill" your app, try terminating its process via DDMS. If your app continues to work in that case, then however you elected to "kill" your app before is doing a "force-stop". Merely having your process be terminated, such as due to low memory conditions, should not prevent you from receiving future broadcasts.
I know that some devices (like my ASUS) are deleting static receivers when you stop an application, yours is probably one of those.
The only thing you can do is trying with emulator or other device.
My question specifically concerns the Samsung Galaxy Camera devices. It ships with a customized camera application. I guess Samsung developed their own. Since this device can be seen as a camera instead of a phone with a camera they seem to decided that their camera app should start on boot, in contrast to other devices which take the user to the home screen after boot completes.
Now, in our szenario we ship the device with our own application that has its own camera interface. We could run our application in kiosk mode but we want to allow the user to use other apps that might be helpful for his daily work as well.
So ideally, the device should start the home screen after boot completes. The user could then decide to start our app or another app. But if this isn’t possible it would also be ok if our app would start on boot instead of the home screen (since the user would reach the home screen with the home button)
Since I don’t see any chance to force the home screen to appear after boot completes, I tried to start our own application by default. To implement that I created a receiver with the following filter:
<intent-filter android:priority="1000">
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
When the intent is received, I start the main Activity of our application.
In the result, after booting the device, Samsungs default camera app will start first. You’ll see their main Activity and the most annoying part: the camera lens will be fully extended. A split second after this our app starts automatically.
My guess is, that Samsungs camera app also reacts to the boot-completed-event. Is there any chance that we could prevent their app from being started?
I believe this can be achieved - albeit in a convoluted manor - without rooting using DevicePolicyManager. By making your app a device administrator and disabling the camera the built in camera app won't launch on power up (nor camera button press). Once your app has launched re-enable the camera and have fun.
I haven't had a chance to create the code (and will update this answer when I have), but I have tested to an extent using the DisableCameraDevice app from the play store. With this app setup the camera app doesn't launch at startup and my app which receives BOOT_COMPLETE launches after a few seconds of homescreen time.
It also doesn't stop the camera button events (but does stop the camera app) so you can do the same for this (which also seems to ignore android:priority values).
If you wanted to go further you could even make you're camera app respond to the ACTION_MAIN, CATEGORY_HOME intents mentioned by CommonsWare and persistently select it as the homescreen app.
Combined with a full screen app which doesn't display the home/back buttons you're locked down pretty well for a fool proof camera to give customers.
The camera app uses the BOOT_COMPLETED permission attached to a receiver. It is a system application, so you would need root to modify it on the system level. If you are packing your own firmware, this would not be an issue. The standard launcher does not have the standard boot permissions, but your app would. This would avoid the issue of not booting to anything by simply removing the permission. Also, a priority of 499 is better to fall within the limit of 500.
I'm developing an android service application, which reacts on some intents. As you know, intents won't trigger until the app is launched for first time. Because my app is not interactive, I'd like it not to be shown in the launcher (app list). I can do this by removing
<category android:name="android.intent.category.LAUNCHER"/>
from the manifest file, but after that, how do I execute the app, as it is not shown anywhere? :|
Thanks.
What about disable the launcher icon after the application was launched the first time?
http://www.helloandroid.com/tutorials/removing-app-icon-launcher
Although this
the icon will only disapper when the launcher is restarted, so likely on next phone reboot, forcing the launcher to restart is not recommended"
doesn't sound good...
how do I execute the app, as it is not shown anywhere?
So you have to use BroadcastReceiver So similar topic where your can find similar solution. Check this
If your application is serviced based, responding to intents, why do you need to execute it? Won't the intents start your application?
Make sure you include the right intent filters in your manifest. Without them intents won't trigger your services.
http://developer.android.com/guide/topics/manifest/intent-filter-element.html
So I'm trying to do what many people have tried before: create an app that does not respond to the Home button. I've looked at many of the similar questions posted here on SO, but none of worked the way I wanted them to.
One thing I tried was making my app essentially another launcher. (Note: a little amount of user input is required to make it work.)
From my application's Manifest:
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME" />
I also disabled the back button and made the launch mode "singleInstance."
I think Toddler Lock did something similar, but my implementation does not behave exactly the same way. Using my implementation, my app exists as the default home launcher indefinitely including after the application has been exited. Is there any way to declare the same behavior in a place other than the Application Manifest where it can be turned on temporarily or and turned off when the app is exited?
Car Home also does a similar thing and actually does it better than Toddler Lock. I'm not sure how it does it (maybe it has more permissions since it is a native app), but it manages to do the same thing without requiring the user to accept the alternate Launcher or choose the app as the default Launcher. Anyone have any idea on how it does it?
hackbod is essentially correct. I have gotten much of the desired behavior by
Make a "capture home key" activity
as described in the question. This
is not the main activity of the
program.
In the manifest, disable it.
In the app, enable the "capture home
key" activity when you want the home
capture to happen, and disable it
when you want to exit.
The only question is what the capture home key activity should actually do. In my case, I needed it to just go to the start of the app... so it manufactures a CATEGORY_HOME intent, tests that it resolves correctly, and if so forwards on to the app. If it doesn't resolve correctly, it notifies the user, waits for the user to be ready, and then uses that intent. This way if the user chooses your app but doesn't make it default, he'll get prompted again.
To disable this after the user has enabled your app as the home app, disable that activity with PackageManager.setComponentEnabledSetting(). Note this implies that the activity that is overriding home should not be the main activity of your app, or else upon disabling it the user won't be able to return to your app.
CarHome is very different -- when Android is in a different UI mode (in a car for car mode or on a desk dock for desk mode), then a different Intent will be launched when the user presses home so that they can have a different "home" in that environment. If you are not writing a car mode home screen, you should not be using this.