2013-10-10 5 views
0

Я вызываю будильник каждые 30 секунд. Это не называется. Что я делаю не так.Почему мой будильник не вызван?

AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE); 
Intent i = new Intent(this, OnAlarmReceiver.class); 
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
PendingIntent pi = PendingIntent 
     .getBroadcast(this, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); 
Calendar cal = Calendar.getInstance(); 
cal.add(Calendar.SECOND, 30); 
mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, cal.getTimeInMillis(), 1000 * 30, pi); 

Мой OnAlarmReceiver

public class OnAlarmReceiver extends BroadcastReceiver { 
@Override 
public void onReceive(Context context, Intent intent) { 
    // PullPendingRequests.acquireStaticLock(context); 
    Toast.makeText(context, "Don't panik but your time is up!!!!.", Toast.LENGTH_LONG).show(); 
    Log.d("Taxeeta:PullPendingRequets", "CallService Location"); 
    context.startService(new Intent(context, DriverService.class)); 
} 
} 

Мои Manifest содержимое для сигнализации и услуг

<service 
     android:name="com.taxeeta.DriverService" 
     android:enabled="true" 
     android:label="@string/app_name" 
     android:screenOrientation="portrait" 
     android:theme="@android:style/Theme.Light.NoTitleBar" /> 

    <receiver 
     android:name="com.taxeeta.support.OnAlarmReceiver" 
     android:exported="true" > 
     <intent-filter> 
      <action android:name="android.intent.action.NOTIFY" /> 
     </intent-filter> 
    </receiver> 
+0

IS OnAlarmReceiver класс внутренний класс некоторой активности? –

+0

Нет, это не так. Его внешний независимый класс. – taxeeta

ответ

0

Fixed, изменив код на, thanks to

Calendar cal = Calendar.getInstance(); 
    cal.add(Calendar.SECOND, 5); 
    AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); 
    Intent notifyintent = new Intent(this, OnAlarmReceiver.class); 
    notifyintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    notifyintent.setAction("android.intent.action.NOTIFY"); 
    PendingIntent notifysender = PendingIntent.getBroadcast(this, 0, notifyintent, 
      PendingIntent.FLAG_UPDATE_CURRENT); 
    am.setInexactRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 20 * 1000, 
      notifysender); 
Смежные вопросы