2016-04-27 6 views
-1
public class SchedulerSetupReceiver extends WakefulBroadcastReceiver { 
    private static final String APP_TAG = "com.hascode.android"; 

    private static final int EXEC_INTERVAL = 10 * 1000; 
    DBhelper dbhelper; 

    @Override 
    public void onReceive(final Context ctx, Intent intent) { 
     Log.d(APP_TAG, "SchedulerSetupReceiver.onReceive() called"); 
     dbhelper = new DBhelper(ctx); 

     String[] ID = dbhelper.FetchAllID(); 
     String[] time = dbhelper.FetchAlltime(); 
     ArrayList<PendingIntent> intentArray = new ArrayList<PendingIntent>(); 

     AlarmManager alarmManager = (AlarmManager) ctx 
       .getSystemService(Context.ALARM_SERVICE); 

     Calendar calendar = Calendar.getInstance(); 
     calendar.set(calendar.HOUR_OF_DAY, 16); 
     calendar.set(calendar.MINUTE, 22); 
     calendar.set(calendar.SECOND, 0); 
     calendar.set(calendar.MILLISECOND, 0); 
     long sdl = calendar.getTimeInMillis(); 

     for (int k = 0; k < ID.length; k++) { 

      intent = new Intent(ctx, SchedulerEventReceiver.class); 
      // Loop counter `i` is used as a `requestCode` 
      PendingIntent pendingIntent = PendingIntent.getBroadcast(ctx, k, 
        intent, 0); 
      // Single alarms in 1, 2, ..., 10 minutes (in `i` minutes) 

      alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, sdl, 
        pendingIntent); 

      intentArray.add(pendingIntent); 

     } 

    } 

これはアラーム用のコードです。私はアラームを特定の時間に設定したいですが時間が完了するとトリガーしません。私はカレンダーを使用しています。私は分20時間16中とで追加が、持っているため分Pmとそのデバイスの時間が4.20 Pmは、私はあなたに忘れてしまったと思います私はこのアンドロイドで時刻を設定するとアラームが鳴りません

alarmManager.set(AlarmManager.RTC_WAKEUP, sdl, 
       pendingIntent); 
+0

**正確な時刻にアラームが届かないと不平を言っていますか? –

+0

はいその配達されていません私はどこで間違いをしているのかわかりません –

+0

**配達されていない**または**正確な時間**に配達されていませんか? –

答えて

0

をやって何を教えてください達したときにトリガされません今日の何日かをカレンダーに伝えてください。

calendar.setTimeInMillis(System.currentTimeMillis()); 
+0

ShaenはTime Multiple時間を設定できますか? –

+0

はい、同じPendingIntentを使用して、期限が到来すると時刻を再設定できます。またはあなたは一度に複数の警告を設定することができます(それぞれ別々のPendingIntentを使用して) –

+0

yaarあなたのコードに問題があります –

0

を試してみて間違い

+0

日付の日付=新しい日付(); \t \t calendar.setTime(date);それは大丈夫です –

+0

calendar.setTimeInMillis(System.currentTimeMillis()); \t \t calendar.set(calendar.HOUR_OF_DAY、16); \t \t calendar.set(calendar.MINUTE、57); \t \t calendar.set(calendar.SECOND、0); \t \t calendar.set(calendar.MILLISECOND、0); \t \t long sdl = calendar.getTimeInMillis(); 私は今これを使用していますが、まだはい、それは私はそれは私がチェックしてみましょう –

0

ブロードキャスト受信者がマニフェストに登録されていることを確認してください。

<receiver android:name=".SchedulerEventReceiver"/> 

また、アラームの許可も与えてください。

<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/> 
+0

を起動しませこの –

+0

について確信している –

+0

NOそのあなたのアラームがまったく設定取得されている場合 –

関連する問題