如何使用CommonWare在android中获取位置?
有人可以分享一个使用android项目的Commonware jar库的工作代码吗 我已经从 我真的很喜欢及时获取位置的概念,但我无法使用此库完成它…请提供帮助 舱单条目如何使用CommonWare在android中获取位置?,android,geolocation,location,broadcastreceiver,android-service,Android,Geolocation,Location,Broadcastreceiver,Android Service,有人可以分享一个使用android项目的Commonware jar库的工作代码吗 我已经从 我真的很喜欢及时获取位置的概念,但我无法使用此库完成它…请提供帮助 舱单条目 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <receiver android:name="com.commonsware.cwac.locpoll.LocationPoller" /> <
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<receiver android:name="com.commonsware.cwac.locpoll.LocationPoller" />
<service android:name="com.commonsware.cwac.locpoll.LocationPollerService" />
谢谢
编辑:
代码工作正常,但执行正常,但我无法在LocationReceiver中接收广播。首先,这不是“android项目的Commonware jar库”。这是Alex Birkett提出的“android项目的公共软件jar库”
第二,正如所解释的:
在demo/
子项目中,您将找到一个示例活动,演示LocationPoller
的使用
首先,这不是“android项目的公共软件jar库”。这是Alex Birkett提出的“android项目的公共软件jar库”
第二,正如所解释的:
在demo/
子项目中,您将找到一个示例活动,演示LocationPoller
的使用
感谢您的回复,但问题是,当我执行上述代码时,它工作正常,我可以看到toast,但之后我无法在LocationReceiver中看到任何东西。@Shax:首先让
demo/
项目开始工作。如果你不能让demo/
项目运作起来,那就去找伯克特先生,因为我实在帮不了他的忙。如果您可以让demo/
正常工作,请确定您的代码与demo/
代码的不同之处。我正在使用IntelliJIdea,每当我尝试打开demo时,它都会提示我一个窗口,并要求我重新输入此属性的值\u android\u LocationPoller\u b2bdace1。我不知道那是什么…我是新的android世界…所以请原谅我问了一些非常愚蠢的问题谢谢你的回答,但问题是当我执行上面的代码时,我可以看到祝酒词,但在那之后我在LocationReceiver中什么都看不到。@Shax:首先让demo/
项目开始工作。如果你不能让demo/
项目运作起来,那就去找伯克特先生,因为我实在帮不了他的忙。如果您可以让demo/
正常工作,请确定您的代码与demo/
代码的不同之处。我正在使用IntelliJIdea,每当我尝试打开demo时,它都会提示我一个窗口,并要求我重新输入此属性的值\u android\u LocationPoller\u b2bdace1。我不知道那是什么…我是新安卓世界…所以请原谅我问了一些非常愚蠢的问题
private void initLocationTracker()
{
try{
alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
Intent intent = new Intent(this, LocationPoller.class);
Bundle bundle = new Bundle();
com.commonsware.cwac.locpoll.LocationPollerParameter locationPollerParameter =
new LocationPollerParameter(bundle);
locationPollerParameter.setIntentToBroadcastOnCompletion(new Intent(this, LocationReceiver.class));
// try GPS connection now
locationPollerParameter.setProviders(new String[]
{LocationManager.GPS_PROVIDER,LocationManager.NETWORK_PROVIDER});
locationPollerParameter.setTimeout(60000);
intent.putExtras(bundle);
pendingIntent = PendingIntent.getBroadcast(this,0,intent,0);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(),PERIOD,pendingIntent);
Toast
.makeText(this,
"Location polling every 30 minutes begun",
Toast.LENGTH_LONG)
.show();
}
catch (Exception e)
{
String s = e.getMessage();
}
}