I am using the funf framework in order to get access to the SMS’s on the users’ phone.
The framework consists of several packages. The provided probes all extend the abstract class Probe.
In order to utilize the framework i have wrote the following class:
package com.senseapp.dieselboris;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class SenseAppV1Activity extends Activity {
private long p;
private String message;
private boolean r;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SMSmessage sp = new SMSmessage();
r = sp.isRunning();
sp.enable();
p = sp.getDefaultPeriod();
message = Boolean.toString(r);
TextView tv = new TextView(this);
tv.setText(message);
setContentView(tv);
}
}
Because the methods of the the class SMSProbe are declared protected i wrote the SMSmessage class:
package com.senseapp.dieselboris;
import edu.mit.media.funf.probe.*;
import edu.mit.media.funf.probe.builtin.*;
import edu.mit.media.funf.probe.builtin.ProbeKeys.AndroidInternal.Sms;
public class SMSmessage extends SMSProbe {
protected String getDataName () {
return super.getDataName();
}
protected long getDefaultPeriod () {
return super.getDefaultPeriod();
}
protected String getDateColumnName () {
return super.getDateColumnName();
}
}
but when i run this code it fails when it should turn on the probe, see this error:
<small>
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.senseapp.dieselboris/com.senseapp.dieselboris.SenseAppV1Activity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
at android.app.ActivityThread.access$2300(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:144)
at android.app.ActivityThread.main(ActivityThread.java:4937)
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:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.content.ContextWrapper.sendBroadcast(ContextWrapper.java:271)
at edu.mit.media.funf.probe.Probe.sendProbeStatus(Probe.java:280)
at edu.mit.media.funf.probe.Probe.sendProbeStatus(Probe.java:227)
at edu.mit.media.funf.probe.Probe.enable(Probe.java:612)
at com.senseapp.dieselboris.SenseAppV1Activity.onCreate(SenseAppV1Activity.java:20)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
</small>
the method enable() in the abstract class Probe:
public final void enable() {
if (!enabled) {
Log.i(TAG, "Enabling probe: " + getClass().getName());
enabled = true;
running = false;
sendProbeStatus();
onEnable();
}
}
What do i do wrong? since my class SMSmessage eventually inherits from Probe this is valid I thought.
I hope one of the developers of Funf reads this.
Thank you.
In Funf, probes are Services. This means they cannot be directly instantiated, but instead have to be created by the system using intents. Here is an example of how to request data from a Probe service using intents. (The example below is for v0.3.x and above.)
Probes use asynchronous methods for sending status and data, so you will need a Service or BroadcastReceiver to receive probe information.
First create your callback intent using either a Service:
or using a Broadcast:
Then make your data request to the probe:
The probe will periodically send data and status messages based on the parameters you provide.
While requesting data from probes directly is required in some cases, it is not the recommended approach for most cases. For testing, I recommend using the ProbeTestCase class. It takes care of the details of requesting data and handling the responses. For an app, the easiest approach is to extend ConfiguredPipeline, and override
onDataReceived(Bundle data)to customize the handling of data that is received.