我正在创建一个Android应用程序。它将添加到应用程序中的所有数字列入白名单!在进行不在白名单中的呼叫时使用服务将被断开!
一切都很完美!我在手机启动时添加了BootCompleteReceiver来启动服务!但我面临一个问题,当用户重启系统时,启动服务需要一些时间!因此,在特定时间用户可以拨打任何电话!
我怎么能处理这个问题!请建议一种方法!
代码:
public class BootCompleteReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(new Intent(context, CallService.class));
//Util.scheduleJob(context);
} else {
context.startService(new Intent(context, CallService.class));
}
}
}
}
答案 0 :(得分:0)
由于可能会有许多应用程序注册此广播,因此在您的应用中接收Intent可能会有轻微的延迟。然而,速度取决于几个因素,如设备的CPU速度,设备上系统RAM的容量等。
由于行为无法控制,您可以做的最好是在AndroidManifest.xml中为接收器设置优先级,如下所示:
<action android:name="android.intent.action.BOOT_COMPLETED" android:priority="999"/>