/**
* 判断是否开启GPS
* @param context
* @return
*/
public boolean isOpenGps(Context context){
try {
String str = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(null!=str){
return str.contains("gps");
}else{
return false;
}
} catch (Exception e) {
return false;
}
}
/**
* 打开GPS
* @param context
* @return
*/
public void openGps(Context context){
try {
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"));
PendingIntent.getBroadcast(context, 0, gpsIntent, 0).send();
} catch (Exception e) {
return ;
}
}
GPS相关
最新推荐文章于 2023-02-14 23:45:00 发布