我从 sqllite 收到一个错误,上面写着这样的内容。现在我检查了日志,它似乎总是随机出现。它永远不会在相同的功能或日志行之后。这是错误:
12-10 16:12:19.397: E/SQLiteDatabase(6496): Error inserting context_name=6 end_time=1449760334152 context_family=1 module_id=com.google.android.contextmanager.module.DetectedActivityProducer version=1 sync_state_mod_time_millis=1449760339393 start_time=1449760329012 sync_state=0 context_id=18d4afbc-7563-403a-84d5-95bab5c64304 time_type=3 proto_blob=[B@9fafac0
12-10 16:12:19.397: E/SQLiteDatabase(6496): android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: context.context_id (code 2067)
12-10 16:12:19.397: E/SQLiteDatabase(6496): at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
12-10 16:12:19.397: E/SQLiteDatabase(6496): at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:780)
12-10 16:12:19.397: E/SQLiteDatabase(6496): at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
12-10 16:12:19.397: E/SQLiteDatabase(6496): at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
12-10 16:12:19.397: E/SQLiteDatabase(6496): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1471)
12-10 16:12:19.397: E/SQLiteDatabase(6496): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1341)
12-10 16:12:19.397: E/SQLiteDatabase(6496): at com.google.android.contextmanager.q.ak.a(SourceFile:445)
12-10 16:12:19.397: E/SQLiteDatabase(6496): at com.google.android.contextmanager.q.ak.b(SourceFile:420)
12-10 16:12:19.397: E/SQLiteDatabase(6496): at com.google.android.contextmanager.q.ak.a(SourceFile:370)
12-10 16:12:19.397: E/SQLiteDatabase(6496): at com.google.android.contextmanager.q.ak.b(SourceFile:400)
12-10 16:12:19.397: E/SQLiteDatabase(6496): at com.google.android.contextmanager.q.r.a(SourceFile:381)
12-10 16:12:19.397: E/SQLiteDatabase(6496): at com.google.android.contextmanager.g.a.j.a(SourceFile:58)
12-10 16:12:19.397: E/SQLiteDatabase(6496): at com.google.android.contextmanager.g.a.a.run(SourceFile:52)
12-10 16:12:19.397: E/SQLiteDatabase(6496): at com.google.android.contextmanager.g.i.a(SourceFile:263)
12-10 16:12:19.397: E/SQLiteDatabase(6496): at com.google.android.contextmanager.g.i.handleMessage(SourceFile:254)
12-10 16:12:19.397: E/SQLiteDatabase(6496): at android.os.Handler.dispatchMessage(Handler.java:102)
12-10 16:12:19.397: E/SQLiteDatabase(6496): at android.os.Looper.loop(Looper.java:148)
12-10 16:12:19.397: E/SQLiteDatabase(6496): at android.os.HandlerThread.run(HandlerThread.java:61)
12-10 16:12:19.401: E/SQLiteDatabase(6496): Error inserting context_name=6 end_time=1449760339330 context_family=1 module_id=com.google.android.contextmanager.module.DetectedActivityProducer version=1 sync_state_mod_time_millis=1449760339399 start_time=1449760334152 sync_state=0 context_id=d6726de4-a445-421d-a437-e66bbdee5c2d time_type=3 proto_blob=[B@8c373f9
12-10 16:12:19.401: E/SQLiteDatabase(6496): android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: context.context_id (code 2067)
12-10 16:12:19.401: E/SQLiteDatabase(6496): at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
12-10 16:12:19.401: E/SQLiteDatabase(6496): at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:780)
12-10 16:12:19.401: E/SQLiteDatabase(6496): at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
12-10 16:12:19.401: E/SQLiteDatabase(6496): at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
12-10 16:12:19.401: E/SQLiteDatabase(6496): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1471)
12-10 16:12:19.401: E/SQLiteDatabase(6496): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1341)
12-10 16:12:19.401: E/SQLiteDatabase(6496): at com.google.android.contextmanager.q.ak.a(SourceFile:445)
12-10 16:12:19.401: E/SQLiteDatabase(6496): at com.google.android.contextmanager.q.ak.b(SourceFile:420)
12-10 16:12:19.401: E/SQLiteDatabase(6496): at com.google.android.contextmanager.q.ak.a(SourceFile:370)
12-10 16:12:19.401: E/SQLiteDatabase(6496): at com.google.android.contextmanager.q.ak.b(SourceFile:400)
12-10 16:12:19.401: E/SQLiteDatabase(6496): at com.google.android.contextmanager.q.r.a(SourceFile:381)
12-10 16:12:19.401: E/SQLiteDatabase(6496): at com.google.android.contextmanager.g.a.j.a(SourceFile:58)
12-10 16:12:19.401: E/SQLiteDatabase(6496): at com.google.android.contextmanager.g.a.a.run(SourceFile:52)
12-10 16:12:19.401: E/SQLiteDatabase(6496): at com.google.android.contextmanager.g.i.a(SourceFile:263)
12-10 16:12:19.401: E/SQLiteDatabase(6496): at com.google.android.contextmanager.g.i.handleMessage(SourceFile:254)
12-10 16:12:19.401: E/SQLiteDatabase(6496): at android.os.Handler.dispatchMessage(Handler.java:102)
12-10 16:12:19.401: E/SQLiteDatabase(6496): at android.os.Looper.loop(Looper.java:148)
12-10 16:12:19.401: E/SQLiteDatabase(6496): at android.os.HandlerThread.run(HandlerThread.java:61)
这是来自 DetectedActivity API 的 onReceive 广播:
@Override
public void onReceive(Context context, Intent intent) {
ArrayList<DetectedActivity> updatedActivities =
intent.getParcelableArrayListExtra(Constants.ACTIVITY_EXTRA);
int type = 0x0;
Integer confidence = 0;
Utils.appendLog("MOTION ON RECEIVE BROADCAST RECEIVER",true);
Log.i("","autopilot-----------------------------------------------");
String rawData = "(";
for (DetectedActivity detectedActivity : updatedActivities){
if(detectedActivity.getConfidence() >= 25){
rawData += detectedActivity.getType() +":" + detectedActivity.getConfidence() + ",";
Log.i("", "autopilot detected activity: " + detectedActivity);
if(confidence < detectedActivity.getConfidence()){
confidence = detectedActivity.getConfidence();
}
if(detectedActivity.getType() == DetectedActivity.STILL){
type |= PSMotionService.stationary;
}else if(detectedActivity.getType() == DetectedActivity.IN_VEHICLE){
type |= PSMotionService.automotive;
}else if(detectedActivity.getType() == DetectedActivity.ON_BICYCLE){
type |= PSMotionService.bicycling;
}else if(detectedActivity.getType() == DetectedActivity.ON_FOOT || detectedActivity.getType() == DetectedActivity.WALKING || detectedActivity.getType() == DetectedActivity.TILTING){
type |= PSMotionService.walking;
}else if(detectedActivity.getType() == DetectedActivity.RUNNING){
type |= PSMotionService.running;
}else if(detectedActivity.getType() == DetectedActivity.UNKNOWN){
type |= PSMotionService.unknown;
}
}
}
rawData += ")";
Long timestamp = System.currentTimeMillis()/1000;
Integer confidenceFlag = 0;
if(confidence >= 25 && confidence < 75){
confidenceFlag = 1;
}else if(confidence >=75){
confidenceFlag = 2;
}
Log.i("", "autopilot type is:" + type + "... timestamp: " + timestamp + "....confidence" + confidence + "...confidenceFlag:" + confidenceFlag);
Log.i("", "autopilot-----------------------------------------------END");
Motion activity = new Motion(timestamp, type, confidenceFlag);
Utils.appendLog("NEW MOTION: [" + activity.getTimestamp() + ", " + activity.getType() + ", " + activity.getConfidence() + "]" + rawData, true);
if(PSTripDBFactory.getInstance(context).getActiveTrip() != null){
PSMotionService.getInstance(context).motionsTrip.add(activity);
Log.i("", "autopilot added to trip: size is:" + PSMotionService.getInstance(context).motionsTrip.size());
if(PSLocationCenter.getInstance().pref.getGeoEnabled(context)) {
appendMotionActivity(context, type, activity);
}
}else{
Log.i("", "autopilot test to add to buffer");
appendMotionActivity(context, type, activity);
}
Log.i("", "autopilot-----------------------------------------------END AAAAALLLLLLL");
}
public void appendMotionActivity(Context context, int type, Motion activity) {
if(type != 0){
Log.i("", "autopilot appendMotionActivity type != 0");
Motion lastActivity = null;
int size = PSMotionService.getInstance(context).autoPilotPreCheckinMotionsBuffer.size();
if(size > 0){
lastActivity = PSMotionService.getInstance(context).autoPilotPreCheckinMotionsBuffer.get(size-1);
}
PSMotionService.getInstance(context).autoPilotPreCheckinMotionsBuffer.add(activity);
if(lastActivity != null){
Long duration = activity.getTimestamp() - lastActivity.getTimestamp();
Utils.appendLog("MOTION autoPilotPreCheckinMotionsBuffer motion size" + PSMotionService.getInstance(context).autoPilotPreCheckinMotionsBuffer.size(),true);
if(lastActivity != null && type * Math.min(activity.getConfidence(), 1) <= 1){
Log.i("", "autopilot received either low-confidence motion or stationary motion");
// received either low-confidence motion or stationary motion
Integer lastType = lastActivity.getType();
PSMotionService.getInstance(context).stationaryPeriod += duration;
if(lastType == PSMotionService.stationary && PSMotionService.getInstance(context).stationaryPeriod > 10){
Log.i("","autopilot Stationary/unknown motion for "+ PSMotionService.getInstance(context).stationaryPeriod +" secs > resetting auto-pilot motions buffer.");
Utils.appendLog("CHECKIN TIME STATIONARY for more than 10 seconds, checkin will be null", true);
PSMotionService.getInstance(context).autoPilotPreCheckinMotionsBuffer.clear();
PSMotionService.getInstance(context).stationaryPeriod = 0l;
PSMotionService.getInstance(context).movingPeriod = 0l;
PSMotionService.getInstance(context).checkinTime = null;
PSLocationCenter.getInstance().stopLocationClient();
}
}else{
PSMotionService.getInstance(context).movingPeriod += duration;
}
}
PSMotionService.getInstance(context).maybeTriggerAutoPilotFromMotionBuffer();
}
}
这就是我所说的活动:
ActivityRecognition.ActivityRecognitionApi.requestActivityUpdates(
mGoogleApiClient,
Constants.DETECTION_INTERVAL_IN_MILLISECONDS,
getActivityDetectionPendingIntent()
).setResultCallback(this);
现在我检查了一下,我没有在我的数据库中添加任何位置(我使用 REALM.io 库作为我的数据库)。所以这个错误对我来说根本没有意义。有没有其他人遇到过这个?有没有办法来解决这个问题?
PS:我在带有 Android 6 的 Nexus 5 上收到此错误