[英]Android Application that periodically gets Location
I am trying to build an Android Application that retrieves the users location for every 'x' seconds and then displays it in a toast. 我正在尝试构建一个Android应用程序 ,该应用程序每隔“ x”秒就会检索一次用户位置,然后将其显示在烤面包中。
There are three main java files that I am using in my code. 我在代码中使用了三个主要的Java文件。 They are: MainActivity.java
which extends Activity and uses the alarm service provided by the AlarmReciever.java
, AlarmReceiver.java
extends the broadcast receiver and LocationModules.java
, extends Service and implements location listener , which contain code to retrieve location. 它们是: MainActivity.java
, 扩展了Activity并使用了AlarmReciever.java
提供的警报服务, AlarmReceiver.java
扩展了广播接收器和LocationModules.java
, 扩展了Service并实现了位置侦听器 ,其中包含用于检索位置的代码。
The sequence of flow is as follows: 流程顺序如下:
MainActivity.java ------> AlarmReceiver.java ------> LocationModules.java MainActivity.java ------> AlarmReceiver.java ------> LocationModules.java
LocationModules.java
has a location manager that needs the application context which needs to be passed from MainActivity.java
(I am not sure if I am right here). LocationModules.java
有一个位置管理器,该管理器需要需要从MainActivity.java
传递的应用程序上下文(我不确定是否在这里)。
Can anyone please help me with this. 谁能帮我这个忙。 Thanks in advance. 提前致谢。
myLocationManager=(LocationManager)mContext.getSystemService(LOCATION_SERVICE);
如果您的LocationModules
扩展了Service
,则可以只使用getSystemService
方法(我的意思是,无需使用mContext
即可调用它)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.