前言:本文基於Android P/Q進行的實驗,其餘版本並不能保證成功php
Google SetupWizard中文翻譯爲設置嚮導, 是GMS應用的一部分, 不過Google提供了文檔供OEM廠商或者運營商進行定製, 文檔的名稱是Configuring the Setup Wizardjava
#Android Q library
LOCAL_STATIC_ANDROID_LIBRARIES := \
setupcompat \
setupdesign
#Android P library
include frameworks/opt/setupwizard/library/common-gingerbread.mk
複製代碼
Android.mk中須要添加SetupWizard庫,這個是爲了使用Google SetupWizard的主題而添加的,若是使用自定義的主題的話,有可能測不過GMS. Android P使用的是frameworks/opt/setupwizard, 而Android Q必須換成external下的setupcompat和setupdesign.android
按照Google的文檔,咱們須要添加一個空的廣播用於接收com.android.setupwizard.action.PARTNER_CUSTOMIZATION
,這個廣播能夠不作任何動做git
<!--AndroidManifest.xml-->
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.setupwizard.demo">
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true">
<receiver android:name=".SuwCustomizationReceiver">
<intent-filter>
<action android:name="com.android.setupwizard.action.PARTNER_CUSTOMIZATION" />
</intent-filter>
</receiver>
</application>
</manifest>
複製代碼
//SuwCustomizationReceiver.java
package com.setupwizard.demo;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class SuwCustomizationReceiver extends BroadcastReceiver {
public SuwCustomizationReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
}
}
複製代碼
通常使用的是GmsSampleIntegration
這個應用裏面的raw目錄,這個應用是Google提供的一段集成自定義SetupWizard的demo例子,通常是在vendor/${partener_gms}/apps
目錄下.
而raw這個目錄則包含了Google SetupWizard的流程, Google SetupWizard就會按照這些xml的流程跳轉到對應的界面, 包括自定義的界面.因此這個raw目錄是自定義Google SetupWizard的核心, 不管是添加仍是修改頁面,都極可能會涉及到
移植了這個raw目錄以後須要修改包名com.google.android.gmsintegration
爲本身的包名github
ag com.setupwizard.demo
看是否與AndroidManifest.xml中的包名是否保持一致便可定製SetupWizard須要指定開機時的啓動的流程, 不然會用Google SetupWizard.apk中的xml/目錄下的流程shell
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="wizard_script_uri" translatable="false">android.resource://com.setupwizard.demo/raw/wizard_script</string>
</resources>
複製代碼
爲了區分與原生Google SetupWizard的不一樣, 在strings.xml
添加一行字符串用於overlay原生的字符串, 在Google文檔中還規定了許多能夠定製的資源,詳情見文檔中的Providing resource assetsbash
<!--strings.xml-->
<!--sim_missing_text出如今設置嚮導第二頁, 前提是設備沒有插入sim卡-->
<string name="sim_missing_text">Demo for sim missing</string>
複製代碼
以上步驟以後就能夠編譯自定義的SetupWizard而後push進去啓動了, 不插卡的狀況下在第二頁中就能夠看到效果了, 拷貝代碼的時候要注意修改包名, 具體的demo放在SetupWizardDemo,提交的commit id(ce16ea3) commit message(<20191120> <android><Add Setup Wizard sim missing>)app