我正在使用Gps和每10分钟后发送到服务器的位置,但要做到Gps,电池耗尽。所以为此,我希望每10分钟后Gps应该打开并获取位置,此后Gps应该关闭。如何在每10分钟后以编程方式打开和关闭GPS?
0
A
回答
1
设置通过AlarmManager报警每10分钟。在警报中,为GPS提供者调用locationManager.requestSingleUpdate。这将打开GPS足够长的时间来获得一个修复程序,然后关闭它(除非其他程序正在使用它)。当它得到修复时,它会通过您在requestSingleUpdate中注册的回调来调用您。然后你可以做任何你需要的结果(比如通过AsyncTask发送给服务器)。
-1
public void turnGPSOn()
{
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
this.ctx.sendBroadcast(intent);
String provider = Settings.Secure.getString(ctx.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.ctx.sendBroadcast(poke);
}
}
//关闭GPS
public void turnGPSOff()
{
String provider = Settings.Secure.getString(ctx.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(provider.contains("gps")){ //if gps is enabled
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.ctx.sendBroadcast(poke);
}
}
相关问题
- 1. android在2.2中以编程方式打开和关闭GPS?
- 2. 以编程方式开启/关闭GPS
- 3. Android gps以编程方式打开和关闭
- 4. 如何以编程方式在Windows Phone 7中打开和关闭GPS
- 5. 如何以编程方式打开GPS
- 6. 以编程方式打开/关闭GPS,而不提示iPhone
- 7. 以编程方式关闭GPS
- 8. Android:如何以编程方式打开和关闭屏幕?
- 9. 如何以编程方式打开和关闭layout_behavior行为?
- 10. 如何在android中以编程方式自动开启和关闭gps
- 11. 我们可以在iPhone中以编程方式打开/关闭GPS吗?
- 12. 如何在WP7上以编程方式打开/关闭WiFi
- 13. 如何以编程方式在Android中打开/关闭通知?
- 14. 如何以编程方式关闭打开的jquery.reveal.js模式框?
- 15. 在android中以编程方式打开和关闭屏幕
- 16. 关闭离子选择以编程方式打开后
- 17. 如何打开和关闭GPS?
- 18. 如何以编程方式打开/关闭定时器
- 19. 如何以编程方式关闭或打开“Windows功能”
- 20. 如何以编程方式打开/关闭按钮?
- 21. Track Gps每隔10分钟在android
- 22. 如何以编程方式关闭黑莓上的GPS
- 23. 以编程方式打开和关闭控制台
- 24. 以可编程方式打开和关闭窗口
- 25. 以编程方式打开和关闭数据绑定?
- 26. iOS 5:以编程方式打开和关闭蓝牙
- 27. 如何以编程方式打开Android中的GPS?
- 28. 以编程方式关闭任何打开的灯箱?
- 29. 在Android中打开和关闭Gps?
- 30. Matlab PARFOR循环可以以编程方式打开/关闭吗?
他想得到的位置,而不是打开和关闭GPS设置 –
好吧,亲爱的...他写道,他想在获得位置后关闭gps ... @ GabeSechan – chiragkyada