苏醒锁需要的广播接收器,同时手机睡觉? [英] Wake lock required for BroadcastReceiver while phone sleeps?
本文介绍了苏醒锁需要的广播接收器,同时手机睡觉?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
想写一个广播接收器,用于处理传入的短信。我是否需要使用唤醒锁/部分唤醒锁,这个应用程序的工作,尽管设备临睡前由于缺乏前景的活动?
Trying to write a Broadcast Receiver that processes incoming SMSs. Do I need to use a wake lock / partial wake lock, for this application to work, in spite of device going to sleep due to lack of foreground activity ?
推荐答案
我倾向于延长WakefulBroadcastReceiver简化的东西,所以在某种程度上是的。例如:
I tend to extend a WakefulBroadcastReceiver to simplify things, so in a way yes. For example:
public class MyBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
final ComponentName comp = new ComponentName(context.getPackageName(),
MyIntentService.class.getName());
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
这篇关于苏醒锁需要的广播接收器,同时手机睡觉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文