如何在Android应用程序中每10分钟设置一次警报?

时间:2012-01-24 12:40:52

标签: android alarm

Hai我试图每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

2 个答案:

答案 0 :(得分:2)

    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);

答案 1 :(得分:1)