爱码蛋Android知识Android开发

Android引导程序开发要点

2017-05-17  本文已影响213人  一只好奇的茂
  1. 如何保证Android重置后进入后启动welcome应用?
    welcome应用实际上是launcher应用;
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
// 去掉如下这行,即可隐藏welcome在桌面的图标
// <category android:name="android.intent.category.LAUNCHER"/>
  1. 如何保证第一次启动welcome,而不是launcher?
    同样的intent,Android优先启动优先级更高的app;launcher默认的优先级为0。
<activity android:name="DefaultActivity"
            android:excludeFromRecents="true">
        <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" />
        </intent-filter>
    </activity>
</application>
  1. 如何确保welcome应用只第一次启动,之后不启动?
    在welcome设置完,加入如下代码,即可在PackageManager中去掉Welcome应用的MainActivity,下次即可不启动之.
// remove this activity from the package manager.
PackageManager pm = getPackageManager();
ComponentName name = new ComponentName(this, MainActivity.class);
pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
        PackageManager.DONT_KILL_APP);
  1. 在welcome设置完成后,调用如下函数,告诉系统已经provisioned,否则将出现Android home虚拟键无法点击等各种异常。
private static void setProvisioned(Context mContext) {
/* Add a persistent setting to allow other apps to know the device has been provisioned.*/
Settings.Secure.putInt(getContentResolver(),Settings.Secure.DEVICE_PROVISIONED, 1); 
Settings.Global.putInt(mContext.getContentResolver(), "device_provisioned", 1);
 Settings.Secure.putInt(mContext.getContentResolver(), "user_setup_complete", 1);
    }

参考:

Android Provision (Setup Wizard)

上一篇 下一篇

猜你喜欢

热点阅读