1 // 飛行模式
2 protected void offLine(boolean setAirPlane) {
3 Settings.System.putInt(getContentResolver(),
4 Settings.System.AIRPLANE_MODE_ON, setAirPlane ? 1 : 0);
5 Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
6 intent.putExtra("TestCode", "ellic");
7 sendBroadcast(intent);
8
9 }
2 protected void offLine(boolean setAirPlane) {
3 Settings.System.putInt(getContentResolver(),
4 Settings.System.AIRPLANE_MODE_ON, setAirPlane ? 1 : 0);
5 Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
6 intent.putExtra("TestCode", "ellic");
7 sendBroadcast(intent);
8
9 }
我们可以通过AirPlaneModeOn = Settings.System.getInt(mContext.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) ==1? true:false;来判断手机是否处于飞行模式。
然后分析下Android编程中调用系统程序的方法,调用系统程序最方便的就是直接通过Intent来激活,Intent真是个好东西,有空要再琢磨琢磨。用几个例子说明一下:
1、调用系统邮件程序
- final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);//建立Intent对象
- emailIntent.setType(“plain/text”);//设置文本格式
- emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{}); //设置对方邮件地址
- emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, “Hello World!”);//设置标题内容
- emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, “It is body-Hello World!”);//设置邮件文本内容
- startActivity(Intent.createChooser(emailIntent, “Sending mail…”));//启动一个新的ACTIVITY
- Uri uri = Uri.parse("smsto:0800000123");
- Intent it = new Intent(Intent.ACTION_SENDTO, uri);
- it.putExtra("sms_body", "The SMS text");
- startActivity(it);
- Intent intent = new Intent();
- intent.setClassName(“com.android.alarmclock”, “com.android.alarmclock.AlarmClock”);
- startActivity(intent);