[Java]
Intent intent = new Intent ("cn. pocketdigi. update. alarm ");
Intent. setClass (this, AlarmReceiver. class );
PendingIntent pi = PendingIntent. getBroadcast (this, 0, intent, 0 );
// Set a PendingIntent object to send a broadcast
AlarmManager am = (AlarmManager) getSystemService (ALARM_SERVICE );
// Obtain the AlarmManager object
// Am. set (AlarmManager. RTC_WAKEUP, System. currentTimeMillis () + 3500, pi); // only run once
Am. setRepeating (AlarmManager. RTC_WAKEUP, System. currentTimeMillis () + 3500,100 00, pi); // repeated execution
Intent intent = new Intent ("cn. pocketdigi. update. alarm ");
Intent. setClass (this, AlarmReceiver. class );
PendingIntent pi = PendingIntent. getBroadcast (this, 0, intent, 0 );
// Set a PendingIntent object to send a broadcast
AlarmManager am = (AlarmManager) getSystemService (ALARM_SERVICE );
// Obtain the AlarmManager object
// Am. set (AlarmManager. RTC_WAKEUP, System. currentTimeMillis () + 3500, pi); // only run once
Am. setRepeating (AlarmManager. RTC_WAKEUP, System. currentTimeMillis () + 3500,100 00, pi); // repeated execution
[Html]
<Cycler android: name = ". AlarmReceiver">
<Intent-filter>
<Action android: name = "cn. pocketdigi. update. alarm"/>
</Intent-filter>
</Cycler>
<Cycler android: name = ". AlarmReceiver">
<Intent-filter>
<Action android: name = "cn. pocketdigi. update. alarm"/>
</Intent-filter>
</Cycler>
[Java]
Public class AlarmReceiver extends BroadcastReceiver {
Private static final String TAG = "AlarmReceiver ";
@ Override
Public void onReceive (Context context, Intent intent ){
// TODO Auto-generated method stub
Log. v (TAG, "receive broadcast ");
// Intent it = new Intent (context, AlarmActivity. class );
// It. addFlags (Intent. FLAG_ACTIVITY_NEW_TASK );
// Context. startActivity (it );
// After receiving the broadcast, start the Activity. For simplicity, you can directly jump to the Activity that sets alarm.
// Intent. FLAG_ACTIVITY_NEW_TASK flag must be added to Intent.
}
}
Public class AlarmReceiver extends BroadcastReceiver {
Private static final String TAG = "AlarmReceiver ";
@ Override
Public void onReceive (Context context, Intent intent ){
// TODO Auto-generated method stub
Log. v (TAG, "receive broadcast ");
// Intent it = new Intent (context, AlarmActivity. class );
// It. addFlags (Intent. FLAG_ACTIVITY_NEW_TASK );
// Context. startActivity (it );
// After receiving the broadcast, start the Activity. For simplicity, you can directly jump to the Activity that sets alarm.
// Intent. FLAG_ACTIVITY_NEW_TASK flag must be added to Intent.
}
}
Cancellation Method:
[Java]
Intent intent = new Intent ("cn. pocketdigi. update. alarm ");
Intent. setClass (this, AlarmReceiver. class );
PendingIntent pi = PendingIntent. getBroadcast (this, 0, intent, 0 );
AlarmManager alarm = (AlarmManager) getSystemService (ALARM_SERVICE );
Alarm. cancel (pi );
Intent intent = new Intent ("cn. pocketdigi. update. alarm ");
Intent. setClass (this, AlarmReceiver. class );
PendingIntent pi = PendingIntent. getBroadcast (this, 0, intent, 0 );
AlarmManager alarm = (AlarmManager) getSystemService (ALARM_SERVICE );
Alarm. cancel (pi );
Another intent Method
[Java]
Code
Intent intent = new Intent (Main. this, alarmreceiver. class );
Intent. setAction ("repeating ");
PendingIntent sender = PendingIntent
. GetBroadcast (Main. this, 0, intent, 0 );
// Start time
Long firstime = SystemClock. elapsedRealtime ();
AlarmManager am = (AlarmManager) getSystemService (ALARM_SERVICE); // sends broadcasts continuously for a cycle of 5 seconds.
Am. setRepeating (AlarmManager. ELAPSED_REALTIME_WAKEUP
, Firstime, 5*1000, sender );
Code
Intent intent = new Intent (Main. this, alarmreceiver. class );
Intent. setAction ("repeating ");
PendingIntent sender = PendingIntent
. GetBroadcast (Main. this, 0, intent, 0 );
// Start time
Long firstime = SystemClock. elapsedRealtime ();
AlarmManager am = (AlarmManager) getSystemService (ALARM_SERVICE); // sends broadcasts continuously for a cycle of 5 seconds.
Am. setRepeating (AlarmManager. ELAPSED_REALTIME_WAKEUP
, Firstime, 5*1000, sender );