尝试编写处理传入SMS的广播接收器。我是否需要使用唤醒锁定/部分唤醒锁定才能使此应用程序正常工作,尽管设备由于缺乏前台活动而进入睡眠状态?
答案 0 :(得分:1)
我倾向于扩展WakefulBroadcastReceiver以简化事情,所以在某种程度上是肯定的。例如:
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);
}
}