postheadericon Read SMS in Android

Definition: Read messages from the mobile and display it on the screen


E13Activity.java


package bsr.exa;

import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;



public class E13Activity extends Activity
{
    /**  @author Bipin S Rupadiya , www.bipinrupadiya.com
     *
     *  13) Read messages from the mobile and display it on the screen
     *
     *  */

@Override
public void onCreate(Bundle savedInstanceState)
{
     super.onCreate(savedInstanceState);
     TextView view = new TextView(this);
     Uri uriSMS = Uri.parse("content://sms/inbox");
     Cursor c = getContentResolver().query(uriSMS, null, null, null,null);
     String sms = "";
     while (c.moveToNext()) {
         sms += "From :" + c.getString(2) + " : " + c.getString(11)+"\n";      
     }
     view.setText(sms);
     setContentView(view);
}
}

AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="bsr.exa"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.READ_SMS"></uses-permission>
    <uses-permission android:name="android.permission.SEND_SMS"></uses-permission>

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".E13Activity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>



0 comments:

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.