google setupwizard 是可以定制,你可以替换掉里面的页面,也可以新添加页面。实现方法就是overlay,用一个定制过的apk。这里google已经实现了,我们只需要修改对应的app就行。
vendor/google/gms/apps/GmsSampleIntegration
介绍:
1.申明一个Overlay APK
这个APK必须要接受
com.android.setupwizard.action.PARTNER_CUSTOMIZATION广播
<receiver android:name=".SuwCustomizationReceiver">
<intent-filter>
<action android:name="com.android.setupwizard.action.PARTNER_CUSTOMIZATION" />
</intent-filter>
</receiver>
2.定制wizard script
config.xml标示了会加载哪个script
<resources>
<string name="wizard_script_uri" translatable="false">android.resource://com.google.android.gmsintegration/raw/wizard_script</string>
</resources>
wizard_script.xml
<!-- Welcome screen with language selection -->
<WizardAction id="welcome"
wizard:uri="intent:#Intent;action=com.android.setupwizard.WELCOME;end">
<result wizard:action="carrier_setup" />
</WizardAction>
<!-- Privileged carrier setup app -->
<WizardAction id="carrier_setup"
wizard:uri="intent:#Intent;action=com.android.setupwizard.CARRIER_SETUP;end">
<result wizard:name="ok"
wizard:resultCode="-1"
wizard:action="wifi_settings" />
<result wizard:name="not_ready"
wizard:resultCode="1"
wizard:action="wifi_settings" />
<result wizard:action="activation_check" />
</WizardAction>
。。。。。。
action就是用来启动相应的script,比如在settings中有相关的action设置,到时候setupwizard就会来加载对应的activity。
result就是执行玩当前的script,下一步的script。如果没有result,就直接结束。
要想定制自己的script,只需要新建一个自己的WizardAction,然后实现相应的intent。
<WizardAction id="welcome"
wizard:uri="intent:#Intent;action=com.android.setupwizard.WELCOME;end">
<result wizard:action=" my_action " />
</WizardAction>
<!-- New custom action -->
<WizardAction id="my_action"
wizard:uri="intent:#Intent;action=com.my.package.ADDITIONAL;end">
<result wizard:action="carrier_setup" />
</WizardAction>
注意:WizardAction顺序不能乱写,后面注释有描述,有的可以定制,有的不能。
<!-- OEM completion [CUSTOMIZABLE] -->
<WizardAction id="oem_post_setup"
wizard:uri="intent:#Intent;action=com.android.setupwizard.OEM_POST_SETUP;end" />
<!-- Leave Setup Wizard [REQUIRED] -->
<WizardAction id="exit"
wizard:uri="intent:#Intent;action=com.android.setupwizard.EXIT;end" />
3.如何处理下一步
当当前页面处理完后,要进入下一个页面,将会发送一个action:
com.android.wizard.NEXT。这个intent应当包含extras,来表明script,当前action和result code。
public class MyActivity extends Activity {
private static final int NEXT_REQUEST_CODE = 1; // Can be any positive int
public void done(boolean success) {
int resultCode = success ? Activity.RESULT_OK : ResultCodes.RESULT_SKIP;
Intent intent = WizardManagerHelper.getNextIntent(getIntent(), resultCode);
startActivityForResult(intent, NEXT_REQUEST_CODE);
// finish(); // Optional. Calling finish will remove this activity from the
// back stack, such that this activity will be skipped if the
// user clicks back from the next screen.
}
}