背景:TV首次开机实现遥控对焦、连接wifi等指导性功能
应用需要的功能 :
1.设置相关属性让自己早于Launcher起来;
2.设置开机引导已经走完的标记位。
1. AndroidManifest.xml配置
<!-- 添加权限 For miscellaneous settings -->
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
<activity
android:name="xxxxxxx"
android:configChanges="locale|keyboard|keyboardHidden|navigation|layoutDirection"
android:exported="true"
android:excludeFromRecents="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<intent-filter android:priority="1">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.SETUP_WIZARD" />
</intent-filter>
</activity>
2.保存开机引导状态
开机引导结束后设置
public void setupSys() {
// Add a persistent setting to allow other apps to know the device has been provisioned.
// 添加持久设置以允许其他应用程序知道设备已配置。
Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);
//这个标记位标识当前用户已经走完引导流程,如果不设置这个值,Home键、锁屏等将不可用
Settings.Secure.putInt(getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1);
// Mediatek Android Patch Begin
Settings.Secure.putInt(getContentResolver(), Settings.Secure.TV_USER_SETUP_COMPLETE, 1);
// Mediatek Android Patch End
// 从PackageManager中禁用该Activity。
// remove this activity from the package manager.
PackageManager pm = getPackageManager();
ComponentName name = new ComponentName(this, GuideMainActivity.class);
pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
finish();
}
注意点 : 开机引导app需要push到system/priv-app目录下
Android.mk配置 LOCAL_PRIVILEGED_MODULE := true