Android Launcher不断恢复到系统默认启动器

sg24os4d  于 2023-06-27  发布在  Android
关注(0)|答案(1)|浏览(140)

我正在为Android电视开发一个Android启动器应用程序。当我将自定义启动器设置为默认启动器时,它会按预期工作,但当我重新启动设备(电视)时,它会显示旧系统(电视操作系统)启动器,当我检查设置时,我发现我的自定义启动器是默认设置。
知道是什么问题吗谢谢

pengsaosao

pengsaosao1#

这也发生在我身上,为此我集成了下面的功能。
DeclarePermission在应用程序中接收引导完成的通知,以便接收者在设备引导完成时得到通知。

  1. <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

然后也声明接收器。

  1. <receiver
  2. android:name=".RunOnStartup"
  3. android:enabled="true"
  4. android:exported="true"
  5. android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
  6. <intent-filter>
  7. <action android:name="android.intent.action.BOOT_COMPLETED" />
  8. <action android:name="android.intent.action.QUICKBOOT_POWERON" />
  9. <category android:name="android.intent.category.DEFAULT" />
  10. </intent-filter>
  11. </receiver>

现在在RunOnStartup类中打开启动器应用的主Activity。

  1. class RunOnStartup: BroadcastReceiver() {
  2. override fun onReceive(context: Context, intent: Intent) {
  3. if (intent.action.equals(Intent.ACTION_BOOT_COMPLETED)) {
  4. val i = Intent(context, MainActivity::class.java)
  5. /*
  6. * FLAG_ACTIVITY_NEW_TASK is important because the activity is launched from context outside
  7. * the activity, without this activity not start.
  8. * */
  9. i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
  10. context.startActivity(i)
  11. }
  12. }
  13. }
展开查看全部

相关问题