Have Android app auto start on reboot [duplicate] - android

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Android, how to determine if a reboot occurred?
I have an app that I would like to always be running on my phone.
Is it possible to have an Android app programmatically start after the phone has been power cycled?

Add permission android.permission.RECEIVE_BOOT_COMPLETED to your manifest. Write a broadcast receiver and add this filter to the manifest:
<receiver android:name=".MyBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Have your receiver launch any service or perform any task it chooses.
I don't think it's a good idea to try to launch an activity at boot time, but maybe it would work out ok.

It's an OK idea to have an app start after a reboot. It's not OK to put an Activity into the foreground after a reboot. Activities should always be under user control. In general, try not to out-guess the users.
However, you may have an interesting use case, so please post it.

Related

does using AccessibilityService in android make it a system app?

I am making an AccessibilityService to get package name of app where click events are registered. In my manifest do I need to ask for permission for
<uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />
or inside the service tag, like this :
<service
android:name=".ListenToEvents"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
android:resource="#xml/accessibility_service_config" />
</service>
I am guessing I don't need both but if I ask for permission outside the services tag in uses permission the ide tells me this permission will make my app a system app. when the permission is inside the service tag, however, it doesn't raise any such warning.
I do enable the settings for the app after installing. The callback on events is not being called.
first of all I would like to know if my app is a system app which needs to be installed in the system partition of the android phone. any further help will be greatly appreciated. I have already looked at two projects on GitHub but they are too big to sort out the pertinent code. so please help with the code necessary to do the basic task, of lets say listening to a tap event.
thanks
When you are building your own Accessibility Service, when you execute the app, the service will become present in Settings->Accessibility under 'Services' section. You can then turn on your service and run it on any app you want. Regarding developing an accessibility service, refer to the following,
https://codelabs.developers.google.com/codelabs/developing-android-a11y-service/#2
https://developer.android.com/guide/topics/ui/accessibility/service
For listening to clicks, I suggest going through 'Configuring the scroll button' section of Codelabs and using ACTION_CLICK instead of ACTION_SCROLL_FORWARD
To clarify about BIND_ACCESSIBILITY_SERVICE. You expose that permission in the service to guarantee that only the system can bind to your service. Only the system may use that permission.

Mobilock app starts before BOOT_COMPLETED broadcast... How is it possible?

There is a kiosk app called Mobilock. This app starts way faster (Almost 5 seconds before) than my own app which starts with BOOT_COMPLETED broadcast.
My own app has the highest priority which is max value of integer. So this is not about the priority.
These guys have found a way to start their application 5 second sooner than BOOT_COMPLETED broadcast.
Has anyone got an idea about what they are doing?
Oh my god! I've luckily found it. :)
This Page Says : Apps must register their components with the system before they can run during Direct Boot mode or access device encrypted storage. Apps register with the system by marking components as encryption aware. To mark your component as encryption aware, set the android:directBootAware attribute to true in your manifest.
Encryption aware components can register to receive a ACTION_LOCKED_BOOT_COMPLETED broadcast message from the system when the device has been restarted. At this point device encrypted storage is available, and your component can execute tasks that need to be run during Direct Boot mode, such as triggering a scheduled alarm.
You just need to put
android:directBootAware="true"
So the code in manifest is;
<receiver
android:directBootAware="true" >
...
<intent-filter>
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
</intent-filter>
</receiver>
Listen also to android.intent.action.QUICKBOOT_POWERON and android.intent.action.LOCKED_BOOT_COMPLETED.
It seems to be device-dependant, which broadcast is sent first.

How to get notify before uninstalling app in android [duplicate]

This question already has answers here:
Is it possible to detect Android app uninstall?
(8 answers)
Closed 6 years ago.
I am working in app that needs to call an api, Webservice before uninstall app so please let me know if any solution to call before uninstall or any process that called before uninstall app.
You could try adding a BroadcastReceiver listening for android.intent.action.PACKAGE_REMOVED events.
You Register your BroadCastReceiver with this filter:
<receiver android:name=".MyBroadCastReceiver">
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
</intent-filter>
</receiver>

Open android application when device opens

I'm developing an android application that I want that starts when the device is opened and remains on foreground until it is closed. To achieve this I have used some tricks that I found surfing the Internet:
Start application when device starts >> Solved using a broadcast receiver that handles the android.intent.action.BOOT_COMPLETED
Ignore the Home button when the application is opened >> Solved using an Activity Alias that is installed when the app starts and uninstalled when the application closes
I test the solution and it works fine almost always. When I close the device with the app executing and it restarts the device the application is opened twice. I think that the extra opening is due because the Activity Alias wasn't uninstalled because the app doesn't close properly when I shutdown the device.
Is there a solution to avoid this behavior?
Thanks
You should use ACTION_SHUTDOWN and perform necessary task on shutdown.Find more details here.
You can maybe use the Shutdown intent to finish your activity when the device is shutting down.
<receiver android:name=".myReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
</intent-filter>
</receiver>
Then you can just use the activity.finish(); to close your app.

What determines app auto start on boot in Android?

In my application, there's a feature that allows users to dial a specific number and brings up an activity to front. I have the following receiver, and the only receiver registered in AndroidManifest.xml.
<receiver android:name="com.example.myapp.OutgoingCallListener" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
Please note there's no BOOT_COMPLETED intent or service.
Now here's the thing I couldn't figure out. When I reboot my device, go check the Running Apps, my application is not listed there. But, if I dial the specific number, my application starts and the activity is brought to front.
My question is: If the app is not a service, and not started on boot, how could it recieve intent from Android? That is, in my case, how could my app listen to NEW_OUTGOING_CALL while it's not started at all?
A BroadcastReceiver that is registered in the manifest is always capable of responding to a matching broadcast. If your process is not running for any reason, Android will start up a process for you.

Categories

Resources