Create a new java class in your android/src/main/java/<package-name>/..
folder (same folder as MainActivity.java)
Call it whatever you want e.g. BootBroadcastReceiver.java
package <your package name here>;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class BootBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}
add this android permission to your AndroidManifest.xml
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
add this at the bottom of the <application ... />
object inside your AndroidManifest.xml
<receiver android:enabled="true" android:exported="false"
android:name=".BootBroadcastReceiver"
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>
The app needs to opened at least once before this will work.
this works for me on ATV devices and Acer/Lenovo tablets