setExact方法无法处理我的项目
Log.d("Alarm","Fire");
AlarmManagerBroadcastReceiver中的在1分钟后没有出现!
public class MainActivity extends AppCompatActivity {
.
.
@Override
protected void onCreate(Bundle savedInstanceState) {
.
.
Calendar alarm = Calendar.getInstance();
alarm.setTimeInMillis(System.currentTimeMillis());
alarm.add(Calendar.MINUTE,1);
Intent myIntent = new Intent(MainActivity.this, AlarmManagerBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, myIntent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarm.getTimeInMillis(), pendingIntent);
.
.
}
}
AlarmManagerBroadcastReceiver:
public class AlarmManagerBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("Alarm","Fire");
}
}
我试图扩展BroadcastReceiver而不是WakefulBroadcastReceiver。我还尝试设置diffrenet硬编码时间。然而,没有任何作用。
请帮忙
答案 0 :(得分:0)
此link(调度重复警报)可以帮助您。你必须添加
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
<receiver android:process=":remote" android:name=".AlarmManagerBroadcastReceiver"></receiver>