android 飞行模式 源代码,android 定时进入飞行模式 例子
【实例简介】
【实例截图】
【核心代码】
package com.example.dsgj;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.content.ContentResolver;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.provider.Settings;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
private Button set;
Handler handler=new Handler();
Runnable runnable=new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
//要做的事情
airplane();
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
set = (Button)findViewById(R.id.ok);
set.setOnClickListener(new Button.OnClickListener(){
@SuppressWarnings("deprecation")
public void onClick(View v)
{
EditText time_box = (EditText )findViewById(R.id.time);
// time_box.setText("30");
final String time=time_box.getText().toString();
int num= Integer.parseInt(time);
num=num*1000*60;
final int Time=num;
final String text="手机将在" time "分钟后进入飞行模式!!";
handler.removeCallbacks(runnable);
//Toast提示控件
Toast.makeText(getApplicationContext(), text,
Toast.LENGTH_SHORT).show();
handler.postDelayed(runnable, Time);//每两秒执行一次runnable.
}
});
}
public void airplane()
{
ContentResolver cr = getContentResolver();
if(Settings.System.getString(cr,Settings.System.AIRPLANE_MODE_ON).equals("0")){
//获取当前飞行模式状态,返回的是String值0,或1.0为关闭飞行,1为开启飞行
//如果关闭飞行,则打开飞行
Settings.System.putString(cr,Settings.System.AIRPLANE_MODE_ON, "1");
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
sendBroadcast(intent);
}else{
//否则关闭飞行
Settings.System.putString(cr,Settings.System.AIRPLANE_MODE_ON, "0");
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
sendBroadcast(intent);
}
handler.removeCallbacks(runnable);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.tuichu) {
this.finish();
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
}
}
android 飞行模式 源代码,android 定时进入飞行模式 例子相关推荐
- android 网络调试 源代码,Android源代码调试环境搭建
我们在调试Android应用程序的时候,有时候遇到一些莫名其妙的问题,因此我们需要查看Android内部是如何调用的.我们都知道Android是一个伟大的开源项目,因此debug的时候肯定是支持源代码 ...
- android人脸识别源代码,Android自带的人脸识别
1.Android自带的人脸识别Android自带的人脸识别只能识别出人脸在画面中的位置,中点,眼间距,角度等基本特性,提供给拍照性质的应用使用.从基本功能中不能得出明显的特征数据 2.底层库支持ex ...
- android摇骰子源代码,Android实现微信摇骰子游戏
过年怎么可以不玩红包娱乐一下呢,微信里的摇骰子大小和石头剪刀布就是不错的游戏方式. 使用Java的Random函数很容易实现,以骰子为例: 1.骰子摇动的动画,使用animation-list帧动画实 ...
- android一键拨号 源代码,android 使用意图(Intent)实现一键拨号实例
本文打算实现具有一个一键拨号功能的 APP 1.布局文件activity_main.xml xmlns:tools="http://schemas.android.com/tools&quo ...
- android 红包雨源代码,Android 红包雨效果自定义控件
WX20201231-181616@2x.png 思路:利用Path绘制动画轨迹,再使用PathMeasure获取轨迹中的坐标位置实时改变view的坐标完成红包动画. 封装一个红包容器view用于管理 ...
- android英语字典(源代码),android英语字典(内含源码哦)
英文词典是手机中经常使用的应用.因此,在本文将结合Android来讨论如何实现一个Android版的英文词典.实现英文词典的方法很多.在本文使用了SQLite数据库来保存英文单词信息.系统通过SQLi ...
- android选项菜单源代码,Android应用程序----UI界面控件(菜单menu)
菜单是应用程序中非常重要的组成部分,能够在不占用界面空间的前提下,为应用程序提供了统一的功能和设置界面,并为程序开发人员提供了易于使用的编程接口 Android系统支持三种菜单 选项菜单(Option ...
- android拨号器源代码,android拨号器...
写完这个拨号器,感慨良多.因刚入门android开发,写的过程,可谓九曲18弯,从搭建开发环境,到完成此拨号器,问题颇多 呵呵,写完这个拨号器,我对android的开发环境算是理解.入门了! ... ...
- android中计算机源代码,Android源代码查看途径
作为一个android coder,多阅读android源码对提高android开发水平是很有帮助的,那么我们可以通过哪些途径查看android源码呢 1.如果你能够FQ的话可以去android官网查 ...
- android北京地铁源代码,Android自定义View实现地铁显示牌效果
本文实例为大家分享了Android地铁显示牌的具体代码,供大家参考,具体内容如下 预览效果 目录 SubwayBoardView.java 代码 public class SubwayBoardVie ...
最新文章
- Oracle数据库的语句级读一致性
- OTN交换amp;P-OTN有效减少100G网络成本(一)
- python opencv imread()函数 (从文件加载图像)
- 关于PHP程序员解决问题的能力
- linux 字符串转数字排序,linux中sort命令排序功能实现方法
- Web框架——Flask系列之蓝图Blueprint(二十一)
- 计算机网络df例题,计算机网络期末试题北交.doc
- Linux Oracle服务启动停止脚本与开机自启动
- 华为机试HJ52:计算字符串的距离(动态规划)
- java每轮排序结果,冒泡排序及其优化java
- 海湾监控计算机,海湾GST-DH9300电气火灾监控图形显示系统软件
- Callable 接口控制线程
- amos看拟合度在哪里看_AMOS分析技术:结构方程模型的拟合度评价指标
- 证件照换底,红白蓝底随机换(附:一寸二寸证件照制作)
- 从阿里云迁移域名至 Amazon Route 53 帮你了解域名迁移
- ceph搭建及使用详解
- 科大星云诗社动态20210513
- rk3288编译android,RK3288 源码编译Android 7.1.2 自动编译
- 印度软件和中国软件工程师_如何成为印度的软件工程师?
- 【JZOJ 省选模拟】多项式(poly)