Open App when booting android

Asked

Viewed 2,438 times

2

I made an Android App on Intelxdk, is working normal, now I want it to open automatically when I turn on the phone.

I know there are some apps on playstore that do this, but at first I didn’t want to use any third-party app but to make my app boot itself.

  • I never made an implementation like this in Intexdk, but if you develop with Android Studio, you will need to implement a native functionality of Android, that is to say call a service native of the Android system to be able to call your app.

1 answer

1

If it was in Android Studio was just you indicate in tag Androidmanifest.xml permission code: android.permission.RECEIVE_BOOT_COMPLETED. This action is a requirement of Android for the application user to know what features the application he is installing will make use of. Without this tag a Runtimeexception will be triggered the moment your application tries to use the resource.

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

Then you must create a Broadcastreceiver which will represent the action that will be executed the moment the device finishes connecting fully. The Broadcastreceiver class of the Android API aims to run a small background processing. It is usually used to intercept Intents like the one that is fired at the moment the device starts.

public class BootUpReceiver extends BroadcastReceiver {
   
     @Override
     public void onReceive(Context context, Intent i) {
        Intent intent = new Intent(context, MinhaActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
     }
 
}

In the code above you can see that when Broadcastreceiver runs an Activity will be called, but that’s just the example I found. You are free to run whatever you want at this point like, start a Service, a scheduled task, etc...

Another important detail is that the flag has been added Intent.FLAG_ACTIVITY_NEW_TASK to display the Activity, as no Acitivity of the application has been started, this will be the first. If this flag is not present an exception at runtime will be launched.

After creating Broadcastreceiver you should announce it on AndroidManifest.xml application as it was done with Activitys. One detail to be explained is that the Intentfilter inside the Receiver tag indicates that this Broadacastreceiver will run when the Intent BOOT_COMPLETED happens. Translating into kids... => when the device is connected.

<receiver android:enabled="true"
  android:name=".receivers.BootUpReceiver"
  android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
    <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</receiver>

Done, your application will start automatically when the device is turned on.

In Intel XDK the process is equal, the only difference is that instead of implementing the steps in Androidmanifest.xml, you must implement in intelxdk.config.Additions.

References

Browser other questions tagged

You are not signed in. Login or sign up in order to post.