views:

54

answers:

3

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?

+1  A: 

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: http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/provider/Telephony.java.

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

EboMike
Hi EboMike, thanks for reply and you are completely right this is not included in official API but still I can use it at my own risk. Could you please tell me the list of the phones brands (other then HTC) which also provide their own API for this?
Creative-MITian
@EboMike: what should be the preferred way of accessing the SMS store? Should we manually create the conversation lists?
Sotapanna
+1  A: 

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();
Sotapanna
Thank you The Sotapanna for quick response and now I have got exactly what I'm looking for.
Creative-MITian
A: 

Hi Sotapanna,

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

Creative-MITian