How to Configure an Android App to Run Automatically After Terminal Boot: Difference between revisions

From wizarPOS
No edit summary
(Replaced content with "{{Migrating|https://smartpossdk.gitbook.io/cloudpossdk/faq/other-development/auto-run-app-post-boot}}")
Tag: Replaced
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Description ==
{{Migrating|https://smartpossdk.gitbook.io/cloudpossdk/faq/other-development/auto-run-app-post-boot}}
* Android apps can listen to system or custom broadcast messages by registering receivers1.
 
* Android system sends a broadcast message when the phone boots up, called android.intent.action.BOOT_COMPLETED23.
 
* Apps can declare a receiver in the manifest file to receive the boot broadcast and start a service or activity in it23.
 
Code example:
<syntaxhighlight lang="java" line='line'>
// Declare receiver in manifest file
<receiver android:name=".BootReceiver">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>
 
// Receiver class
public class BootReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        // Check if it is boot broadcast
        if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
            // Start service or activity
            Intent newIntent = new Intent(context, MyService.class);
            context.startService(newIntent);
        }
    }
}
</syntaxhighlight >
== Demo APK ==
[http://ftp.wizarpos.com/advanceSDK/BootCompleteAutoStartDemo.zip Demo APK]

Latest revision as of 04:57, 8 April 2024

Please visit new link of same subject:

https://smartpossdk.gitbook.io/cloudpossdk/faq/other-development/auto-run-app-post-boot

We're making a move! Our site's content is migrating to a new URL, to provide you with an enhanced browsing experience. Please update your bookmarks accordingly. Thank you for your continuous support!