我正在为Android电视开发一个Android启动器应用程序。当我将自定义启动器设置为默认启动器时,它会按预期工作,但当我重新启动设备(电视)时,它会显示旧系统(电视操作系统)启动器,当我检查设置时,我发现我的自定义启动器是默认设置。知道是什么问题吗谢谢
pengsaosao1#
这也发生在我身上,为此我集成了下面的功能。DeclarePermission在应用程序中接收引导完成的通知,以便接收者在设备引导完成时得到通知。
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
然后也声明接收器。
<receiver android:name=".RunOnStartup" android:enabled="true" android:exported="true" android:permission="android.permission.RECEIVE_BOOT_COMPLETED"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.QUICKBOOT_POWERON" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter></receiver>
<receiver
android:name=".RunOnStartup"
android:enabled="true"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
现在在RunOnStartup类中打开启动器应用的主Activity。
class RunOnStartup: BroadcastReceiver() {override fun onReceive(context: Context, intent: Intent) { if (intent.action.equals(Intent.ACTION_BOOT_COMPLETED)) { val i = Intent(context, MainActivity::class.java) /* * FLAG_ACTIVITY_NEW_TASK is important because the activity is launched from context outside * the activity, without this activity not start. * */ i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) context.startActivity(i) }}}
class RunOnStartup: BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action.equals(Intent.ACTION_BOOT_COMPLETED)) {
val i = Intent(context, MainActivity::class.java)
/*
* FLAG_ACTIVITY_NEW_TASK is important because the activity is launched from context outside
* the activity, without this activity not start.
* */
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(i)
}
1条答案
按热度按时间pengsaosao1#
这也发生在我身上,为此我集成了下面的功能。
DeclarePermission在应用程序中接收引导完成的通知,以便接收者在设备引导完成时得到通知。
然后也声明接收器。
现在在RunOnStartup类中打开启动器应用的主Activity。