Vikas Patidar
Vikas Patidar

Reputation: 43359

How many database columns associated with a SMS in android?

I want to read all the messages and their respective details from my phone. For this I am using the Uri like this:

Uri sms = Uri.parse("content://sms/");

But I don't know how many columns in database which are associated with this uri.

I want to display the following information:

  1. Message Type
  2. Sender Number
  3. Message Body
  4. Timestamp

Please can anybody enumerate the total column names?

Upvotes: 24

Views: 28301

Answers (6)

Lau
Lau

Reputation: 1834

If you just want to know what is stored in particular cursor you can simply use DatabaseUtils.dumpCursor(cursor); to display all columns with values on your console

Upvotes: 0

Shwarz Andrei
Shwarz Andrei

Reputation: 707

Just try this:

public void showAllCNames (View v){
        Uri uri = Uri.parse("content://sms/");
        final Cursor cur = getContentResolver().query(uri, null, null, null, null);
        for (String s : cur.getColumnNames()){Log.d("COLUMN_NAME", s);}
}

I ran through the column name and got it:

COLUMN_NAME: _id

COLUMN_NAME: thread_id

COLUMN_NAME: address

COLUMN_NAME: person

COLUMN_NAME: date

COLUMN_NAME: date_sent

COLUMN_NAME: sc_timestamp

COLUMN_NAME: protocol

COLUMN_NAME: read

COLUMN_NAME: status

COLUMN_NAME: type

COLUMN_NAME: reply_path_present

COLUMN_NAME: subject

COLUMN_NAME: body

COLUMN_NAME: service_center

COLUMN_NAME: locked

COLUMN_NAME: sub_id

COLUMN_NAME: error_code

COLUMN_NAME: seen

COLUMN_NAME: lgeMsgType

COLUMN_NAME: lgeSiid

COLUMN_NAME: lgeCreated

COLUMN_NAME: lgeExpires

COLUMN_NAME: lgeReceived

COLUMN_NAME: lgeAction

COLUMN_NAME: lgeSec

COLUMN_NAME: lgeMac

COLUMN_NAME: lgeDoc

COLUMN_NAME: doInstalled

COLUMN_NAME: lgePinRemainCnt

COLUMN_NAME: index_on_icc

COLUMN_NAME: service_msg_sender_address

COLUMN_NAME: lgeCallbackNumber

COLUMN_NAME: sms_imsi_data

Upvotes: 5

kalabog76
kalabog76

Reputation: 21

Android 4.4.2 phone Since this is version/content specific, do not rely on the numberic index key

_id thread_id address m_size person date date_sent protocol read status type reply_path_present subject body service_center locked sim_id error_code seen ipmsg_id

Upvotes: -1

EboMike
EboMike

Reputation: 77752

content://sms is not part of the official Android API, and as such it's not a good idea to use it. It may stop working, and some phones that use their own implementations for SMS (HTC Sense, maybe?) may have their own content provider that won't work with your code.

That said, if you really want to dig into it, you can look at the source code for it.

But again, heed this warning: http://android-developers.blogspot.com/2010/05/be-careful-with-content-providers.html.

Upvotes: 6

Vikas Patidar
Vikas Patidar

Reputation: 43359

package com.readsms;

import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

public class ReadSMS extends Activity 
{
    private static final String tag = "Whozzat";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Uri sms = Uri.parse("content://sms/inbox");
        ContentResolver cr = this.getContentResolver();
        Cursor c = cr.query(sms, null, null, null, null);
        for (int i = 0; i < c.getColumnCount(); i++)
        {
            Log.v(tag, c.getColumnName(i).toString());
        }
        c.close();
    }
}

after running this code snippet I have got the following columns:

alt text

Upvotes: 54

Dennis Winter
Dennis Winter

Reputation: 2037

You should be able to rotate through the Cursor and look for yourself:

mCursor = managedQuery(sms, null, null, null, null);

StringBuffer info = new StringBuffer();
for( int i = 0; i < mCursor.getColumnCount(); i++) {
    info.append("Column: " + mCursor.getColumnName(i) + "\n");
}
Toast.makeText(getApplicationContext(), info.toString(), Toast.LENGTH_LONG).show();

Upvotes: 25

Related Questions