Android的开启GPS ON&放大器;关闭编程在2.2? [英] android turn GPS On & Off Programmatically in 2.2?
本文介绍了Android的开启GPS ON&放大器;关闭编程在2.2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用我的GPS应用,我想打开GPS和关闭编程以节省电能我怎么能做到这一点 :(
这是关掉我需要请翻
私人无效turnGPSOnOff(){
字符串商= Settings.Secure.getString(getContentResolver(),Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
如果(!provider.contains(GPS)){
最终意图捅=新意图();
poke.setClassName(com.android.settings,com.android.settings.widget.SettingsAppWidgetProvider);
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse(3));
sendBroadcast(捅);
//Toast.makeText(this,您的GPS已启用,Toast.LENGTH_SHORT).show();
}
}
解决方案
您可以在GPS使用转动
LocationManager locationManager =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener的LocationListener的=新CTLocationListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,1.0F,LocationListener的);
和关闭它使用
locationManager.removeUpdates(LocationListener的);
或者,你也可能会发现这对利用GPS另一个线程: 启用GPS编程喜欢塔斯克
i am using GPS in My application and i want to turn GPS on and off Programmatically to save power how can i do it :(
this is for turn off i need the turn on please
private void turnGPSOnOff(){
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);
//Toast.makeText(this, "Your GPS is Enabled",Toast.LENGTH_SHORT).show();
}
}
解决方案
You can turn on the gps using
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new CTLocationListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1.0f, locationListener);
and turn it off using
locationManager.removeUpdates(locationListener);
Or you might also find this another thread on gps of use: Enable GPS programatically like Tasker
这篇关于Android的开启GPS ON&放大器;关闭编程在2.2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文