PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, July 11, 2022

[FIXED] How many database columns associated with a SMS in android?

 July 11, 2022     android, messages, sms     No comments   

Issue

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?


Solution

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



Answered By - Vikas Patidar
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing