android报警应用程序 - 接收器未启动

时间:2013-08-27 20:01:54

标签: java android broadcastreceiver

我一直试图做一个定时通知而它只是不起作用,帮忙?

设置闹钟:

 Intent intent = new Intent(context, MyAlarmReceiver.class);
         PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent,0);

          AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
          alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent);  //calendar is declared and taking it's values from a time picker

接收器:

   public class MyAlarmReceiver extends BroadcastReceiver
{

    @Override
    public void onReceive(Context context, Intent intent)
    {

       Log.wtf("ddd", "IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII");

       Intent service1 = new Intent(context, MyAlarmService.class);
       context.startService(service1);



    }   
}

清单:

  <receiver android:name="MyAlarmReceiver" >
        <intent-filter>
            <action android:name="REFRESH_THIS" />
        </intent-filter>
    </receiver>

1 个答案:

答案 0 :(得分:0)

您是否在清单中添加了闹钟设置权限?

SET_ALARM

"com.android.alarm.permission.SET_ALARM"