android - 在 BOOT_COMPLETED 上安排任务

标签 android broadcastreceiver android-service

我已经为 BOOT_COMPLETED 操作编写了下一个广播接收器

public class FineWeatherBootStarter extends BroadcastReceiver {
PendingIntent pendingIntent = null;

public void onReceive(Context context, Intent intent) {

    long firstTime = System.currentTimeMillis();
    Intent serviceIntent = new Intent(FineWeather.ACTION_REFRESH);
    intent.setType(Weather.CONTENT_TYPE);
    pendingIntent = PendingIntent.getService(context, 0,serviceIntent, 0);
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    am.setRepeating(AlarmManager.RTC,
                    firstTime, 30*1000, pendingIntent);
    Toast.makeText(context, "STARTED!!!!!!!!!", 5000).show();
}

我可以看到“STARTED!!!!!!!!!”启动设备上的消息,但我的服务似乎不是每 30 秒启动一次

哪里有问题&

最佳答案

尝试改变你的 list

<receiver android:name="MyBootReceiver" android:process=":hascode_process">
        <intent-filter >
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.USER_PRESENT" />
        </intent-filter>
    </receiver>

关于android - 在 BOOT_COMPLETED 上安排任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7077456/

相关文章:

Android 11 无障碍服务权限

android - 如何为android中的每个联系人/人发送短信确认?

android - 如何等待确认短信在 AsyncTask 中发送?

java - 在android中应用程序退出之前完成写入磁盘任务

android - Droid 上的 zz_moto_actionbar_bkg.xml 资源错误

android - 动态添加的行不可见

android - 如何为 Android 上的任何 SMS 应用程序发送的 SMS 生成送达报告

Android _ 从服务类重定向到另一个 Activity ?

android - 第三方应用程序可以在android 7中实现CallScreeningService吗?

java - 汉堡包到箭头动画无法以编程方式工作