public class AirPlaneModeActivity extends Activity {
Button b;
TimePicker tp;
Calendar cal;
AlarmManager am ;
PendingIntent pi;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b = (Button)findViewById(R.id.button1);
tp = (TimePicker)findViewById(R.id.timePicker1);
cal = Calendar.getInstance(Locale.getDefault());
am = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
tp.setIs24HourView(true);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
cal.set(Calendar.HOUR_OF_DAY,tp.getCurrentHour());
cal.set(Calendar.MINUTE,tp.getCurrentMinute());
cal.set(Calendar.SECOND,0);
}
});
pi = PendingIntent.getBroadcast(this, 0, setAPM(), 0);
am.set(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(),pi);
}
public Intent setAPM(){
boolean isEnabled = Settings.System.getInt(
getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, 0) == 1;
// toggle airplane mode
Settings.System.putInt(getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1);
// Post an intent to reload
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intent.putExtra("state", !isEnabled);
return intent;
}
}
我想在设定的时间更改飞机模式,这是我从时间选择器获得的。
然后我将时间选择器的时间设置为女巫的日历,我得到了alarmmanager.set
方法的时间,但它没有做任何事情。
我在互联网上到处看,但我什么也没找到。我在stackoverflow上找到了这篇文章,但没有答案(抱歉我的英语不好)谢谢你的回答