Feu de notification à toutes les 24 heures et à l'heure exacte de 8 h

Je suis en utilisant AlarmManager() à feu de notification et de le répéter toutes les 24 heures.

Mon code est sur onCreate() dans Splash Activité qui tire en premier quand on ouvre l'App. L'utilisateur peut installer l'Application à tout moment. Donc, je veux que lorsque l'Utilisateur installe l'App, Il vérifie pour le moment et puis les feux de Notification à 8 h du matin et de le répéter tous les jours. Je ne veux pas de notification quand quelqu'un ouvre App.

Mon code est comme ci-dessous :

public class Splash extends Activity {
final String WebsiteURL = "http://www.mytestbuddy.com";
String cookie;
@SuppressLint("SimpleDateFormat")
@Override
protected void onCreate(Bundle showSplash) {
//TODO Auto-generated method stub
super.onCreate(showSplash);
setContentView(R.layout.splash);
getWindow().getDecorView().setBackgroundColor(Color.WHITE);
Intent myIntent = new Intent(Splash.this, AlarmReceiver.class);
final PendingIntent pendingIntent = PendingIntent.getBroadcast(
Splash.this, 0, myIntent, 0);
final AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
CookieSyncManager.createInstance(this);
CookieManager cm = CookieManager.getInstance();
cm.setAcceptCookie(true);
CookieSyncManager.getInstance().sync();
if (cm.getCookie("" + WebsiteURL + "") != null) {
cookie = cm.getCookie("" + WebsiteURL + "").toString();
} else {
cookie = null;
}
Thread timer = new Thread() {
public void run() {
try {
sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
if (cookie == null) {
Intent openStartingPoint = new Intent(
"com.MobileWeb.mytestbuddy.Login");
startActivity(openStartingPoint);
} else if (cookie.contains("Premium")) {
Calendar firingCal = Calendar.getInstance();
Calendar currentCal = Calendar.getInstance();
firingCal.set(Calendar.HOUR, 10);
firingCal.set(Calendar.MINUTE, 30);
firingCal.set(Calendar.SECOND, 0);
long intendedTime = firingCal.getTimeInMillis();
long currentTime = currentCal.getTimeInMillis();
if (intendedTime >= currentTime) {
alarmManager.setRepeating(AlarmManager.RTC,
intendedTime, AlarmManager.INTERVAL_DAY,
pendingIntent);
} else {
firingCal.add(Calendar.DAY_OF_MONTH, 1);
intendedTime = firingCal.getTimeInMillis();
alarmManager.setRepeating(AlarmManager.RTC,
intendedTime, AlarmManager.INTERVAL_DAY,
pendingIntent);
}
Intent openStartingPoint = new Intent(
"com.MobileWeb.mytestbuddy.PremiumMain");
startActivity(openStartingPoint);
} else {
Calendar firingCal = Calendar.getInstance();
Calendar currentCal = Calendar.getInstance();
firingCal.set(Calendar.HOUR, 10);
firingCal.set(Calendar.MINUTE, 30);
firingCal.set(Calendar.SECOND, 0);
long intendedTime = firingCal.getTimeInMillis();
long currentTime = currentCal.getTimeInMillis();
if (intendedTime >= currentTime) {
alarmManager.setRepeating(AlarmManager.RTC,
intendedTime, AlarmManager.INTERVAL_DAY,
pendingIntent);
} else {
firingCal.add(Calendar.DAY_OF_MONTH, 1);
intendedTime = firingCal.getTimeInMillis();
alarmManager.setRepeating(AlarmManager.RTC,
intendedTime, AlarmManager.INTERVAL_DAY,
pendingIntent);
}
Intent openStartingPoint = new Intent(
"com.MobileWeb.mytestbuddy.Main");
startActivity(openStartingPoint);
}
}
}
};
timer.start();
}

}

  • Le titre devrait être "Répéter la Notification de tous les jours sur le temps spécifique en Android avec des" Si tout un google et trouver.