· 7 years ago · Sep 16, 2018, 10:46 AM
1Android sqlite insert is not inserting
2db.setVersion(1);
3 db.setLocale(Locale.getDefault());
4 db.setLockingEnabled(true);
5
6 final String gps =
7
8 "CREATE TABLE IF NOT EXISTS GPS_Values ("
9
10 + "id INTEGER PRIMARY KEY AUTOINCREMENT, Latitude float(10, 6), Longitude float(10, 6), cur_timestamp TIMESTAMP);";
11 db.execSQL(gps);
12
13// GPS
14public class MyLocationListener implements LocationListener {
15 public void onLocationChanged(Location loc) {
16 loc.getLatitude();
17 loc.getLongitude();
18
19 ContentValues gps_values = new ContentValues();
20
21 gps_values.put("Latitude", loc.getLatitude());
22 gps_values.put("Longitutde", loc.getLongitude());
23
24
25 try {
26 db.beginTransaction();
27 db.insert("GPS_Values", null, gps_values);
28 db.setTransactionSuccessful();
29 } finally {
30 db.endTransaction();
31 }
32
33 String Text = "My current location is: " + "Latitude = "
34 + loc.getLatitude() + "nLongitude = " + loc.getLongitude();
35
36 Toast.makeText(getApplicationContext(), Text, Toast.LENGTH_SHORT)
37 .show();
38
39 }
40
41 public void onProviderDisabled(String provider) {
42 Toast.makeText(getApplicationContext(), "Gps Disabled",
43 Toast.LENGTH_SHORT).show();
44 }
45
46 public void onProviderEnabled(String provider) {
47 Toast.makeText(getApplicationContext(), "Gps Enabled",
48 Toast.LENGTH_SHORT).show();
49 }
50
51 public void onStatusChanged(String provider, int status, Bundle extras) {
52 }
53
54}// gps vége
55
56gps_values.put("Longitutde", loc.getLongitude());
57
58gps_values.put("Longitude", loc.getLongitude());