mroshow / funf-open-sensing-framework

Automatically exported from code.google.com/p/funf-open-sensing-framework
0 stars 0 forks source link

Unregistering receiver that is not registered in ScreenProbe #21

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

v0.1.0
Oct 6, 2011 11:39:16 AM
1 reports/week
1 reports
java.lang.RuntimeException: Unable to stop service 
edu.mit.media.funf.probe.builtin.ScreenProbe@47cff010: 
java.lang.IllegalArgumentException: Receiver not registered: 
edu.mit.media.funf.probe.builtin.m@47eaa710
at android.app.ActivityThread.handleStopService(ActivityThread.java:3090)
at android.app.ActivityThread.access$3700(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2099)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: Receiver not registered: 
edu.mit.media.funf.probe.builtin.m@47eaa710
at 
android.app.ActivityThread$PackageInfo.forgetReceiverDispatcher(ActivityThread.j
ava:793)
at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:938)
at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:331)
at edu.mit.media.funf.probe.builtin.ScreenProbe.f(Unknown Source)
at edu.mit.media.funf.probe.Probe.s(Unknown Source)
at edu.mit.media.funf.probe.Probe.onDestroy(Unknown Source)
at android.app.ActivityThread.handleStopService(ActivityThread.java:3076)
... 10 more

Original issue reported on code.google.com by nad...@gmail.com on 12 Oct 2011 at 4:29

GoogleCodeExporter commented 9 years ago
java.lang.RuntimeException: Unable to stop service 
edu.mit.media.funf.probe.builtin.ScreenProbe@406980b8: 
java.lang.IllegalArgumentException: Receiver not registered: 
edu.mit.media.funf.probe.builtin.m@4061f090
at android.app.ActivityThread.handleStopService(ActivityThread.java:2417)
at android.app.ActivityThread.access$2900(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1114)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4293)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: Receiver not registered: 
edu.mit.media.funf.probe.builtin.m@4061f090
at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:634)
at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:878)
at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:331)
at edu.mit.media.funf.probe.builtin.ScreenProbe.f(Unknown Source)
at edu.mit.media.funf.probe.Probe.s(Unknown Source)
at edu.mit.media.funf.probe.Probe.onDestroy(Unknown Source)
at android.app.ActivityThread.handleStopService(ActivityThread.java:2400)
... 10 more

Original comment by nad...@gmail.com on 12 Oct 2011 at 4:30

GoogleCodeExporter commented 9 years ago
I had a similiar issue with the ScreenProbe, especially because i work with my 
custom broadcastreceivers to explicit trigger the probes. 

The Problem is the registration of the Broadcastreceiver with its intents. 

IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
        filter.addAction(Intent.ACTION_SCREEN_OFF);
        screenReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                final String action = intent.getAction();

                JsonObject data = new JsonObject();
                if (Intent.ACTION_SCREEN_OFF.equals(action)) {
                    data.addProperty(SCREEN_ON, false);
                    sendData(data);
                } else if (Intent.ACTION_SCREEN_ON.equals(action)) {
                    data.addProperty(SCREEN_ON, true);
                    sendData(data);
                }
            }
        };

        getContext().registerReceiver(screenReceiver, filter);

You have to build the receiver for SCREEN_ON and SCREEN_OFF into an activity, 
at onReceive then simply call the ScreenProbe and replace the 
onEnabled()-method with:
    @Override
    protected void onEnable() {
        PowerManager powerManager = (PowerManager) getContext().getSystemService(Context.POWER_SERVICE);
        JsonObject data = new JsonObject();
        if (powerManager.isScreenOn()){ 
                data.addProperty(SCREEN_ON, true);
                sendData(data);
        }else{
                data.addProperty(SCREEN_ON, false); 
                sendData(data);
        }
    }
to get the display state. This works fine for me, maybe it helps someone.

Original comment by simon.s1...@gmail.com on 13 Jun 2014 at 5:56