获取 Android GpsLocationProvider 对象
我想访问 Android 上的 GpsLocationProvider
类。我想调用这个类的一些方法,比如setMinTime()
。 这是我的代码:
LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
GpsLocationProvider pr = (GpsLocationProvider)lm.getProvider(LocationManager.GPS_PROVIDER);
问题是 GpsLocationProvider 类未解决
。我知道它位于 com.android.internal.location.GpsLocationProvider 中,但此类导入也未解决,并且 import com.android.internal.*; 没有也无助于解决“GpsLocationProvider”问题。 这意味着什么? 感谢您的任何提示。
编辑:我知道我可以通过 LocationManager
更改大多数 LocationProvider
参数,例如 LocationManager.requestLocationUpdates(Stringprovider, long minTime, float minDistance, LocationListenerlistener)< /code> ,但我想做的是一点小技巧。我想要另一个程序比它更频繁地更新 GPS 坐标。这就是为什么我不能使用
LocationManager
(需要侦听器参数),并且想要设置“全局”gps 参数,这将影响另一个活动。
EDIT2:我按照里诺的建议尝试了反射。
LocationProvider provider = lm.getProvider(LocationManager.GPS_PROVIDER);
try {
Class classGpsProvider = Class.forName("com.android.internal.location.GpsLocationProvider");
classGpsProvider.cast(provider);
...
但不幸的是,对 lm.getProvider()
的调用返回 DummyLocationProvider
,而它的作用就像 GpsLocationProvider
的影子。
I want to get to the class GpsLocationProvider
on Android. I want to call a few methods of this class, like setMinTime()
.
Here is my code:
LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
GpsLocationProvider pr = (GpsLocationProvider)lm.getProvider(LocationManager.GPS_PROVIDER);
And the problem is GpsLocationProvider class is unresolved
. I know that it is located in com.android.internal.location.GpsLocationProvider
, but such import is unresolved as well, and import com.android.internal.*;
doesn't help to resolve ``GpsLocationProvider` too.
What does this mean?
Thank you for any tips.
EDIT: I know that I can change most of the LocationProvider
pararmeters through LocationManager
like LocationManager.requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener)
, but what I'm trying to do is a little hack. I want another programm to update gps coords more often than it does. That's why I cant use LocationManager
(that requires listener parameter), and want to set "global" gps params, that will affect another activity.
EDIT2: I tried with reflections as suggested by Reno.
LocationProvider provider = lm.getProvider(LocationManager.GPS_PROVIDER);
try {
Class classGpsProvider = Class.forName("com.android.internal.location.GpsLocationProvider");
classGpsProvider.cast(provider);
...
But unfortunately the call to lm.getProvider()
returns DummyLocationProvider
, and that one acts like a shadow for GpsLocationProvider
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果没有 reflection 你可能无法做到这一点
你应该使用 import <代码> android.location.*
You probably can't do that without reflection
You should be using the import
android.location.*