마케팅을 위해 방문 할 때마다 매번 보고서를 제출해야하는 학교 응용 프로그램을 만들고 있습니다. 방문이 일 경우 방문이 실패한 경우 문제가되지 않습니다. 다음 방문을 위해 회의 일정을 다시 잡아야합니다. 내가 날짜를 정했을 때 내 다음 회의 시간에 이른 아침에 님이 알림을 보내는 것을 상기시켜야하고 그 때 알림을 보내야 알리미를 얻을 수 있습니다. 여기에 보고서 활동에 대한 내 코드는 간단한 방법으로 나에게알림을 받으면 알림이 울리도록 설정하고 싶습니다.
private void sendNotificationDetailsTwo() { /* Calendar firingCal = Calendar.getInstance(); Calendar currentCal = Calendar.getInstance(); firingCal.set(Calendar.HOUR_OF_DAY, 8); // At the hour you wanna fire firingCal.set(Calendar.MINUTE, 30); // Particular minute firingCal.set(Calendar.SECOND, 0); // particular second Long intendedTime = firingCal.getTimeInMillis(); if (firingCal.compareTo(currentCal) < 0) { firingCal.add(Calendar.DAY_OF_MONTH, 1); } else { for (int i = 0; i < 10; ++i) { Intent newIntentTwo = new Intent(Report_Activity.this, MyReceiver.class); final int intent_id_two = (int) System.currentTimeMillis(); newIntentTwo.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); Bundle bundle = new Bundle(); bundle.putString("date", str_view_date); bundle.putString("time", str_view_time); bundle.putString("school_name", str_show_school_name); bundle.putInt("intent_id", intent_id_two); newIntentTwo.putExtras(bundle); AlarmManager alarmManager = (AlarmManager) Report_Activity.this.getSystemService(Report_Activity.this.ALARM_SERVICE); PendingIntent pendingIntent = PendingIntent.getBroadcast(Report_Activity.this, intent_id_two, newIntentTwo, PendingIntent.FLAG_ONE_SHOT); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, intendedTime, AlarmManager.INTERVAL_DAY, pendingIntent); } }*/ /*alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmIntent = new Intent(context of current file, AlarmReceiver1.class); // AlarmReceiver1 = broadcast receiver pendingIntent = PendingIntent.getBroadcast( Menu.this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); alarmIntent.setData((Uri.parse("custom://"+System.currentTimeMillis()))); alarmManager.cancel(pendingIntent); Calendar alarmStartTime = Calendar.getInstance(); Calendar now = Calendar.getInstance(); alarmStartTime.set(Calendar.HOUR_OF_DAY, 8); alarmStartTime.set(Calendar.MINUTE, 00); alarmStartTime.set(Calendar.SECOND, 0); if (now.after(alarmStartTime)) { Log.d("Hey","Added a day"); alarmStartTime.add(Calendar.DATE, 1); } alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, alarmStartTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); Log.d("Alarm","Alarms set for everyday 8 am.");*/ Calendar firingCal = Calendar.getInstance(); Calendar now = Calendar.getInstance(); firingCal.set(Calendar.HOUR_OF_DAY,15); firingCal.set(Calendar.MINUTE,25); firingCal.set(Calendar.SECOND,0); while(now.getTimeInMillis()>firingCal.getTimeInMillis()){ firingCal.add(Calendar.DATE,1); } Intent myInten = new Intent(Report_Activity.this,MyReceiver.class); final int intent_id_two = (int) System.currentTimeMillis(); myInten.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); Bundle bundle = new Bundle(); bundle.putString("date", str_view_date); bundle.putString("time", str_view_time); bundle.putString("school_name", str_show_school_name); bundle.putInt("intent_id", intent_id_two); myInten.putExtras(bundle); //final int intent_id_two = (int) System.currentTimeMillis(); PendingIntent myPendingIntent = PendingIntent.getBroadcast(Report_Activity.this,intent_id_two,myInten,PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager)Report_Activity.this.getSystemService(Report_Activity.ALARM_SERVICE); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,firingCal.getTimeInMillis(),2000,myPendingIntent); }
MyAlarmService.java
public class MyAlarmService extends Service { private NotificationManager notificationManager; @Nullable @Override public IBinder onBind(Intent intent) { return null; } @Override public void onCreate() { super.onCreate(); boolean alarm =(PendingIntent.getBroadcast(this,0,new Intent("Alarm"),PendingIntent.FLAG_NO_CREATE)==null); if(alarm){ Intent mintent =new Intent("Alarm"); PendingIntent mpendingIntent = PendingIntent.getBroadcast(this,0,mintent,0); Calendar mcalender = Calendar.getInstance(); mcalender.setTimeInMillis(System.currentTimeMillis()); mcalender.add(Calendar.SECOND,3); AlarmManager malarmmanager = (AlarmManager)getSystemService(ALARM_SERVICE); malarmmanager.setRepeating(AlarmManager.RTC_WAKEUP,mcalender.getTimeInMillis(),6000,mpendingIntent); } } }
MyReceiver.java
public class MyReceiver extends BroadcastReceiver { int MID = 0; int m = (int) ((new Date().getTime()/1000L) % Integer.MAX_VALUE); String date, time, school_name; PendingIntent pendingIntent; int intent_id; @Override public void onReceive(Context context, Intent intent) { // long when = System.currentTimeMillis(); Bundle bundle = intent.getExtras(); date = bundle.getString("date"); time = bundle.getString("time"); school_name = bundle.getString("school_name"); intent_id = bundle.getInt("intent_id"); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(context, MainActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); //final int intent_id = (int) System.currentTimeMillis(); pendingIntent = PendingIntent.getActivity(context, intent_id, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(context) .setContentTitle("Notification From Dextro") .setContentText("Meeting Schedule at " + school_name + " on " + date + " and time is " + time) .setSmallIcon(R.mipmap.dextro_customerlogo) .setContentIntent(pendingIntent) .setAutoCancel(true) .setSound(alarmSound) .setTicker("Notification From Dextro") .setStyle(new NotificationCompat.BigTextStyle() .bigText("Meeting Schedule at " + school_name + " on " + date + " and time is " + time)) .setVibrate(new long[]{100, 100, 100, 100}); notificationManager.notify(m, builder.build()); MID++; } }
1. 도와주세요입니다 내 일정을 변경할 때 그것을 얻을
을 시도 알람 다음 날 아침에 저를 통보해야 작업 할 수 있습니다. [android-notification-sound] (http://stackoverflow.com/questions/15809399/android-notification-sound) –
특정 학교 이름과 날짜 및 시간으로 제출 일정을 정하는시기를 확인하고 다음 날 아침에 알람 코드를 확인하시기 바랍니다 내 코드를 확인하십시오 – Sushil
하나 이상의 정보를 내 상태 표시 줄에 여러 개의 알림을 만들 수 있습니다 위의 코드에서 여러 번 같은 데이터를 얻고 있습니다. – Sushil