当前位置:网站首页>工作积累-判断GPS是否打开
工作积累-判断GPS是否打开
2022-06-23 04:14:00 【木子102】
Android判断GPS是否开启和强制帮用户打开GPS
/** * 判断GPS是否开启,GPS或者AGPS开启一个就认为是开启的 * @param context * @return true 表示开启 */
public static final boolean isOPen(final Context context) {
LocationManager locationManager
= (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
// 通过GPS卫星定位,定位级别可以精确到街(通过24颗卫星定位,在室外和空旷的地方定位准确、速度快)
boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
// 通过WLAN或移动网络(3G/2G)确定的位置(也称作AGPS,辅助GPS定位。主要用于在室内或遮盖物(建筑群或茂密的深林等)密集的地方定位)
boolean network = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (gps || network) {
return true;
}
return false;
} /** * 强制帮用户打开GPS * @param context */
public static final void openGPS(Context context) {
Intent GPSIntent = new Intent();
GPSIntent.setClassName("com.android.settings",
"com.android.settings.widget.SettingsAppWidgetProvider");
GPSIntent.addCategory("android.intent.category.ALTERNATIVE");
GPSIntent.setData(Uri.parse("custom:3"));
try {
PendingIntent.getBroadcast(context, 0, GPSIntent, 0).send();
} catch (CanceledException e) {
e.printStackTrace();
}
} <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" /> 引用块内容
边栏推荐
- Digital collections - new investment opportunities
- FS2119A同步升压IC输出3.3V和FS2119B同步升压IC输出5V
- PAT 乙等 1018 C语言
- 英集芯推出4串锂电池100W移动电源升降压方案SoC芯片IP5389
- 高等数学(第七版)同济大学 习题1-9 个人解答
- 华为软硬件生态圈成型,从根子上改变美国对软硬件体系的领导地位
- Skill self check | do you know these 6 skills if you want to be a test leader?
- Low cost 5W wireless charger scheme fs68001b simple charging chip
- C primer plus学习笔记 —— 2、常量与格式化IO(输入/输出)
- 数字藏品到底有什么魔力?目前有哪些靠谱的团队在开发
猜你喜欢

Real MySQL interview question (XXVIII) -- case - Analysis of indicators of communication operators

Lihongyi, machine learning 5 Tips for neural network design

Software design and Development Notes 2: serial port debugging tool based on QT design

Alibaba cloud object storage oss+picgo+typera implements the construction map

Lottery DDD code

Management system of borrowed books based on SSM framework

阿里云对象存储oss+picgo+typora实现构建图床

数字藏品火热背后需要强大的技术团队支持 北方技术团队

SIFT feature point extraction

MySQL面试真题(二十六)——滴滴2020年笔试题
随机推荐
The road of architects starts from "storage selection"
STC 32-bit 8051 MCU development example tutorial I development environment construction
PAT 乙等 1022 D进制的A+B
MySQL面试真题(二十四)——行列互换
MySQL面试真题(三十)——贝壳-房产订单分析
PAT 乙等 1026 程序运行时间
Use of visdom
What is the magic of digital collections? Which reliable teams are currently developing
【数据库备份】通过定时任务完成MySQL数据库的备份
数字藏品火热背后需要强大的技术团队支持 北方技术团队
Software design and Development Notes 2: serial port debugging tool based on QT design
51万奖池邀你参战——第二届阿里云ECS CloudBuild开发者大赛来袭
Advanced Mathematics (Seventh Edition) Tongji University exercises 1-7 personal solutions
What is the reason for the black screen of the computer monitor when the computer is turned on? What should I do about the black screen of the computer monitor
jvm: 方法重载时,具体调用哪个方法,是由传入参数的静态类型来决定的,而不是由参数的实际类型来决定
Alibaba cloud object storage oss+picgo+typera implements the construction map
Skill self check | do you know these 6 skills if you want to be a test leader?
How can digital collections empower economic entities?
PAT 乙等 1011 C语言
高等数学(第七版)同济大学 习题1-9 个人解答