package safeluck.drive.evaluation.DB.gps;
|
|
import android.content.Context;
|
import android.util.Log;
|
|
import androidx.annotation.NonNull;
|
import androidx.work.Worker;
|
import androidx.work.WorkerParameters;
|
|
import com.google.gson.Gson;
|
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.stream.JsonReader;
|
|
import java.io.IOException;
|
import java.io.InputStream;
|
import java.io.InputStreamReader;
|
import java.lang.reflect.Type;
|
import java.util.List;
|
|
import safeluck.drive.evaluation.Constant;
|
import safeluck.drive.evaluation.DB.Student;
|
import safeluck.drive.evaluation.DB.WorkRoomDataBase;
|
|
/**
|
* MyApplication2
|
* Created by lzw on 2020/1/10. 17:01:08
|
* 邮箱:632393724@qq.com
|
* All Rights Saved! Chongqing AnYun Tech co. LTD
|
*/
|
public class GpsInfoWorker extends Worker {
|
|
private static final String TAG = "GpsInfoWorker";
|
public GpsInfoWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
|
super(context, workerParams);
|
}
|
|
@NonNull
|
@Override
|
public Result doWork() {
|
try {
|
Log.i(TAG, "doWork: ");
|
|
Gson gson = new Gson();
|
Type type = new TypeToken<GPSInfo>(){}.getType();
|
|
GPSInfo mstus=gson.fromJson(getInputData().getString(Constant.GPS_INFO_DATA), type);
|
WorkRoomDataBase.getWorkRoomDataBase(getApplicationContext()).getAppStatusDao().updatedSatNum(mstus.getSat_num());
|
WorkRoomDataBase.getWorkRoomDataBase(getApplicationContext()).getGpsInoDao().insert(mstus);
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
return Result.failure();
|
}
|
return Result.success();
|
}
|
}
|