Android(判断wifi是否开启,手机屏幕状态,sdcard是否被拔出,设置全屏)
来源:互联网 发布:网络监视器 编辑:程序博客网 时间:2024/05/22 22:29
工作中遇到的问题要注意总结,我在工作中遇到了问题,现在抽空简单整理一下;
第一个问题:判断手机当前上网用的是sim卡还是wifi,我写了一个封装的方法,以后可以拿来用:
/** * check the internet is * mobile or wifi * add by wangxianming * in 2012-03-22 */ private boolean checkWifi() { boolean isWifiConnect = true; ConnectivityManager cm = (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
//check the networkInfos numbers NetworkInfo[] networkInfos = cm.getAllNetworkInfo(); for (int i = 0; i<networkInfos.length; i++) { if (networkInfos[i].getState() == NetworkInfo.State.CONNECTED) { if(networkInfos[i].getType() == cm.TYPE_MOBILE) { isWifiConnect = false; } if(networkInfos[i].getType() == cm.TYPE_WIFI) { isWifiConnect = true; } } } return isWifiConnect; }
第二个例子:判断当前的手机屏幕是否开启了旋转屏幕这个选项:
/** * ACCELEROMETER_ROTATION---->explain: * * Control whether the accelerometer will be * used to change screen orientation. * If 0, it will not be used unless explicitly * requested by the application; * if 1, it will be used by default * unless explicitly disabled by the application. * Constant Value: "accelerometer_rotation" */ systemGravity = Settings.System.getInt(this.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION);//1 is open;0 is close;
第三个是在代码中注册监听内存卡状态的广播:
IntentFilter intentFilter=new IntentFilter); intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED); intentFilter.addAction(Intent.ACTION_MEDIA_EJECT); intentFilter.addAction(Intent.ACTION_MEDIA_REMOVED); intentFilter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL); registerReceiver(sdcardListener,intentFilter);
有registerReceiver()注册广播,就有unregisterReceiver()方法,他们是成对出现的。
如果在onCreate()方法中注册广播,就在onDestroy()方法中释放。
如果在onResume()方法中注册广播,就在onPause()方法中释放。
在代码中写个内部类的广播:
private final BroadcastReceiver sdcardListener=new BroadcastReceiver() {public void onReceive(Context context, Intent intent) {Toast.makeText(SummaryAppMainActivityActivity.this, R.string.sd_removed, 2000).show();} };
第四个是全屏的设置:写一个简单的方法中;
//set the activity is fullScreen private void setFullScreen() {misFullscreen = !misFullscreen;if (misFullscreen) {getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);} else {getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);}}今天先整理这么少吧,抽空把知识串联一下!呵呵,睡觉了,下次见!今天参加移动语音开发者大会,见到了柳传志和李开复雷军没有到场,有点遗憾。呵呵,有点收获,听了他们现场的访谈!
- Android(判断wifi是否开启,手机屏幕状态,sdcard是否被拔出,设置全屏)
- Android(判断wifi是否开启,手机屏幕状态,sdcard是否被拔出,设置全屏)
- Android(判断wifi是否开启,手机屏幕状态,sdcard是否被拔出,设置全屏)
- Android中判断Wift是否开启,手机屏幕状态,sdcard是否被拔出,设置全屏
- Android 判断开启网络,wifi是否可用
- Android 如何判断设备是否联网以及WIFI 是否开启
- Android判断网络是否断开(WIFI 状态)--ConnectivityManager
- 判断网络是否,gps,wifi是否开启
- android判断是否连接wifi和网络状态的判断
- 判断SDCARD扫描状态和是否存在,网络是否可用
- DELPHI判断是否连网(网线是否被拔出)
- Android判断手机屏幕是否亮着
- 判断手机屏幕是否旋转
- android 判断 sdcard 是否是 emulated
- 判断是否有SDCard
- 判断sdcard是否存在
- Android 判断是否联wifi
- Android 判断wifi是否链接
- iOS的视图深入浅出
- poj 1192
- Spring的注入方式详解
- [原创]美工必备小工具《屏幕颜色拾取器》
- at&a汇编
- Android(判断wifi是否开启,手机屏幕状态,sdcard是否被拔出,设置全屏)
- Ubuntu 11.10更新源地址列表
- vb源码
- 什么叫做“假学习”?
- makefile双冒号规则
- Windows File Junctions, Symbolic Links and Hard Links
- svn switch命令使用方法记录
- VBA小知识点
- VC 使用ADO连接数据库的问题!error C2059: 语法错误 : “<L_TYPE_raw>”