【问题标题】:Service doesn't run Repeating alarm at boot time服务未运行 在启动时重复警报
【发布时间】:2013-10-23 05:30:22
【问题描述】:

我想在系统启动时运行重复警报。这是代码:

// Run the SendService once an hour
@Override
public void onReceive(Context context, Intent intent) {
    //Logger.getInstance().writeLine(getClass().getName(), "Received boot, start SMS repeating alarm");
    Toast.makeText(context, "Starting SMS2Mail alarm on boot", Toast.LENGTH_LONG).show();
    Intent svcIntent = new Intent(context, MessageFileService.class);
    svcIntent.setAction(MessageFileService.GET_INTENT);
    sendSMSIntent = PendingIntent.getBroadcast(context, 0, svcIntent, 0);
    alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
            AlarmManager.INTERVAL_FIFTEEN_MINUTES,
            AlarmManager.INTERVAL_HOUR, sendSMSIntent);
}

清单有

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

 <service
        android:name="com.cio1.sms2mail.StartSendService"
        android:enabled="true"
        android:exported="true" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </service>

就我的任何调试资源而言,AlarmManager 根本不会触发。此外,有关如何从启动时恢复 LogCat 信息的任何线索都会有所帮助。 另外,这是否与here 提到的对广播接收器的限制有关? 谢谢。

【问题讨论】:

    标签: android android-service


    【解决方案1】:

    几个想法

    我在您的清单中看到了service 标记。不应该是receiver吗?在所有教程中,我都看到 BOOT_COMPLETE 被接收器捕获,而接收器又启动了 AlarmManager。

    其次,要接收onboot Intent,应用程序必须至少手动启动一次。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-11
      • 2017-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-02
      相关资源
      最近更新 更多