commonsware locationpoller

时间:2012-03-28 14:21:08

标签: android commonsware-cwac

我尝试使用alexbirkett编辑的commonsware的locationpoller但有时广播进入超时并杀死应用程序

这里是我的logcat

WindowManager(  299): rotationForOrientationLw(orient=4, last=0); user=0  displayEnabled=true mHdmiPlugged=false mLidOpen=-1 mDockMode=0 (useSensorForOrientationLp(orientation)=true mAccelerometerDefault=1
V/WindowManager(  299): new rotation is set to 0
D/BatteryService(  299): update start
D/BatteryService(  299): level:84 scale:100 status:3 health:2 present:true voltage: 3 temperature: 296 technology: Li-ion AC powered:false USB powered:false icon:17302738 invalid charger:0
I/TabletStatusBar(  349): DISABLE_BACK: yes
I/TabletStatusBar(  349): DISABLE_TRAY: bChanged = true
D/InputManagerService(  299): startInputLocked: cs=ClientState{40b72e58 uid 1000 pid 299}, cs.pid=299, Binding.getCallingPid()=299
D/InputManagerService(  299): startInputLocked : startInputLocked(client=android.view.inputmethod.InputMethodManager$1@40b71e00, inputContext=android.view.inputmethod.InputMethodManager$ControlledInputConnectionWrapper@41995ef0, attribute=android.view.inputmethod.EditorInfo@41be2d20initial=true, neededResult=false
D/InputManagerService(  299): java.lang.Throwable
D/InputManagerService(  299):   at com.android.server.InputMethodManagerService.startInputLocked(InputMethodManagerService.java:906)
D/InputManagerService(  299):   at com.android.server.InputMethodManagerService.startInput(InputMethodManagerService.java:1041)
D/InputManagerService(  299):   at android.view.inputmethod.InputMethodManager.startInputInner(InputMethodManager.java:1050)
D/InputManagerService(  299):   at android.view.inputmethod.InputMethodManager.checkFocus(InputMethodManager.java:1185)
D/InputManagerService(  299):   at android.view.ViewRoot.handleMessage(ViewRoot.java:2216)
D/InputManagerService(  299):   at android.os.Handler.dispatchMessage(Handler.java:99)
D/InputManagerService(  299):   at android.os.Looper.loop(Looper.java:132)
D/InputManagerService(  299):   at com.android.server.wm.WindowManagerService$PolicyThread.run(WindowManagerService.java:722)
I/WindowManager(  299): Placing input method @1
W/ActivityManager(  299): Timeout of broadcast BroadcastRecord{421ec4d0 null} - receiver=android.os.BinderProxy@40cf6448, started 20001ms ago
W/ActivityManager(  299): Receiver during timeout: ResolveInfo{41a09bb0 com.sitrade.LocationReceiver p=0 o=0 m=0x0}
E/ActivityManager(  299): ANR in com.sitrade
E/ActivityManager(  299): Reason: Broadcast of Intent { flg=0x10 pkg=com.sitrade cmp=com.sitrade/.LocationReceiver (has extras) }
E/ActivityManager(  299): Load: 0.34 / 0.75 / 0.95
E/ActivityManager(  299): CPU usage from 10300ms to 1855ms ago:
E/ActivityManager(  299):   13% 1923/com.skype.raider: 11% user + 2% kernel / faults: 589 minor 1 major
E/ActivityManager(  299):   12% 299/system_server: 9.4% user + 2.6% kernel / faults: 1004 minor 1 major
E/ActivityManager(  299):   5.2% 246/gpsd: 5.1% user + 0.1% kernel
E/ActivityManager(  299):   1.4% 3014/skypekit: 0.8% user + 0.5% kernel
E/ActivityManager(  299):   0.5% 349/com.android.systemui: 0.4% user + 0.1% kernel / faults: 12 minor
E/ActivityManager(  299):   0.5% 238/surfaceflinger: 0.3% user + 0.2% kernel / faults: 132 minor
E/ActivityManager(  299):   0.5% 257/irq/182-3d: 0% user + 0.5% kernel
E/ActivityManager(  299):   0.2% 377/com.android.launcher: 0.1% user + 0% kernel / faults: 484 minor
E/ActivityManager(  299):   0.4% 208/kinteractiveup: 0% user + 0.4% kernel
E/ActivityManager(  299):   0.4% 7787/kworker/u:9: 0% user + 0.4% kernel
E/ActivityManager(  299):   0.3% 359/com.samsung.sec.android.inputmethod.axt9: 0.2% user + 0.1% kernel / faults: 8 minor
E/ActivityManager(  299):   0.3% 8454/kworker/0:0: 0% user + 0.3% kernel
E/ActivityManager(  299):   0% 4521/com.sec.android.widgetapp.digitalclock: 0% user + 0% kernel / faults: 106 minor
E/ActivityManager(  299):   0.1% 3/ksoftirqd/0: 0% user + 0.1% kernel
E/ActivityManager(  299):   0.1% 219/mmcqd: 0% user + 0.1% kernel
E/ActivityManager(  299):   0.1% 247/immvibed: 0% user + 0.1% kernel
E/ActivityManager(  299):   0% 251/rild: 0% user + 0% kernel
E/ActivityManager(  299):   0.1% 281/smdctld: 0% user + 0.1% kernel
E/ActivityManager(  299):   0.1% 368/com.android.phone: 0.1% user + 0% kernel / faults: 6 minor
E/ActivityManager(  299):   0% 626/ksdioirqd/mmc1: 0% user + 0% kernel
E/ActivityManager(  299):   0% 652/wpa_supplicant: 0% user + 0% kernel
E/ActivityManager(  299):   0% 2464/com.sec.minimode.taskcloser: 0% user + 0% kernel / faults: 10 minor
E/ActivityManager(  299):   0.1% 4512/com.sitrade: 0.1% user + 0% kernel
E/ActivityManager(  299):   0% 7097/com.google.android.apps.maps:NetworkLocationService: 0% user + 0% kernel / faults: 5 minor
E/ActivityManager(  299):   0% 7225/com.wssyncmldm: 0% user + 0% kernel / faults: 121 minor
E/ActivityManager(  299):   0.1% 8435/kworker/1:2: 0% user + 0.1% kernel
E/ActivityManager(  299): 17% TOTAL: 14% user + 3.4% kernel + 0.1% iowait
E/ActivityManager(  299): CPU usage from 576ms to 1094ms later:
E/ActivityManager(  299):   46% 299/system_server: 28% user + 17% kernel / faults: 71 minor
E/ActivityManager(  299):     40% 393/Binder Thread #: 28% user + 11% kernel
E/ActivityManager(  299):     3.8% 309/ActivityManager: 1.9% user + 1.9% kernel
E/ActivityManager(  299):   2.5% 1923/com.skype.raider: 2.5% user + 0% kernel
E/ActivityManager(  299):     2.5% 1926/HeapWorker: 2.5% user + 0% kernel
E/ActivityManager(  299):   1.1% 238/surfaceflinger: 0% user + 1.1% kernel
E/ActivityManager(  299):   1.2% 2464/com.sec.minimode.taskcloser: 0% user + 1.2% kernel / faults: 281 minor
E/ActivityManager(  299):     2.5% 2464/mode.taskcloser: 0% user + 2.5% kernel
E/ActivityManager(  299):     1.2% 7726/AsyncTask #3: 1.2% user + 0% kernel
E/ActivityManager(  299):   1.2% 3014/skypekit: 0% user + 1.2% kernel
E/ActivityManager(  299):     1.2% 3022/Backbone: 1.2% user + 0% kernel
E/ActivityManager(  299): 25% TOTAL: 17% user + 8.6% kernel
I/WindowManager(  299): WIN DEATH: Window{41bd4280 com.sitrade/com.sitrade.Hub paused=false}
I/ActivityManager(  299): Process com.sitrade (pid 4512) has died.
I/WindowManager(  299): WIN DEATH: Window{414bba58 com.sitrade/com.sitrade.Hub paused=false}
I/WindowManager(  299): WIN DEATH: Window{40bae208 com.sitrade/com.sitrade.Dettagliopratica paused=false}
I/WindowManager(  299): WIN DEATH: Window{40ac2ad0 com.sitrade/com.sitrade.NuovaLavorazione paused=false}
I/WindowManager(  299): WIN DEATH: Window{40b0a2c0 com.sitrade/com.sitrade.ElencoPratiche paused=false}
I/WindowManager(  299): WIN DEATH: Window{40b4c540 com.sitrade/com.sitrade.ElencoPratiche paused=false}
I/WindowManager(  299): WIN DEATH: Window{40c72ec0 com.sitrade/com.sitrade.ElencoPratiche paused=false}
I/WindowManager(  299): WIN DEATH: Window{416b69b8 com.sitrade/com.sitrade.NuovaLavorazione paused=false}
I/WindowManager(  299): WIN DEATH: Window{41424328 com.sitrade/com.sitrade.NuovaLavorazione paused=false}
I/WindowManager(  299): WIN DEATH: Window{40c7aeb8 com.sitrade/com.sitrade.Dettagliopratica paused=false}
I/WindowManager(  299): WIN DEATH: Window{40ba9618 com.sitrade/com.sitrade.Firma paused=false}
I/WindowManager(  299): WIN DEATH: Window{416b2d28 com.sitrade/com.sitrade.Dettagliopratica paused=false}
I/WindowManager(  299): WIN DEATH: Window{41289588 com.sitrade/com.sitrade.ElencoPratiche paused=false}
I/WindowManager(  299): WIN DEATH: Window{40c4c418 com.sitrade/com.sitrade.NuovaLavorazione paused=false}
I/WindowManager(  299): WIN DEATH: Window{40bb07d8 com.sitrade/com.sitrade.Hub paused=false}
I/WindowManager(  299): WIN DEATH: Window{415a4338 com.sitrade/com.sitrade.ElencoPratiche paused=false}
I/WindowManager(  299): WIN DEATH: Window{40bc5320 com.sitrade/com.sitrade.Dettagliopratica paused=false}
I/WindowManager(  299): WINDOW DIED Window{416b2d28 com.sitrade/com.sitrade.Dettagliopratica paused=false}
W/ActivityManager(  299): Failure sending broadcast Intent { act=android.intent.action.SCREEN_OFF flg=0x40000010 }
W/ActivityManager(  299): android.os.DeadObjectException
W/ActivityManager(  299):   at android.os.BinderProxy.transact(Native Method)
W/ActivityManager(  299):   at android.content.IIntentReceiver$Stub$Proxy.performReceive(IIntentReceiver.java:121)
W/ActivityManager(  299):   at com.android.server.am.ActivityManagerService.performReceiveLocked(ActivityManagerService.java:11648)
W/ActivityManager(  299):   at com.android.server.am.ActivityManagerService.deliverToRegisteredReceiverLocked(ActivityManagerService.java:11710)
W/ActivityManager(  299):   at com.android.server.am.ActivityManagerService.processNextBroadcast(ActivityManagerService.java:11916)
W/ActivityManager(  299):   at com.android.server.am.ActivityManagerService.access$100(ActivityManagerService.java:147)
W/ActivityManager(  299):   at com.android.server.am.ActivityManagerService$2.handleMessage(ActivityManagerService.java:1100)
W/ActivityManager(  299):   at android.os.Handler.dispatchMessage(Handler.java:99)
W/ActivityManager(  299):   at android.os.Looper.loop(Looper.java:132)
W/ActivityManager(  299):   at com.android.server.am.ActivityManagerService$AThread.run(ActivityManagerService.java:1438)
W/ActivityManager(  299): Failure sending broadcast Intent { act=android.intent.action.SCREEN_OFF flg=0x40000010 }
W/ActivityManager(  299): android.os.DeadObjectException
W/ActivityManager(  299):   at android.os.BinderProxy.transact(Native Method)
W/ActivityManager(  299):   at android.content.IIntentReceiver$Stub$Proxy.performReceive(IIntentReceiver.java:121)
W/ActivityManager(  299):   at com.android.server.am.ActivityManagerService.performReceiveLocked(ActivityManagerService.java:11648)
W/ActivityManager(  299):   at com.android.server.am.ActivityManagerService.deliverToRegisteredReceiverLocked(ActivityManagerService.java:11710)
W/ActivityManager(  299):   at com.android.server.am.ActivityManagerService.processNextBroadcast(ActivityManagerService.java:11916)
W/ActivityManager(  299):   at com.android.server.am.ActivityManagerService.access$100(ActivityManagerService.java:147)
W/ActivityManager(  299):   at com.android.server.am.ActivityManagerService$2.handleMessage(ActivityManagerService.java:1100)
W/ActivityManager(  299):   at android.os.Handler.dispatchMessage(Handler.java:99)
W/ActivityManager(  299):   at android.os.Looper.loop(Looper.java:132)
W/ActivityManager(  299):   at com.android.server.am.ActivityManagerService$AThread.run(ActivityManagerService.java:1438)
W/ActivityManager(  299): Failure sending broadcast Intent { act=android.intent.action.SCREEN_OFF flg=0x40000010 }
W/ActivityManager(  299): android.os.DeadObjectException
W/ActivityManager(  299):   at android.os.BinderProxy.transact(Native Method)
W/ActivityManager(  299):   at android.content.IIntentReceiver$Stub$Proxy.performReceive(IIntentReceiver.java:121)
W/ActivityManager(  299):   at com.android.server.am.ActivityManagerService.performReceiveLocked(ActivityManagerService.java:11648)
W/ActivityManager(  299):   at com.android.server.am.ActivityManagerService.deliverToRegisteredReceiverLocked(ActivityManagerService.java:11710)
W/ActivityManager(  299):   at com.android.server.am.ActivityManagerService.processNextBroadcast(ActivityManagerService.java:11916)
W/ActivityManager(  299):   at com.android.server.am.ActivityManagerService.access$100(ActivityManagerService.java:147)
W/ActivityManager(  299):   at com.android.server.am.ActivityManagerService$2.handleMessage(ActivityManagerService.java:1100)
W/ActivityManager(  299):   at android.os.Handler.dispatchMessage(Handler.java:99)
W/ActivityManager(  299):   at android.os.Looper.loop(Looper.java:132)
W/ActivityManager(  299):   at com.android.server.am.ActivityManagerService$AThread.run(ActivityManagerService.java:1438)

这里是我的实施

PERIOD = SharedPreference.getInt("georef_intervallo", appConfig.georef_intervallo);

        mgr =(AlarmManager)getSystemService(ALARM_SERVICE);

        Intent i = new Intent(this, LocationPoller.class);

        Bundle bundle = new Bundle();
        LocationPollerParameter parameter = new LocationPollerParameter(bundle);
        parameter.setIntentToBroadcastOnCompletion(new Intent(this, LocationReceiver.class));
        // try GPS and fall back to NETWORK_PROVIDER
        parameter.setProviders(new String[] {LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER});
        parameter.setTimeout(60000); //questo è il timeout di check dopo il quale scala sul lastknowlocation
        i.putExtras(bundle);

        pi = PendingIntent.getBroadcast(this, 0, i, 0);
        mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                                            SystemClock.elapsedRealtime(),
                                            PERIOD,
                                            pi);

这里是locationreceiver.java

package com.sitrade;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import com.commonsware.cwac.locpoll.LocationPoller;
import com.commonsware.cwac.locpoll.LocationPollerResult;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.location.Location;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;

public class LocationReceiver extends BroadcastReceiver {

    Network Network;
    DatabaseHelper DatabaseHelper;

    @Override
      public void onReceive(Context context, Intent intent) {
        Log.d("rss","receive");
        AppConfig appConfig = new AppConfig();
        SharedPreferences SharedPreference = context.getSharedPreferences(appConfig.sharedpreference_key, Context.MODE_PRIVATE);

        if ( SharedPreference.getBoolean("georef_active",true) && SharedPreference.getBoolean("DB_DOWNLOADED", false) && SharedPreference.getBoolean("USER_LOGGED",false) ) {


            Network = new Network( context );
            DatabaseHelper = new DatabaseHelper( context );

            Log.i("rss","ricevo la location");
            Bundle b=intent.getExtras();

            LocationPollerResult locationResult = new LocationPollerResult(b);

            Location loc=locationResult.getLocation();
            String msg;

            if ( loc == null ) {
              loc = locationResult.getLastKnownLocation();

              if ( loc == null ) {
                msg = locationResult.getError();
              }
              else {
                msg = "TIMEOUT, lastKnown="+loc.toString();
              }
            }
            else {
              msg = loc.toString();
            }

            if ( msg == null ) {
                msg = "Invalid broadcast received!";
            }
            else {
                Network.appSendGeo(loc);
                DatabaseHelper.insertFRONT_GeoTracking(loc);
            }



            Log.i("rss","*LOCATION RESPONSE:"+msg);
        }
        else{
            Log.d("rss","localion is down");

        }
    }


}

我无法理解出了什么问题!!

现在更新02/04,问题消失了,谢谢!但是出现了这个

E/AndroidRuntime( 3081): FATAL EXCEPTION: LocationPoller-PollerThread
E/AndroidRuntime( 3081): java.lang.RuntimeException: WakeLock under-locked com.commonsware.cwac.locpoll.LocationPoller
E/AndroidRuntime( 3081):    at android.os.PowerManager$WakeLock.release(PowerManager.java:320)
E/AndroidRuntime( 3081):    at android.os.PowerManager$WakeLock.release(PowerManager.java:295)
E/AndroidRuntime( 3081):    at com.commonsware.cwac.locpoll.WakefulThread.onPostExecute(WakefulThread.java:59)
E/AndroidRuntime( 3081):    at com.commonsware.cwac.locpoll.LocationPollerService$PollerThread.onPostExecute(LocationPollerService.java:264)
E/AndroidRuntime( 3081):    at com.commonsware.cwac.locpoll.WakefulThread.run(WakefulThread.java:93)

1 个答案:

答案 0 :(得分:3)

我的猜测是:

            Network.appSendGeo(loc);
            DatabaseHelper.insertFRONT_GeoTracking(loc);

分别正在进行网络I / O和磁盘I / O.如果是这样,您需要将这些内容移出BroadcastReceiver并移至IntentService发起的BroadcastReceiver。您正在主应用程序线程上执行网络I / O和磁盘I / O,最终Android假定您的BroadcastReceiver已损坏。