[英]Android 6.0.1 application auto start after boot
I want to start my MainActivity
right after device boot.我想在设备启动后立即启动我的MainActivity
。 I tried multiple solutions but no one works.我尝试了多种解决方案,但没有一个有效。 Currently, I have this.目前,我有这个。
AndroidManifest.xml AndroidManifest.xml
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver android:name="installer.common.InstallerBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
InstallerBroadcastReceiver.kt安装程序广播接收器.kt
class InstallerBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val i = Intent(context, MainActivity::class.java)
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
i.putExtra("test", 1)
context.startActivity(i)
}
}
MainActivity.kt MainActivity.kt
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main)
if (intent.hasExtra("test")) {
someMethodHere()
}
}
Any suggestion on what can be wrong?关于什么可能是错误的任何建议?
try to split your intent-filter
尝试拆分您的intent-filter
<intent-filter>
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
Seems like there is some problem with device (zkteco), i get this error I/BackgroundManagerService: prevent from boot complete broadcast: com.mypackagename
似乎设备(zkteco)有问题,我收到此错误I/BackgroundManagerService: prevent from boot complete broadcast: com.mypackagename
On other devices i tried, it was working.在我尝试过的其他设备上,它正在工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.