这是代码......
private void turnGPSOn(){
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(!provider.contains("gps")){
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"));
sendBroadcast(poke);
} }
Run Code Online (Sandbox Code Playgroud)
您可以使用启动GPS
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new CTLocationListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1.0f, locationListener);
Run Code Online (Sandbox Code Playgroud)
停止使用gps提供程序
locationManager.removeUpdates(locationListener);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14747 次 |
| 最近记录: |