Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用CommonWare在android中获取位置?_Android_Geolocation_Location_Broadcastreceiver_Android Service - Fatal编程技术网

如何使用CommonWare在android中获取位置?

如何使用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" /> <

有人可以分享一个使用android项目的Commonware jar库的工作代码吗

我已经从

我真的很喜欢及时获取位置的概念,但我无法使用此库完成它…请提供帮助

舱单条目

<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();
        }
    }