Android.os.HandleIntent calling the intent service without extravalues

183 Views Asked by At

I am developing the android application to get user activity in the background. Here is my code

public class ActivityRecognitionService extends IntentService implements GooglePlayServicesClient.ConnectionCallbacks,GooglePlayServicesClient.OnConnectionFailedListener {

AbstractWrapper w = null;

private PendingIntent pIntent;

private VSensorConfig config = null;

private ActivityRecognitionClient arclient;
private static final String DATE_FORMAT_PATTERN = "yyyy-MM-dd HH:mm:ss.SSSZ";

private static final String LOG_DELIMITER = ";;";

private SimpleDateFormat mDateFormat;


public ActivityRecognitionService() {
    super("ActivityRecognitionIntentService");
}

@Override
protected void onHandleIntent(Intent intent) {

    Bundle b = intent.getExtras();
    config = (VSensorConfig) b.get("config");


try {
        mDateFormat = (SimpleDateFormat) DateFormat.getDateTimeInstance();
    } catch (Exception e) {
    }

    mDateFormat.applyPattern(DATE_FORMAT_PATTERN);
    mDateFormat.applyLocalizedPattern(mDateFormat.toLocalizedPattern());

    int resp =GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
           arclient = new ActivityRecognitionClient(this, this, this);
           arclient.connect();

    if (ActivityRecognitionResult.hasResult(intent)) {


        ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
        Log.i("Activity Recived :DDDD", getType(result.getMostProbableActivity().getType()) +"\t" + result.getMostProbableActivity().getConfidence());
        DetectedActivity mostProbableActivity = result.getMostProbableActivity();
        Double confidence = (double) mostProbableActivity.getConfidence();
        Double activityType = (double) mostProbableActivity.getType();



        for (InputStream inputStream : config.getInputStreams()) {
            for (StreamSource streamSource : inputStream.getSources()) {
                w = streamSource.getWrapper();
                break;
            }
            break;
        }

        ((AndroidActivityRecognitionWrapper) w).getLastKnownData();
    }
}

private boolean activityChanged(int currentType) {
    return false;

}




@Override
public void onConnectionFailed(ConnectionResult arg0) {
    // TODO Auto-generated method stub

}

@Override
public void onConnected(Bundle arg0) {
    Intent intent = new Intent(this, ActivityRecognitionService.class);
    pIntent = PendingIntent.getService(this, 0, intent,PendingIntent.FLAG_UPDATE_CURRENT);
    arclient.requestActivityUpdates(1000, pIntent);   
}

@Override
public void onDisconnected() {
    // TODO Auto-generated method stub

}

}

The problem is that Android.os.HandleThread class call starts this intent without the extravalue so I got nullPointerException. Can anyone help me with that?

0

There are 0 best solutions below