编写GPS代码的时候总是要做这个判断,干脆封装成一个函数,随用随取。public boolean isGpsEnabled(Context context)
{
LocationManager locationManager =
((LocationManager)context.getSystemService(Context.LOCATION_SERVICE));
List<String> accessibleProviders = locationManager.getProviders(true);
return accessibleProviders != null && accessibleProviders.size() > 0;
}类似的wifi是否打开
public boolean isWifiEnabled(Context context)
{
ConnectivityManager mgrConn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
TelephonyManager mgrTel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
return ((mgrConn.getActiveNetworkInfo()!=null && mgrConn.getActiveNetworkInfo().getState()==NetworkInfo.State.CONNECTED)
|| mgrTel.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS)
}
网络连接是否好用
public static boolean isNetworkConnected(Context context){
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo network = cm.getActiveNetworkInfo();
if(network != null){
return network.isAvailable();
}
return false;
} 蓝牙的没用过,有用过的,跟个帖子,把蓝牙的搞定。还有什么其他的大家也总结一下,收藏此帖就当索引了。
{
LocationManager locationManager =
((LocationManager)context.getSystemService(Context.LOCATION_SERVICE));
List<String> accessibleProviders = locationManager.getProviders(true);
return accessibleProviders != null && accessibleProviders.size() > 0;
}类似的wifi是否打开
public boolean isWifiEnabled(Context context)
{
ConnectivityManager mgrConn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
TelephonyManager mgrTel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
return ((mgrConn.getActiveNetworkInfo()!=null && mgrConn.getActiveNetworkInfo().getState()==NetworkInfo.State.CONNECTED)
|| mgrTel.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS)
}
网络连接是否好用
public static boolean isNetworkConnected(Context context){
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo network = cm.getActiveNetworkInfo();
if(network != null){
return network.isAvailable();
}
return false;
} 蓝牙的没用过,有用过的,跟个帖子,把蓝牙的搞定。还有什么其他的大家也总结一下,收藏此帖就当索引了。
解决方案 »
- 为什么在一个自定义view里面popupWindow.showAsDropDown方法Y值不能固定
- 在线等高手:关于Google Apis问题,谢谢 !!!
- 开机自动启动问题
- 关于android 9patch 图原理
- 全志A10 android4.1编译出错
- 请问有谁参加谷歌的开发者大会?
- 关于media设置和闹铃的问题,求大神帮忙解决
- 有谁能帮忙,详细分析一下andoid中的AccessibilityEvent机制,我看了好多天,没看清楚,请教大神
- 去掉应用title引起空指针错误
- 为什么SQLite里的数据用ListView在Fragment里显示不出来
- RelativeLayout在ALIGN_PARENT_RIGHT后设置setMargins无效,求指教
- LocationManager.GPS_ENABLED_CHANGE_ACTION 监听不到
Android蓝牙开发浅谈
http://www.eoeandroid.com/thread-37575-1-1.html
是通过WifiManager来判断wifi的状态的