【问题标题】:How to set alarm for every 10 minutes in Android Application?如何在 Android 应用程序中每 10 分钟设置一次闹钟?
【发布时间】:2012-01-24 12:40:52
【问题描述】:

我想每 10 分钟设置一次闹钟。但它是第一次运行,只有任何机构好心帮助我

Intent intent = new Intent(this, ConnectionReceiver.class);

PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0,
intent, PendingIntent.FLAG_ONE_SHOT);

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (1 * 1000),   pendingIntent);
Toast.makeText(this, "Alarm set", Toast.LENGTH_LONG).show();//every 10 minutes i want to print the toast

【问题讨论】:

  • 将 (1 * 1000) 替换为 (10 * 60 * 1000) 您在代码中为 alarmManager 设置的位置。

标签: android alarm


【解决方案1】:
    Calendar calCurrent = Calendar.getInstance();
    long tenmin = 10 * 60 * 1000;
    int mynotifyidis = Integer.parseInt(mydelid);
    Intent mIntent = new Intent(this, NotificationService1.class);
    mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    mIntent.putExtra("id", mynotifyidis);

    AlarmManager mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    PendingIntent snoozependingintent = PendingIntent.getService(this,
            -mynotifyidis, mIntent, PendingIntent.FLAG_ONE_SHOT);

    mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
            calCurrent.getTimeInMillis() + fivemin, fivemin,
            snoozependingintent);

【讨论】:

    【解决方案2】:
    猜你喜欢
    • 2022-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多