小编use*_*410的帖子

每 5 分钟通知一次

我想每 5 分钟向用户发送一次通知,我正在使用以下代码。它第一次向我显示通知,但下次不给。

public void startAlarm() {
    AlarmManager alarmManager = (AlarmManager) this.getSystemService(this.ALARM_SERVICE);
    long whenFirst = System.currentTimeMillis();         // notification time
    Intent intent = new Intent(this, NotifyUser.class);
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, 0);
    alarmManager.setRepeating(AlarmManager.RTC, whenFirst, 60*5000, pendingIntent);            
}

public class NotifyUser extends Service {   
    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        loadNotification(); 
    }

    private void loadNotification() {
        NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notify = new Notification(R.drawable.ic_launcher/*android.R.drawable.stat_notify_more*/, "Hanumanji …
Run Code Online (Sandbox Code Playgroud)

android android-alarms

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

android ×1

android-alarms ×1