Open app when initializing android

2

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

I know there are some applications in the playstore that do this, but at first I did not want to use any third-party apps, but rather to make my app boot itself.

    
asked by anonymous 26.05.2016 / 14:59

1 answer

1

If it was in Android Studio, you only had to indicate in the permission tag of AndroidManifest.xml the code: android.permission.RECEIVE_BOOT_COMPLETED . This action is an Android requirement for the application user to know what features the application that he is installing will make use of. Without this tag a RuntimeException will be triggered when your application attempts to use the feature.

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

Then you should create a BroadcastReceiver that will represent the action that will take place when the device is fully powered on. The BroadcastReceiver class of the Android API is meant to perform a little background processing. It is usually used to intercept Intents like the one that is triggered the moment the device boots.

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 the BroadcastReceiver is executed an Activity will be called, but that was just the example I found. You are free to perform whatever you want at this point like, start a Service, a scheduled task, etc ...

Another important detail is that the Intent.FLAG_ACTIVITY_NEW_TASK flag has been added to display the Activity, because until that time no application Acitivity has been started, this will be the first. If this flag is not present a run-time exception will be thrown.

After creating the BroadcastReceiver you must announce it in AndroidManifest.xml of the application just as it was done with the Activity. One detail to be explained is that the IntentFilter within the Receiver tag indicates that this BroadacastReceiver will run when the BOOT_COMPLETED attempt is made. Translating as 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 the same, the only difference is that instead of implementing the steps in AndroidManifest.xml , you should deploy to intelxdk.config.additions .

References

26.02.2017 / 00:21