我已链接到您的图书馆(再次感谢和出色的工作)。
在过去的两个小时里,我一直在尝试问题是什么,但我失败了。
这是我的登录屏幕代码中的 AlarmManager:
Intent i = new Intent(con, LocationPoller.class);
i.putExtra(LocationPoller.EXTRA_INTENT, new Intent(con,
LocationReceiver.class));
i.putExtra(LocationPoller.EXTRA_PROVIDER,
LocationManager.NETWORK_PROVIDER);
gps = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
PendingIntent pi = PendingIntent.getBroadcast(con, 0, i, PendingIntent.FLAG_NO_CREATE);
gps.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(),
10 * 1000, pi);
Log.d("Service: ",
"GPS Service started and scheduled with AlarmManager");
这是我自己创建的课程(不是您演示中的课程,虽然类似):
public class LocationReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Bundle b = intent.getExtras();
Location loc = (Location) b.get(LocationPoller.EXTRA_LOCATION);
String msg;
if (loc == null)
{
loc = (Location) b.get(LocationPoller.EXTRA_LASTKNOWN);
if (loc == null)
{
msg = intent.getStringExtra(LocationPoller.EXTRA_ERROR);
}
else
{
msg = "TIMEOUT, lastKnown=" + loc.toString();
}
}
else
{
msg = loc.toString();
}
if (msg == null)
{
msg = "Invalid broadcast received!";
}
Log.d("GPS Broadcast: ", "Location: " + msg);
}
}
什么都没有发生。我假设这是因为我根本没有在我的 logcat 中看到任何信息。另外,当我查看调试视图时,PollerThread(如果这是正确的术语)不断堆积,好像它们都在等待某些东西但没有发送任何广播。
我究竟做错了什么?通过网络确定位置应该不会花费太多时间吧?即使这是问题所在,我也应该得到一些反馈..
以下是我的清单的应用程序标签中的条目:
<receiver android:name="com.commonsware.cwac.locpoll.LocationPoller" />
<receiver android:name=".LocationReceiver" />
<service android:name="com.commonsware.cwac.locpoll.LocationPollerService" />