我正在开发一个Widget,它将获取当前GPS位置并将此值传递给远程PHP页面以获取信息并将其显示在Widget中.这就是我想要做的.
我在为appWidget实现Location Listener时遇到了问题.它没有使用当前位置进行更新,它显示了初始窗口小部件,即"正在加载窗口小部件"(这里我放了这个文本)
我们可以为AppWidgetProvider实现位置监听器吗?
或者
你能否告诉我在App Widget中获取GPS位置的可能解决方案?
我在Manifest文件中放置了所有必要的权限.
这是我的代码片段:
public class test extends AppWidgetProvider {
static LocationManager locMan;
static Location curLocation;
static Boolean locationChanged;
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,int[] appWidgetIds) {
// To prevent any ANR timeouts, we perform the update in a service
context.startService(new Intent(context, UpdateService.class));
}
public static class UpdateService extends Service {
// GPS Listener Class
LocationListener gpsListener = new LocationListener() {
public void onLocationChanged(Location location) {
// Log.w("GPS", "Started");
if (curLocation == null) { …Run Code Online (Sandbox Code Playgroud)