Note that there are some explanatory texts on larger screens.

plurals
  1. POSet airplanemode at a specific time
    text
    copied!<pre><code>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; } } </code></pre> <p>I want to change the airplanemode at the setted time, that I get from a timepicker. </p> <p>Then I set the time from the timepicker into a calender from witch I get the time for the <code>alarmmanager.set</code> Method but it doesn't do anything. </p> <p>I watch all over the internet but I didn't found anything. I found this post on <a href="https://stackoverflow.com/questions/9136924/timed-airplane-mode-for-android">stackoverflow</a> but without answer (Sorry for my bad english) Thanks for your answers</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload