STK应用在源代码中是有源代码的,在android系统启动的过程中这个应用在理论上讲是应该被启动的。但是在没有SIM卡或者RIL层出现问题的时候,我们在应用列表里是无法看到这个应用的图标的。这种使某个应用不在应用列表里显示的功能是通过如下代码实现的。
private static void setAppState(Context context, boolean install, int slotId) {
if (context == null) {
return;
}
PackageManager pm = context.getPackageManager();
if (pm == null) {
return;
}
ComponentName cName;
// check that STK app package is known to the PackageManager
if (slotId == 0) {
cName = new ComponentName("com.android.stk",
"com.android.stk.StkLauncherActivity");
} else {
cName = new ComponentName("com.android.stk",
"com.android.stk.StkLauncherActivity2");
}
int state = install ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
: PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
try {
/// 这里是关键
pm.setComponentEnabledSetting(cName, state,
PackageManager.DONT_KILL_APP);
} catch (Exception e) {
CatLog.d("StkAppInstaller", "Could not change STK app state");
}
}
主要是通过调用 PackageManager的setComponentEnabledSetting函数来实现。
private static void setAppState(Context context, boolean install, int slotId) {
if (context == null) {
return;
}
PackageManager pm = context.getPackageManager();
if (pm == null) {
return;
}
ComponentName cName;
// check that STK app package is known to the PackageManager
if (slotId == 0) {
cName = new ComponentName("com.android.stk",
"com.android.stk.StkLauncherActivity");
} else {
cName = new ComponentName("com.android.stk",
"com.android.stk.StkLauncherActivity2");
}
int state = install ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
: PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
try {
/// 这里是关键
pm.setComponentEnabledSetting(cName, state,
PackageManager.DONT_KILL_APP);
} catch (Exception e) {
CatLog.d("StkAppInstaller", "Could not change STK app state");
}
}
主要是通过调用 PackageManager的setComponentEnabledSetting函数来实现。