【发布时间】:2021-01-18 21:12:01
【问题描述】:
当应用程序打开时,它工作正常,但当应用程序在后台时,调用 BroadcastReceiver 但活动意图不工作
class FakeCallReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent?) {
LogUtils.d("===onReceive 1")
setCustomSetting(context)
LogUtils.d("===onReceive 2")
val incomingCallActivity = Intent(context.applicationContext, FakeCallActivity::class.java)
incomingCallActivity.flags = Intent.FLAG_ACTIVITY_NEW_TASK
context.startActivity(incomingCallActivity)
LogUtils.d("===onReceive 3")
}
fun setCustomSetting(context: Context){
val wakeLock: PowerManager.WakeLock =
(context.getSystemService(Context.POWER_SERVICE) as PowerManager).run {
newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyApp::MyWakelockTag").apply {
acquire()
}
}
val mKeyguard = (context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager).apply {
newKeyguardLock("MyApp::Keyguard").disableKeyguard()
}
}
}
所有日志都是打印的,没有发生异常但仍然没有调用FakeCallActivity
MinSdkVersion = 24
TargetSdkVersion = 29
1.我有错吗?
2. 应用在后台时是否有其他方法可以打开活动?
【问题讨论】:
-
你试过了吗? stackoverflow.com/a/16666632
-
您可以在此处添加设备详细信息吗?另外,添加
minSdkVersion和targetSdkVersion。 -
@Deepanshu
androidMinSdkVersion = 24 androidTargetSdkVersion = 29 device os version = 8.1 -
@HimanshuChoudhary 是的,我试过了
标签: java android kotlin broadcastreceiver