Android 对于根设备:在4.0及以上版本中打开GPS
我正在为根设备开发一个项目,我想打开位置服务,以编程方式跟踪位置,而无需用户交互。 我已经创建了一个sms广播接收器,并在其中打开GPS 我发现:Android 对于根设备:在4.0及以上版本中打开GPS,android,gps,root,Android,Gps,Root,我正在为根设备开发一个项目,我想打开位置服务,以编程方式跟踪位置,而无需用户交互。 我已经创建了一个sms广播接收器,并在其中打开GPS 我发现: public void turnGPSOn() { Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE"); intent.putExtra("enabled", true); this.sendBroadcast(intent); String pr
public void turnGPSOn() {
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
this.sendBroadcast(intent);
String provider = Settings.Secure.getString(getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(!provider.contains("gps")){ //if gps is disabled final Intent poke = new Intent();
poke.setClassName("com.android.settings","com.android.settings.widget.SettingsAppWidgetProvider");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("3"));
this.sendBroadcast(poke);
}
但这是一个错误,我不知道该怎么办
注:我只是一个初学者。使用Android studio。我的测试设备是安卓5.1.1
sendBroacast,Settings.Secure.getString(getContentResolver(),Settings.Secure.LOCATION_PROVIDERS_-ALLOWED);:在android studio@Pragadeesyes中以红色文本显示,它在4.0以上无法工作,因此请使用com.google.android.gms:play services:8.1.0或7