Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.content.Context;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.provider.Telephony;

public class Main {
    public static final int MESSAGE_TYPE = 0x8C;
    public static final int MESSAGE_TYPE_SEND_REQ = 0x80;
    public static final int MESSAGE_ID = 0x8B;

    protected static long findThreadId(Context context, String messageId) {
        StringBuilder sb = new StringBuilder('(');
        sb.append(Telephony.Mms.MESSAGE_ID);
        sb.append('=');
        sb.append(DatabaseUtils.sqlEscapeString(messageId));
        sb.append(" AND ");
        sb.append(Telephony.Mms.MESSAGE_TYPE);
        sb.append('=');
        sb.append(MESSAGE_TYPE_SEND_REQ);

        // TODO ContentResolver.query() appends closing ')' to the selection argument
        // sb.append(')');

        Cursor cursor = context.getContentResolver().query(Telephony.Mms.CONTENT_URI,
                new String[] { Telephony.Mms.THREAD_ID }, sb.toString(), null, null);

        if (cursor != null) {
            try {
                if ((cursor.getCount() == 1) && cursor.moveToFirst()) {
                    return cursor.getLong(0);
                }
            } finally {
                cursor.close();
            }
        }

        return -1;
    }
}