判断GPS、网络是否开启
判断GPS、网络是否开启
1.判断GPS打开与否,没有打开则打开GPS
private void initGPS(Context context) {
LocationManager locationManager = (LocationManager) context
.getSystemService(Context.LOCATION_SERVICE);
// 判断GPS模块是否开启,如果没有则开启
if (!locationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setMessage("请打开GPS");
dialog.setPositiveButton("确定", new android.content.DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface arg0, int arg1) {
// 转到手机设置界面,用户设置GPS
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(intent, 0); // 设置完成后返回到原来的界面
}
});
dialog.setNeutralButton("取消", new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
arg0.dismiss();
}
});
dialog.show();
}
}
判断网络是否开启
private void initInternet(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
boolean isConnect = cm.getActiveNetworkInfo().isAvailable();
if (!isConnect) {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setMessage("请打开网络或连接wifi");
dialog.setPositiveButton("确定", new android.content.DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface arg0, int arg1) {
// 转到手机设置界面,用户设置GPS
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(intent, 0); // 设置完成后返回到原来的界面
}
});
dialog.setNeutralButton("取消", new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
arg0.dismiss();
}
});
dialog.show();
}
}
判断GPS、网络是否开启的更多相关文章
- Android判断GPS是否开启和强制帮用户打开GPS
引子:在我们的应用为用户提供定位服务时,通常想为用户提供精确点的定位服务,这是需要用户配合的.我们必须先检测用户手机的GPS当前是否打开,若没打开则弹出对话框提示.用户若不配合我们也没办法,只能采用基 ...
- 判断GPS是否开启&转到设置GPS界面
/** * 判断GPS是否开启,GPS或者AGPS开启一个就认为是开启的 * @param context * @return true 表示开启 */ public static final boo ...
- 判断网络是否连接 和 判断GPS是否连接
//判断网络是否连接 public static Boolean isNetworkEnabled(Context context){ int status=-1 //设置默认连接的状态为-1 Co ...
- Android 判断wifi和4G网络是否开启
public boolean isWifiAvailable() { ConnectivityManager connectivityManager = (ConnectivityManager) g ...
- XAMARIN +VS2015 ANDROID 开发判断gps 是否打开。
在获取位置的时候首先要判断gps是否打开,如果没有打开就要提示打开,当然最友好的就是直接调转到打开界面. LocationManager alm = (LocationManager)this.Get ...
- Android中判断当前网络是否可用
转载原文地址:http://www.cnblogs.com/renqingping/archive/2012/10/18/Net.html 当前有可用网络,如下图: 当前没有可用网络,如下图: 实现步 ...
- iOS 如何判断当前网络连接状态 网络是否正常 网络是否可用
网络资源:出处http://blog.csdn.net/mad1989/article/details/8987368 众所周知,我们在开发APP时,涉及网络连接的时候,都会想着提前判断一下当前的 ...
- api.connectionType 判断当前网络技术经验
使用 api.connectionType 判断当前网络的时候,需要注意,要加入大小写转换,三星返回的网络是大写 3G /** * 返回当前是否联网 * 周枫 * 3g 4g wifi none * ...
- Android 判断当前网络连接类型
实际应用开发时,如果存在需要用户获取大量数据的情况,最好是先判断下网络类型,提示用户当前的网络类型,是否需要连接Wifi,etc.(手机流量太贵啦,当然土豪是无视这玩意的, (/ □ \)). 定义网 ...
随机推荐
- 如何使VS2008 调试网站的根目录和IIS调试的一致?
用VS2008做asp.net网站调试时,经常会多出来一个目录,如http://localhost:1234/Foo/ , 由于一些图片的路径问题,我们不需要最后的/Foo/目录,而是像IIS调试那样 ...
- 基于s5pv210嵌入式linux系统sqlite3数据库移植
基于s5pv210嵌入式linux系统sqlite3数据库移植 1.下载源码 http://www.sqlite.org/download.html 最新源码为3080100 2.解压 tar xvf ...
- 破解金盘gdlisxp系统
1.现在要破解的金盘gdlisxp系统版本 2.首先在你电脑上要有脱壳工具AspackDie,和OllyDBG动态调试工具,电脑上装好金盘软件. 3.用AspackDie进行对金盘应用程序脱壳处理,生 ...
- Vmware为Ubuntu安装VmTools
From:http://www.cnblogs.com/killerlegend/p/3632443.html Author:KillerLegend 1:首先打开Vmware并运行里面的Ubuntu ...
- ADO.NET 结构 集中数据库联接结构
MSDN 原文出处 https://msdn.microsoft.com/zh-cn/library/27y4ybxw.aspx .NET Framework 4.6 and 4.5 其他版本 以前, ...
- C# 笛卡尔积
void Main() { string[] str1 = { "a", "b" }; " }; string[] str3 = { "一& ...
- rails的字符编码
想练练手,随意的写了个登陆页面,简单的只有几行. <%= form_tag('login_check') do -%><%= text_field_tag 'user_name', ...
- Hashset,Iterator
HashSet类主要是设计用来做高性能集运算的,例如对两个集合求交集.并集.差集等.集合中包含一组不重复出现且无特性顺序的元素. (一)HashSet的一些特性如下: 1.HashSet中的值不能重复 ...
- Collection、Iterator、Set、HashSet
Collection接口的基本方法 boolean add(Object o) 向集合当中加入一个对象 void clear() 删除集合当中的所有对象 boolean isEmpty() 判断集合是 ...
- char const*, char*const, const char *const的区别
C++标准规定,const关键字放在类型或变量名之前等价的.所以,const char*和 char const*是一样的. const char* //常量指针---指向常量的指针----指针指 ...