2017-03-03 16 views
1
  • 私は マーケティングのためにそこにアクセスするとき毎回レポートを提出する必要がある学校のアプリケーションを作成しています。訪問が の場合、訪問が失敗した場合は問題は発生しません。次に 次の訪問のために会議のスケジュールを変更する必要があります。私は日付を設定し、 時間は私の次の会議のためにそれは 通知を送信すると、私は リマインダーを得ることができるので、その時に警告する必要があります早朝に私に思い出させる必要があります。ここでレポート活動のための私のコードは私に簡単な方法で通知を受け取ったときに鳴るように通知するように設定する

    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.を助けてくださいです私が私の予定を変更するときそれが取得

+0

を試しアラームに 次の日の朝に私を通知しなければならない作業。 [android-notification-sound](http://stackoverflow.com/questions/15809399/android-notification-sound) –

+0

特定の学校の名前と日時を提出する必要があります。私のコードを確認してくださいアラームで私に思い出させるべきです – Sushil

+0

上記のコードから複数の通知を私のステータスバーに複数の通知を作成する方法を教えてください。同じデータを複数回取得しています – Sushil

答えて

0

はあなたを助けるかもしれない、この質問をチェックするこの

.setVibrate(new long[]{0, 2000, 500, 2000, 500, 2000, 500}); 
    try { 
      Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.bells_bells_bells); //your sound file name from Raw folder 
      .setSound(uri); 
      } catch (Exception e) { 
       e.printStackTrace(); 
     }   
+0

どのように私は私の複数の通知上記のコードからのステータスバー私は同じデータを複数回取得しています – Sushil

関連する問題