久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<tfoot id='RtPKC'></tfoot>

    <i id='RtPKC'><tr id='RtPKC'><dt id='RtPKC'><q id='RtPKC'><span id='RtPKC'><b id='RtPKC'><form id='RtPKC'><ins id='RtPKC'></ins><ul id='RtPKC'></ul><sub id='RtPKC'></sub></form><legend id='RtPKC'></legend><bdo id='RtPKC'><pre id='RtPKC'><center id='RtPKC'></center></pre></bdo></b><th id='RtPKC'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='RtPKC'><tfoot id='RtPKC'></tfoot><dl id='RtPKC'><fieldset id='RtPKC'></fieldset></dl></div>

        <bdo id='RtPKC'></bdo><ul id='RtPKC'></ul>

      <small id='RtPKC'></small><noframes id='RtPKC'>

    1. <legend id='RtPKC'><style id='RtPKC'><dir id='RtPKC'><q id='RtPKC'></q></dir></style></legend>

      如何持續(xù)追蹤安卓手機(jī)的位置?

      How to continuously track the location of an Android mobile phone?(如何持續(xù)追蹤安卓手機(jī)的位置?)

        <small id='7FxbG'></small><noframes id='7FxbG'>

        <i id='7FxbG'><tr id='7FxbG'><dt id='7FxbG'><q id='7FxbG'><span id='7FxbG'><b id='7FxbG'><form id='7FxbG'><ins id='7FxbG'></ins><ul id='7FxbG'></ul><sub id='7FxbG'></sub></form><legend id='7FxbG'></legend><bdo id='7FxbG'><pre id='7FxbG'><center id='7FxbG'></center></pre></bdo></b><th id='7FxbG'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='7FxbG'><tfoot id='7FxbG'></tfoot><dl id='7FxbG'><fieldset id='7FxbG'></fieldset></dl></div>
          <bdo id='7FxbG'></bdo><ul id='7FxbG'></ul>
          <tfoot id='7FxbG'></tfoot>

                <tbody id='7FxbG'></tbody>
              • <legend id='7FxbG'><style id='7FxbG'><dir id='7FxbG'><q id='7FxbG'></q></dir></style></legend>

              • 本文介紹了如何持續(xù)追蹤安卓手機(jī)的位置?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我需要編寫一個(gè)應(yīng)用程序,它每 5 分鐘確定一次手機(jī)的當(dāng)前位置(使用所有免費(fèi)、可用的位置提供程序)并將其發(fā)送到服務(wù)器.

                I need to write an app, which every 5 minutes determines the current location of the mobile phone (using all free, available location providers) and sends it to a server.

                如果某些位置提供程序在應(yīng)用程序啟動時(shí)不起作用,但稍后可用,則應(yīng)用程序也應(yīng)處理其位置數(shù)據(jù).

                If some location provider doesn't work at the start of the application, but becomes available later, the application should process its location data as well.

                為了做到這一點(diǎn),我實(shí)現(xiàn)了以下課程.在我的一項(xiàng)活動中,我創(chuàng)建了它的一個(gè)實(shí)例并調(diào)用它的 startTrackingUpdates 方法.locationChangeHandler 處理位置數(shù)據(jù).

                In order to do this, I implemented following class. In one of my activities, I create an instance of it and call its startTrackingUpdates method. locationChangeHandler does the processing of location data.

                public class LocationTracker implements ILocationTracker, LocationListener {
                    public static final long MIN_TIME_BETWEEN_UPDATES = 1000 * 60 * 5; // 5 minutes
                    public static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10 meters
                    private ILocationManager locationManager;
                    private ILocationChangeHandler locationChangeHandler;
                
                    public LocationTracker(final ILocationManager aLocationManager,
                            final ILocationChangeHandler aLocationChangeHandler) {
                        this.locationManager = aLocationManager;
                        this.locationChangeHandler = aLocationChangeHandler;
                    }
                
                    public void startTrackingUpdates() {
                        final List<String> providers = locationManager.getAllProviders();
                
                        for (final String curProviderName : providers)
                        {
                            final ILocationProvider provider = locationManager.getLocationProvider(curProviderName);
                
                            if (!provider.hasMonetaryCost())
                            {
                                subscribeToLocationChanges(provider);
                            }
                        }
                    }
                
                    private void subscribeToLocationChanges(final ILocationProvider aProvider) {
                        locationManager.requestLocationUpdates(aProvider.getName(), MIN_TIME_BETWEEN_UPDATES, 
                                (float)MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                    }
                
                    public void onLocationChanged(final Location aLocation) {
                        locationChangeHandler.processLocationChange(new LocationWrapper(aLocation));
                    }
                
                    public void onProviderDisabled(final String aProvider) {
                    }
                
                    public void onProviderEnabled(final String aProvider) {
                    }
                
                    public void onStatusChanged(final String aProvider, final int aStatus, 
                            final Bundle aExtras) {
                    }
                }
                

                我構(gòu)建了應(yīng)用程序并將其安裝在我的手機(jī)上.然后,早上我拿起手機(jī),去上班,然后回家.在家查看應(yīng)用程序一天工作的結(jié)果,發(fā)現(xiàn)數(shù)據(jù)庫中只有一條記錄.

                I built the application and installed it on my mobile phone. Then, in the morning I took my phone, went to work, then went back home. At home I checked the results of a day-long work of the application and found only one record in the database.

                如果系統(tǒng)的其余部分(將位置數(shù)據(jù)傳輸?shù)椒?wù)器,保存在數(shù)據(jù)庫中)正常工作,我的位置跟蹤代碼肯定有問題(onLocationChanged 沒有被調(diào)用即使我多次更改我的位置).

                Provided that the rest of the system (transmission of location data to the server, saving in the database) works correctly, I must have some problem in the location tracking code (onLocationChanged wasn't invoked even though I changed my location several times).

                我的代碼有什么問題(我應(yīng)該如何更改它,以便在手機(jī)位置更改超過 MIN_DISTANCE_CHANGE_FOR_UPDATES 米時(shí)調(diào)用 onLocationChanged到定位提供者之一)?

                What's wrong with my code (how should I change it, in order for the onLocationChanged to be called whenever the location of the phone changes by more than MIN_DISTANCE_CHANGE_FOR_UPDATES meters according to one of the locatin providers) ?

                更新 1(18.08.2013 13:59 MSK):

                我根據(jù) msh 的建議更改了我的代碼.我使用以下代碼啟動計(jì)時(shí)器:

                I changed my code according to msh recommendations. I start the timer using following code:

                public void startSavingGeoData() {
                    final IAlarmManager alarmManager = activity.getAlarmManager();
                    final IPendingIntent pendingIntent = activity.createPendingResult(
                            ALARM_ID, intentFactory.createEmptyIntent(), 0);
                    alarmManager.setRepeating(INTERVAL, pendingIntent);
                }
                

                activity 我放置了以下計(jì)時(shí)器事件處理程序:

                In the activity I put following timer event handler:

                @Override
                protected void onActivityResult(final int aRequestCode, final int aResultCode, 
                        final Intent aData) {
                    geoDataSender.processOnActivityResult(aRequestCode, aResultCode, 
                            new IntentWrapper(aData));
                }
                

                當(dāng)手機(jī)開機(jī)時(shí),一切都按預(yù)期工作 - onActivityResultINTERVAL 毫秒內(nèi)執(zhí)行一次.

                When the phone is turned on, everything works as expected - onActivityResult is executed once in INTERVAL milliseconds.

                但是當(dāng)我按下電源按鈕(屏幕被禁用)時(shí),根本不會調(diào)用 onActivityResult.當(dāng)我再次按下電源按鈕時(shí),onActivityResult 會執(zhí)行多次,因?yàn)?INTERVAL 自我關(guān)閉手機(jī)以來已經(jīng)過去了.如果我關(guān)閉手機(jī) 1 * INTERVAL 毫秒,它會觸發(fā)一次.如果我將手機(jī)關(guān)機(jī) 2 * INTERVAL 毫秒,它會觸發(fā)兩次,以此類推.

                But when I press the power button (screen becomes disabled), onActivityResult is not invoked at all. When I press the power button again, onActivityResult is executed as many times, as INTERVAL has passed since the time when I turned the phone off. If I turned the phone off for 1 * INTERVAL milliseconds, it will fire once. If I turned the phone off for 2 * INTERVAL milliseconds, it will fire twice etc.

                注意:關(guān)閉"是指短按電源按鈕(例如,手機(jī)仍然活著"并對傳入的 SMS 做出反應(yīng)).

                Note: By "turning off" I mean a short press of the power button (the phone still "lives" and reacts to incoming SMS, for example).

                我應(yīng)該如何修改 startSavingGeoData 的代碼,以使 onActivityResult 方法每 INTERVAL 毫秒執(zhí)行一次,即使手機(jī)處于休眠狀態(tài)?

                How should I modify the code of startSavingGeoData in order for the method onActivityResult to be executed every INTERVAL milliseconds, even when the phone sleeps?

                更新 2(18.08.2013 19:29 MSK): alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, 0, INTERVAL, pendingIntent)alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, INTERVAL, INTERVAL, pendingIntent) 解決了這個(gè)問題.

                Update 2 (18.08.2013 19:29 MSK): Neither alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, 0, INTERVAL, pendingIntent), nor alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, INTERVAL, INTERVAL, pendingIntent) solved the problem.

                推薦答案

                您的代碼可能是正確的,但是當(dāng)您的手機(jī)處于睡眠狀態(tài)時(shí),位置提供程序沒有運(yùn)行.您可能需要獲取喚醒鎖(如果您不關(guān)心功耗),或者使用 AlarmManager 并安排您的應(yīng)用程序喚醒并定期檢查位置(在等待更新時(shí)您仍然需要激活喚醒鎖,或者由 AlamManager 或您自己獲得).

                Your code is probably correct, but location providers are not running when your phone is sleeping. You may need to acquire a wakelock (if you don't care about power draw), or use AlarmManager and schedule your application to wake up and check location periodically (you still need to have active wakelock while you are waiting for an update, either acquired by AlamManager, or your own).

                這篇關(guān)于如何持續(xù)追蹤安卓手機(jī)的位置?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                Help calculating X and Y from Latitude and Longitude in iPhone(幫助從 iPhone 中的緯度和經(jīng)度計(jì)算 X 和 Y)
                Get user#39;s current location using GPS(使用 GPS 獲取用戶的當(dāng)前位置)
                IllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 拋出的 IllegalArgumentException)
                How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新一次?)
                CLLocation returning negative speed(CLLocation 返回負(fù)速度)
                How to detect Location Provider ? GPS or Network Provider(如何檢測位置提供者?GPS 或網(wǎng)絡(luò)提供商)

              • <small id='1HECy'></small><noframes id='1HECy'>

                  <tfoot id='1HECy'></tfoot>

                        <tbody id='1HECy'></tbody>

                      • <i id='1HECy'><tr id='1HECy'><dt id='1HECy'><q id='1HECy'><span id='1HECy'><b id='1HECy'><form id='1HECy'><ins id='1HECy'></ins><ul id='1HECy'></ul><sub id='1HECy'></sub></form><legend id='1HECy'></legend><bdo id='1HECy'><pre id='1HECy'><center id='1HECy'></center></pre></bdo></b><th id='1HECy'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='1HECy'><tfoot id='1HECy'></tfoot><dl id='1HECy'><fieldset id='1HECy'></fieldset></dl></div>
                        <legend id='1HECy'><style id='1HECy'><dir id='1HECy'><q id='1HECy'></q></dir></style></legend>
                        • <bdo id='1HECy'></bdo><ul id='1HECy'></ul>
                          主站蜘蛛池模板: 国产精品久久久久久妇女6080 | 中文字幕亚洲一区二区三区 | 国产福利一区二区 | 国产精品欧美日韩 | 午夜视频免费网站 | 天天久久 | 国产精品欧美一区二区三区不卡 | 亚洲日本一区二区三区四区 | 国产激情在线观看 | 久久精品国产一区 | 国产91观看 | 国产精产国品一二三产区视频 | 亚洲综合大片69999 | 国产一区二区小视频 | 在线一区二区国产 | 国产在线精品一区二区三区 | 久久精品国产久精国产 | 免费精品 | 一级黄色片在线看 | 久久国产成人精品国产成人亚洲 | 国产免国产免费 | 日韩一区精品 | 欧美aⅴ | 日韩色视频 | 极情综合网 | 日本久久精品视频 | 日韩欧美一级 | 免费高潮视频95在线观看网站 | 久久毛片 | 亚洲一区av| 国产精品成人久久久久a级 久久蜜桃av一区二区天堂 | 波多野结衣av中文字幕 | 亚洲国产视频一区二区 | 久久小视频 | 另类在线| 欧美性生活网 | 国产成人综合在线 | 天天干夜夜操 | 爱操影视 | 日韩中字幕| 日韩一级免费电影 |