I tried using the sample code in this link but it seems outdated and it did not work. So what changes do I have to make and to what files to have my app start automatically
For Android 10 there is background restrictions.
For android 10 and all version of android follow this steps to start an app after a restart or turn on mobile
Add this two permission in Android Manifest
Add this in your application tag
Add this class to start activity when boot up
public class BootReciever extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Objects.equals(intent.getAction(), Intent.ACTION_BOOT_COMPLETED)) {
Intent i = new Intent(context, SplashActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}}
We need Draw overlay permission for android 10
so add this in your first activity
private fun requestPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!Settings.canDrawOverlays(this)) {
val intent = Intent(
Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + this.packageName)
)
startActivityForResult(intent, 232)
} else {
//Permission Granted-System will work
}
}
}