我目前正在开发一个自定义 ROM(基于 CyanogenMod 11.0),旨在实现自定义“Kiosk 模式”。为此,我在一个应用程序中包含三个组件(具有系统权限): 服务,用于处理对状态/导航栏的修改并禁用电源键。接收方,仅在BOOT_COMPLETED
收到信号。这HomeIntentWrapper
作为启动器,仅启动一个自定义活动。
我目前面临的问题是startActivity(...)
命令在HomeIntentWrapper
以某种方式阻止系统进一步启动,并且BOOT_COMPLETED
意图从未被发送。
我用以下方法验证了这一点adb shell dumpsys activity
命令,它告诉我:
mStartedUsers:
User #0: mState=BOOTING
它也没有显示BOOT_COMPLETED
曾经发送过的广播。
现在,如果用户按下主页按钮,BOOT_COMPLETED
意图已发送,并且mState
切换到RUNNING
.
如果我不开始活动HomeIntentWrapper
,意图已发送。我在这里做错了什么?
AndroidManifest.xml:
<manifest coreApp="true">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:allowBackup="true"
android:persistent="true" >
<service android:name="Service"
android:process=":service" >
</intent-filter>
</service>
<receiver android:name="Receiver"
android:process=":receiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity android:name="HomeIntentWrapper"
android:process=":launcher" >
<intent-filter>
<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>
</manifest>
接收者:
public class Receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
context.startService(new Intent(context, Service.class));
}
}
HomeIntentWrapper:
public class HomeIntentWrapper extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startApp();
}
@Override
protected void onResume() {
super.onResume();
startApp();
}
private void startApp() {
SharedPreferences sharedPrefs = getSharedPreferences(getString(R.string.settings_file), Context.MODE_MULTI_PROCESS);
String customAppIntentString = sharedPrefs.getString(getString(R.string.settings_custom_intent), "");
if(customAppIntentString.equals("") == false) {
try {
Intent intent = Intent.getIntent(customAppIntentString);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} catch(java.net.URISyntaxException e) {
// Intentionally
}
}
}
}