我是新手。.我想知道我的案子是否可能,因为我没有如何做的参考。...
在我的数据库助手上:
public boolean saveLocationToLocalDatabase(String serialNumber, String
latitude, String longitude, String dateTime, String speed, String
port, SQLiteDatabase db)
{
ContentValues contentValues = new ContentValues();
contentValues.put(SERIALNUMBER, serialNumber);
contentValues.put(LATITUDE, latitude);
contentValues.put(LONGITUDE, longitude);
contentValues.put(DATE_TIME, dateTime);
contentValues.put(SPEED, speed);
contentValues.put(PORT, port);
long locationResult=db.insert(TABLE_FLEET_LOCATION, null,
contentValues);
if (locationResult == -1)
return false;
else
return true;
}
这是我的onclicklistener,可以将我的数据提取到我的sqlite数据库中。
locate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick( View view) {
mMap.setOnMyLocationChangeListener(new
GoogleMap.OnMyLocationChangeListener() {
@Override
public void onMyLocationChange(Location location) {
CameraUpdate center = CameraUpdateFactory.newLatLng(new
LatLng(location.getLatitude(), location.getLongitude()));
CameraUpdate zoom = CameraUpdateFactory.zoomTo(15);
mMap.clear();
MarkerOptions mp = new MarkerOptions();
mp.position(new LatLng(location.getLatitude(),
location.getLongitude()));
mp.title("");
mMap.addMarker(mp);
mMap.moveCamera(center);
mMap.animateCamera(zoom);
String gg =Settings.Secure.getString(getApplicationContext()
.getContentResolver(),Settings.Secure.ANDROID_ID);
lat = Double.toString(location.getLatitude());
lon = Double.toString(location.getLongitude());
well = String.valueOf(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",
java.util.Locale.getDefault()).format(new java.util.Date()));
speed="0000";
port="9090";
}
这是我将数据保存到我的数据库中
DatabaseHelper databaseHelper = new
DatabaseHelper(getApplicationContext());
SQLiteDatabase db = databaseHelper.getWritableDatabase();
boolean accepted = databaseHelper.saveLocationToLocalDatabase(gg,lat,
lon, well,speed,port, db);
if (accepted == true)
Log.w("Data Entered:","MAIN");
}
如果我在数据上找到:这是我的sqlite数据库上的示例字段: 注意:如果您发现本人在更改数据之前已保存5个数据,因为自从数据以来,我想每秒钟保存一次,然后再检索其他数据。
这是我的情况,有可能这样做吗?”“我很想获取所有数据,并通过json对象构造所有数据,并通过改型发送给api”。
顺便说一句,我的最后一个代码是从onclick侦听器中获取一次数据,但是ive想做另一种方式(保存数据(例如5-10个数据,并通过翻新将其全部发送到api))出于我的错误捕获目的。先前的改装代码: 私人void sendAllToApi(){
MapDetails mapDetails = new MapDetails(gg, lat, lon,
well, "0", portInts); //Data ive get once ive pressed
onclicklistener
List<MapDetails> data = new ArrayList<>();
data.add(mapDetails);
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl("http://" + ADDRESS + ":" + PORT)//this
is my configuration for api link
.addConverterFactory(GsonConverterFactory.create());
Retrofit retrofit = builder.build();
Api locate = retrofit.create(Api.class);
Call<MapDetails> call = locate.mapDetailLocation(data);
call.enqueue(new Callback<MapDetails>() {
@Override
public void onResponse(Call<MapDetails> call,
Response<MapDetails> response) {
Snackbar.make(view, "" + response,
Snackbar.LENGTH_INDEFINITE)
.setAction("Action", null).show();
}
@Override
public void onFailure(Call call, Throwable t) {
Snackbar.make(view, "" + t.getMessage(),
Snackbar.LENGTH_INDEFINITE)
.setAction("Action", null).show();
}
});
}