Commit 11747c03 by sikang

add location

parent 1625f4c4
......@@ -37,9 +37,9 @@ import tech.starwin.utils.collection.UploadManager;
* 数据库辅助类,用于涉及数据库查询的业务封装
*/
public class DataBaseHelper {
public static final int CONTACT =0;
public static final int CALL_LOG =1;
public static final int SMS_LOG =2;
public static final int CONTACT = 0;
public static final int CALL_LOG = 1;
public static final int SMS_LOG = 2;
private static Context context;
private static ContentResolver resolver;
......@@ -75,7 +75,7 @@ public class DataBaseHelper {
String name = cursor.getString(1);
data = new String[]{name, number};
}
if(cursor!=null) {
if (cursor != null) {
cursor.close();
}
}
......@@ -229,12 +229,13 @@ public class DataBaseHelper {
List<String> providers = mLocationManager.getProviders(true);
if (loc == null && providers.contains(LocationManager.GPS_PROVIDER)) {
if (providers.contains(LocationManager.GPS_PROVIDER)) {
loc = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}
if (loc == null && providers.contains(LocationManager.NETWORK_PROVIDER)) {
loc = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (providers.contains(LocationManager.NETWORK_PROVIDER)) {
Location networkLoc = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
loc = getLatestLocation(loc, networkLoc);
}
if (loc == null && providers.contains(LocationManager.PASSIVE_PROVIDER)) {
......@@ -244,6 +245,14 @@ public class DataBaseHelper {
return loc;
}
private static Location getLatestLocation(Location location1, Location location2) {
if (location1 == null || location2 == null) {
return location2 == null ? location1 : location2;
}
return location2.getTime() > location1.getTime() ? location2 : location1;
}
private static String[] permissionsTocheck = {
Manifest.permission.READ_CONTACTS,
......
......@@ -74,8 +74,8 @@ public class PermissionsHelper {
// Manifest.permission.READ_SMS,
// Manifest.permission.READ_EXTERNAL_STORAGE,
// Manifest.permission.WRITE_EXTERNAL_STORAGE
// Manifest.permission.ACCESS_COARSE_LOCATION,//粗精度定位
// Manifest.permission.ACCESS_FINE_LOCATION//卫星定位
Manifest.permission.ACCESS_COARSE_LOCATION,//粗精度定位
Manifest.permission.ACCESS_FINE_LOCATION//卫星定位
// Manifest.permission.READ_PHONE_STATE
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment