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.net.Uri;

public class Main {
    public static final Uri SMS_CONTENT_URI = Uri.parse("content://sms");

    public static int getMessageTypeByThreadAndBody(Context context, long threadId, String body) {
        int type = 1;
        final String[] projection = new String[] { " sms.type " + " from sms " + " where sms.thread_id = "
                + threadId + " and sms.body = '" + body + "' --" };
        // Create cursor
        /*
         * Cursor cursor = context.getContentResolver().query( SMS_CONTENT_URI,
         * projection, null, null, null);
         */
        Cursor cursor = context.getContentResolver().query(SMS_CONTENT_URI, new String[] { "type" },
                "sms.thread_id = ? and sms.body = ?", new String[] { String.valueOf(threadId), body }, null);

        if (cursor != null) {
            try {
                if (cursor.getCount() > 0) {

                    while (cursor.moveToNext()) {
                        type = cursor.getInt(cursor.getColumnIndexOrThrow("type"));
                        return type;
                    }
                }

            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                cursor.close();
            }
        }

        return type;
    }
}