im working on my android app. i need to make an Alarm manager, it should notify every day at some hour.
But the problem its for example: if now is 16:00HR and i set these variables at 14:00HR it should sound the day after but when i run my app, the alarm notify at start (because now are 16:00 and it was setted at 14:00).
My setted intents, i do this before call the alarm method
Intent intAlarmaManual = new Intent( getActivity(), AlarmaManualBroad.class );
pdIntAlarmaManual = PendingIntent.getBroadcast( getActivity(), 0, intAlarmaManual, PendingIntent.FLAG_CANCEL_CURRENT );
My Method
private void setearAlarmaManual()
{
// Variables for testing
hr = 14;
min = 00;
AlarmManager manager = (AlarmManager) getActivity().getSystemService( Context.ALARM_SERVICE );
/** Set alarm by user selections **/
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis( System.currentTimeMillis() );
calendar.set( Calendar.HOUR_OF_DAY, hr );
calendar.set( Calendar.MINUTE, min );
manager.setInexactRepeating( AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, pdIntAlarmaManual );
Toast.makeText( getActivity(), "Alarm OK", Toast.LENGTH_SHORT ).show();
}
My Receiver
public class AlarmaManualBroad extends BroadcastReceiver
{
@Override
public void onReceive( Context context, Intent intent )
{
// Toast, notifys, etc.
}
}
Hope u can help me. ^^
Aucun commentaire:
Enregistrer un commentaire