Exercise : 13
Read messages from
the mobile and display it on the screen.
Screen Shot:
XML :
main.xml :
JAVA :
ThirteenActivity.java :
package kmn.Thirteen;
import android.app.Activity;
import android.database.Cursor;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;
public class ThirteenActivity extends Activity
{
/** @author Y@@D */
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
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);
view.setBackgroundColor(Color.BLUE);
view.setTextColor(Color.WHITE);
setContentView(view);
}
}
