I am developing an app and I need it to start after boot the device or after mounting the sdcard. This has been done using a receiver in manifest and a class that extends BroadcastReceiver.
Fragment of AndroidManifest.xml
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<receiver android:name="util.MediaMountedReceiver" android:enabled="true"
android:exported="false" >
<intent-filter>
<action android:name="android.intent.action.MEDIA_MOUNTED" />
<data android:scheme="file"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Class MediaMountedReceiver
public class MediaMountedReceiver extends BroadcastReceiver{
SharedPreferences sharedPref = null;
@Override
public void onReceive(Context context, Intent intent) {
sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
/** Verifica se é para iniciar automático ou não */
if(sharedPref.getBoolean(SettingsFragment.KEY_PREF_STARTUP_AUTO, false)){
Intent i = new Intent(context, PlayerScreen.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}
In almost all devices I tested functioned normally except one mini pc android.
Conf. the device: Android 4.1.1 Kernel Version 3.0.8 + rk30sdk-eng4.1.1 JRO03H
In this device after booting the app is opened and following is minimized. I believe it is a configuration problem device itself since I have other similar features but with different versions of android.