工作中遇到的问题要注意总结,我在工作中遇到了问题,现在抽空简单整理一下;
第一个问题:判断手机当前上网用的是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);
}
}
今天先整理这么少吧,抽空把知识串联一下!呵呵,睡觉了,下次见!
今天参加移动语音开发者大会,见到了柳传志和李开复雷军没有到场,有点遗憾。呵呵,有点收获,听了他们现场的访谈!
分享到:
相关推荐
// suffix:需要选择的文件后缀,比如需要选择wav、mp3文件的时候设置为".wav;.mp3;",注意最后需要一个分号(;) // images:用来根据后缀显示的图标资源ID。 // 根目录图标的索引为sRoot; // 父目录的索引为...
一段详细的往手机内存和手机sdcard卡上面存储数据的代码,作者对里面的功能进行了封装,在实际的开发项目中可以直接拿来用。
如何在 android 模拟器中使用SDCard
Android获取sdcard信息 文档
Android应用源码SdCard读写文件实例
获取外置SDcard路径,进行创建,写入,读取,删除操作。
Android模拟器sdcard操作 ,帮助我们更好学Android系统开发
具体介绍了android中sdcard的读写操作步骤和具体的实现过程,介绍了sdcard的应用等
android应用开发中关于SDCard读写操作的实例代码,在下载学习SDCard操作中,碰到很棘手的问题了。不过最后还在我的坚持下成功了,
android 写入SDcard 文件,通俗易懂,适合初学者
Android应用源码SdCard读写文件实例.zip
android手机外置SDcard(TF卡)获取方法,非内置sdcard!
Android数据存储之Sdcard,Android数据存储之Sdcard,自己写的简单例子,需要的可以参考一下。
android开发实例-sdcard文件读写 WIFI检测、下载文件等 开发环境:JAVA SDK1.7及android最新的开发包
android 默认安装apk 到sdcard tf 卡
android外部存储文件操作,实现对sdcard上的文件进行操作
一个关于文件操作的静态工具类 实现手机SD卡目录或文件的拷贝 移动 删除 递归 Demo中有详细注释 在进行Demo测试时 建议先把测试的文件备份一下在测试 否则删除就找不回了 具体可见我博客...实现手机SD卡目录或文件的...
Android数据存储(内置sdcard)案例1
真正实现android webview自身下载文件,并自动保存到SDCARD上,静默下载哦。