Täglich lokale Benachrichtigung durch die Einstellung von Uhrzeit android
Rufe ich TimePickerDialog und basiert auf der, die Benutzer die Zeit einstellen, basierend auf der Zeit, die Benutzer tägliche Benachrichtigung in der Statusleiste.
Ich getan haben, schreiben Sie folgenden code,
Zunächst rufe ich das Dialogfeld, indem Sie folgenden code
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case TIME_DIALOG_ID:
//set time picker as current time
return new TimePickerDialog(this, timePickerListener, hour, minute,
true);
}
return null;
}
Listener-Methode ist
private TimePickerDialog.OnTimeSetListener timePickerListener = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minutes) {
System.out.println("TimePicker: OnTimeSetLister: hour is "+hourOfDay+": mins"+minutes);
DailyNotification.registerAlarm(SubscribeMsgTime.this, hourOfDay, minutes);
}
};
habe ich verwendet BroadCastRecevier in AndroidMenifiast.xml Datei
<receiver
android:name="com.example.easynotification.DailyNotification"
android:process=":remote" >
<intent-filter>
<action android:name="com.example.easynotification.DAILY_NOTIFICATION" />
<action android:name="android.intent.action.EXTERNAL_APPLICATIONS_AVAILABLE" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Und die letzten DailyNotification (BroadcastReceiver) Klasse ist unten
public class DailyNotification extends BroadcastReceiver {
public static void registerAlarm(Context paramContext, int mHour, int mMin) {
Calendar calendar = Calendar.getInstance();
if (calendar.get(Calendar.HOUR_OF_DAY) >= mHour) {
calendar.add(Calendar.DATE, 1);
}
calendar.set(Calendar.HOUR_OF_DAY, mHour);
calendar.set(Calendar.MINUTE, mMin);
calendar.set(Calendar.SECOND, 00);
PendingIntent localPendingIntent = PendingIntent.getBroadcast(
paramContext, 22341, new Intent(
"com.example.easynotification.DAILY_NOTIFICATION"),
PendingIntent.FLAG_UPDATE_CURRENT);
((AlarmManager) paramContext.getSystemService("alarm")).setRepeating(1,
calendar.getTimeInMillis(), 24 * 60 * 60 * 1000,
localPendingIntent);
System.out.println("Alarm Registered on Hour :- "+mHour+" : Min "+mMin);
}
private void showNotification(Context paramContext) {
try {
Notification localNotification = new Notification(R.drawable.ic_launcher,
paramContext.getString(R.string.app_name),
System.currentTimeMillis());
localNotification.flags = (0x10 | localNotification.flags);
//PendingIntent that will start the EnterWeightActivity
Intent intent = new Intent(paramContext, MainActivity.class);
PendingIntent localPendingIntent = PendingIntent.getActivity(
paramContext, 0, intent, 0);
localNotification.setLatestEventInfo(paramContext, "hi", "Amit",
localPendingIntent);
//Retrieve a NotificationManager to show the notification
((NotificationManager) paramContext
.getSystemService("notification")).notify(0,
localNotification);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onReceive(Context paramContext, Intent paramIntent) {
if (paramIntent.getAction().equals(
"com.example.easynotification.DAILY_NOTIFICATION"))
showNotification(paramContext);
}
}
aber alles ist in Ordnung, die Dialogfeld öffnen Zeit ist die Registrierung aber eine Benachrichtigung oder onReceive-Methode nicht aufrufen bitte jemand mir helfen
InformationsquelleAutor Siddhpura Amit | 2013-09-27
Du musst angemeldet sein, um einen Kommentar abzugeben.
Weiß ich nicht mehr von deinem code, aber ich denke, Sie wollen Holen Sie sich täglich die Benachrichtigung basierend auf der Zeit, die man von TimePickerDialog also mein Vorschlag ist, dass in diesem Beispiel wird Ihnen helfen,
http://karanbalkar.com/2013/07/tutorial-41-using-alarmmanager-and-broadcastreceiver-in-android/
Hallo das ist in Ordnung, aber ich möchte, um den Dienst zu beenden, wenn die Benachrichtigung geöffnet wird ..wie kann ich das tun?
InformationsquelleAutor