diff --git a/app/src/main/java/com/termux/api/SmsInboxAPI.java b/app/src/main/java/com/termux/api/SmsInboxAPI.java index 7cda2df4..42b7c252 100644 --- a/app/src/main/java/com/termux/api/SmsInboxAPI.java +++ b/app/src/main/java/com/termux/api/SmsInboxAPI.java @@ -59,7 +59,7 @@ public static void getConversations(Context context, JsonWriter out, int offset, ContentResolver cr = context.getContentResolver(); String sortOrder = "date DESC"; try (Cursor c = cr.query(Conversations.CONTENT_URI, null, null, null , sortOrder)) { - c.moveToFirst(); + c.moveToLast(); Map nameCache = new HashMap<>(); @@ -77,7 +77,7 @@ public static void getConversations(Context context, JsonWriter out, int offset, cc.moveToFirst(); writeElement(cc, out, nameCache, context); cc.close(); - c.moveToNext(); + c.moveToPrevious(); } out.endArray(); } @@ -123,9 +123,9 @@ private static void writeElement(Cursor c, JsonWriter out, Map n public static void getAllSms(Context context, JsonWriter out, int offset, int limit, String number, Uri contentURI) throws IOException { ContentResolver cr = context.getContentResolver(); String sortOrder = "date DESC LIMIT + " + limit + " OFFSET " + offset; - try (Cursor c = cr.query(contentURI, null, - ADDRESS + " LIKE '%" + number + "%'",null, sortOrder)) { - c.moveToFirst(); + try (Cursor c = cr.query(contentURI, null, + ADDRESS + " LIKE '%" + number + "%'", null, sortOrder)) { + c.moveToLast(); new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Map nameCache = new HashMap<>(); @@ -133,7 +133,7 @@ public static void getAllSms(Context context, JsonWriter out, int offset, int li out.beginArray(); for (int i = 0, count = c.getCount(); i < count; i++) { writeElement(c, out, nameCache, context); - c.moveToNext(); + c.moveToPrevious(); } out.endArray(); }