@@ -46,6 +46,7 @@ public class PhotoBean implements Serializable{
|
||
| 46 | 46 |
"photoId=" + photoId + |
| 47 | 47 |
", photoName='" + photoName + '\'' + |
| 48 | 48 |
", sessionSeq=" + sessionSeq + |
| 49 |
+ ", captureTime=" + captureTime + |
|
| 49 | 50 |
'}'; |
| 50 | 51 |
} |
| 51 | 52 |
|
@@ -101,7 +101,7 @@ public class DBService {
|
||
| 101 | 101 |
public void addPhotoBean(PhotoBean bean){
|
| 102 | 102 |
SQLiteDatabase db = null; |
| 103 | 103 |
synchronized (DB_LOCK) {
|
| 104 |
- LogHelper.d(TAG,"dbservice addUploadPhoto "+bean.photoId); |
|
| 104 |
+ LogHelper.d(TAG,"dbservice addUploadPhoto "+bean); |
|
| 105 | 105 |
try {
|
| 106 | 106 |
db = dbHelper.getWritableDatabase(); |
| 107 | 107 |
db.beginTransaction(); |
@@ -227,7 +227,7 @@ public class DBService {
|
||
| 227 | 227 |
try {
|
| 228 | 228 |
db = dbHelper.getReadableDatabase(); |
| 229 | 229 |
db.beginTransaction(); |
| 230 |
- long time = (System.currentTimeMillis()-30_1000); |
|
| 230 |
+ long time = (System.currentTimeMillis()-30_000); |
|
| 231 | 231 |
c = db.rawQuery("select * from " + DBHelper.PHOTO_INFO_TABLE + " where "
|
| 232 | 232 |
+ DBHelper.PHOTO_INFO_COLUMNS.UPLOADED_STATUS + " = '" + 0 + "'" |
| 233 | 233 |
+" and "+DBHelper.PHOTO_INFO_COLUMNS.CAPTURE_TIME+" <" +"'"+time |
@@ -3,7 +3,9 @@ package ai.pai.lensman.service; |
||
| 3 | 3 |
import android.app.Service; |
| 4 | 4 |
import android.content.Intent; |
| 5 | 5 |
import android.os.Binder; |
| 6 |
+import android.os.Handler; |
|
| 6 | 7 |
import android.os.IBinder; |
| 8 |
+import android.os.Message; |
|
| 7 | 9 |
|
| 8 | 10 |
import com.android.common.executors.ThreadExecutor; |
| 9 | 11 |
import com.android.common.utils.LogHelper; |
@@ -11,14 +13,22 @@ import com.android.common.utils.LogHelper; |
||
| 11 | 13 |
import ai.pai.lensman.bean.PhotoBean; |
| 12 | 14 |
import ai.pai.lensman.db.DBService; |
| 13 | 15 |
|
| 14 |
-public class UploadService extends Service implements UploadTask.OnPhotoUploadListener{
|
|
| 16 |
+public class UploadService extends Service implements UploadTask.OnPhotoUploadListener,Handler.Callback{
|
|
| 15 | 17 |
|
| 16 | 18 |
private PhotoBean currentPhoto; |
| 17 | 19 |
private PhotoUploadListener listener; |
| 20 |
+ private Handler handler; |
|
| 21 |
+ private static final int MSG_TRY_UPLOAD = 4567; |
|
| 18 | 22 |
|
| 19 | 23 |
private static final String TAG = "UploadService"; |
| 20 | 24 |
|
| 21 | 25 |
@Override |
| 26 |
+ public void onCreate() {
|
|
| 27 |
+ super.onCreate(); |
|
| 28 |
+ handler = new Handler(this); |
|
| 29 |
+ } |
|
| 30 |
+ |
|
| 31 |
+ @Override |
|
| 22 | 32 |
public IBinder onBind(Intent intent) {
|
| 23 | 33 |
return new MyBinder(); |
| 24 | 34 |
} |
@@ -39,8 +49,11 @@ public class UploadService extends Service implements UploadTask.OnPhotoUploadLi |
||
| 39 | 49 |
LogHelper.d(TAG,"当前有图片正在上传"+currentPhoto); |
| 40 | 50 |
return; |
| 41 | 51 |
} |
| 52 |
+ LogHelper.d(TAG,"查询是否有可以上传的照片,时间="+System.currentTimeMillis()); |
|
| 42 | 53 |
currentPhoto = DBService.getInstance().getNextUploadPhoto(); |
| 43 | 54 |
if(currentPhoto==null){
|
| 55 |
+ handler.removeMessages(MSG_TRY_UPLOAD); |
|
| 56 |
+ handler.sendEmptyMessageDelayed(MSG_TRY_UPLOAD,2000); |
|
| 44 | 57 |
LogHelper.d(TAG,"本地图片已全部上传"); |
| 45 | 58 |
return; |
| 46 | 59 |
} |
@@ -78,6 +91,15 @@ public class UploadService extends Service implements UploadTask.OnPhotoUploadLi |
||
| 78 | 91 |
this.listener = listener; |
| 79 | 92 |
} |
| 80 | 93 |
|
| 94 |
+ @Override |
|
| 95 |
+ public boolean handleMessage(Message message) {
|
|
| 96 |
+ if(message.what == MSG_TRY_UPLOAD){
|
|
| 97 |
+ startUpload(); |
|
| 98 |
+ return true; |
|
| 99 |
+ } |
|
| 100 |
+ return false; |
|
| 101 |
+ } |
|
| 102 |
+ |
|
| 81 | 103 |
public interface PhotoUploadListener{
|
| 82 | 104 |
void onPhotoUploaded(PhotoBean bean); |
| 83 | 105 |
void onPhotoUploadError(PhotoBean bean); |