I\'m trying to give the user a notification each day on a certain time so I use an AlarmManager with a notification. I have this:
public void check_products(
use this Example for reference..
http://androidideasblog.blogspot.in/2011/07/alarmmanager-and-notificationmanager.html
Use This code for Repeating alarm in it..
AlarmManager am = (AlarmManager) MainActivity.this.getSystemService(MainActivity.this.ALARM_SERVICE);
am.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, alarmIntent);
Try like this, it may help you
Intent myIntent1 = new Intent(sign_in.this,MyNotificationService.class);
pendingintent2 = PendingIntent.getService(sign_in.this, 1,myIntent1, 1);
AlarmManager alarmManager1 = (AlarmManager) getSystemService(ALARM_SERVICE);
Calendar calendar1Notify = Calendar.getInstance();
calendar1Notify.setTimeInMillis(System.currentTimeMillis());
calendar1Notify.set(Calendar.HOUR_OF_DAY, 8);
calendar1Notify.set(Calendar.MINUTE, 00);
alarmManager1.set(AlarmManager.RTC_WAKEUP,calendar1Notify.getTimeInMillis(), pendingintent2);
long time24h = 24*60*60*1000;
alarmManager1.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar1Notify.getTimeInMillis(),time24h,pendingintent2);
link For Reference
See above link Your question is Solved .
It could be helpful to mention here. Optimize your app with Doze and app stand by article from android developers blog help you out.
If you need to set alarms that fire while in Doze, use setAndAllowWhileIdle()
or setExactAndAllowWhileIdle().
you can find source here
Call receiver in your manifest file.
Like this
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<receiver android:name="myPackage.AlarmReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
</application>
Or
Try this whole example
MainActivity.java
private PendingIntent pendingIntent;
Intent intent = new Intent(MainActivity.this, AlarmReceiver.class);
pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, intent , 0);
AlarmManager littlefluppy = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
littlefluppy.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 2000, pendingIntent);
AlarmReceiver.java
public class AlarmReceiver extends BroadcastReceiver {
public AlarmReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
// TODO: This method is called when the BroadcastReceiver is receiving
// an Intent broadcast.
Log.e("alram set.....","");
}
}