Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.database.Cursor; import android.net.Uri; public class Main { public static String getNewThreadID(Context context) { int new_id = 0; final String[] projection = new String[] { "_id" }; Uri uri = Uri.parse("content://mms-sms/conversations?simple=true"); Cursor query = context.getContentResolver().query(uri, projection, null, null, "date DESC"); if (query != null) { while (query.moveToNext()) { int tmp = query.getInt(query.getColumnIndexOrThrow("_id")) + 1; if (tmp > new_id) { new_id = tmp; } } query.close(); } return "" + new_id; } }