android - Broadcast Receiver 每 5 分钟获取一次 wifi 信号

标签 android android-broadcast

friend

我在这里很新,对于 Android 也是如此。我想知道是否可以每 5 -10 分钟获得一次 Wifi 信号,我听说我们可以使用广播接收器,但我不知道是否可以每 5 或 10 分钟刷新一次

谢谢

最佳答案

是的,你可以。

    AlarmManager service = (AlarmManager) context
        .getSystemService(Context.ALARM_SERVICE);
    Intent i = new Intent(context, StatusQueryServiceStartReceiver.class);
    // Schedule the alarm!If there is already an alarm scheduled for the same IntentSender, it will first be canceled.
    PendingIntent pending = PendingIntent.getBroadcast(context, 0, i,
        PendingIntent.FLAG_CANCEL_CURRENT);
    // InexactRepeating allows Android to optimize the energy consumption
    service.setInexactRepeating(AlarmManager.RTC_WAKEUP,
        0,//cal.getTimeInMillis(), 
        REPEAT_TIME, pending);
    // service.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
    // REPEAT_TIME, pending);

StatusQueryServiceStartReceiver 是一个广播接收器

关于android - Broadcast Receiver 每 5 分钟获取一次 wifi 信号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20758181/

相关文章:

android - Gradle 多项目 android 库设置与 maven 本地

android - 在 Service 中发送广播并在 AndroidTestCase 中接收

android - java.lang.SecurityException : Permission Denial: not allowed to send broadcast android. intent.action.MEDIA_MOUNTED 仅在 KitKat 上

android - 我可以使用广播接收器启动另一个应用程序吗?

java - PutAll to the Map 不打乱顺序

android - 我无法设置日期选择器从明天开始(Material Design Datepicker)

android - 在 Android Room 中如何创建和调用自定义查询

android - LocalBroadcastReceiver 在线程内部不起作用

android - RECEIVE_BOOT_COMPLETED 和 "Exported receiver does not require permission"

android - Android 浏览器上的 HTML5 输入