我正在开发 android 应用程序以在后台获取用户活动。这是我的代码
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
}
}
问题是 Android.os.HandleThread 类调用在没有额外值的情况下启动了这个意图,所以我得到了 nullPointerException。任何人都可以帮助我吗?