Wednesday, 23 November 2011

Progress Dialog


import android.app.Activity;

import android.app.ProgressDialog;

import android.content.pm.ActivityInfo;

import android.os.Bundle;


public class ProgressDialogActivity extends Activity {

/** Called when the activity is first created. */

ProgressDialog pro;

@Override

public void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);

setContentView(R.layout.main);

pro=new ProgressDialog(this);

pro.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

pro.setMax(300);

pro.setCancelable(true);

pro.setMessage("Loading data..");

pro.show();

Threadex t=new Threadex();

t.start(); //start thread

}//This is Oncreate method

class Threadex extends Thread

{


public void run()

{

for(int i=10;i<=pro.getMax();i=i+10)

{

pro.incrementProgressBy(10);

try

{

sleep(1000); //sleep for 1 seconds

}

catch(Exception e)

{

e.printStackTrace();

}

} //this is for loop ends

pro.dismiss();

} //this is end of Run

}//This is End of Threadex

} //This is End of Activity


Here Update the 10 distance continues Upto 300 distance because we have set 300 distance as max .




This is after the Dismiss the ProgressDialog





This is for ProgressDialog.STYLE_HORIZONTAL.

we can set Another Style ProgressDialog.STYLE_SPINNER but view is different

Monday, 14 November 2011

Getting SMS in your Activity

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

public class SMSActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
Uri url = Uri.parse("content://sms/inbox");
Cursor cursor = getContentResolver().query(url, null, null, null,null);
String smsdisplay = "";
while (cursor.moveToNext()) {
smsdisplay += "From :" + cursor.getString(2) + " : " + cursor.getString(11)+"\n";
}
textview.setText(smsdisplay);
setContentView(textview);
}
}

in the AndroidManifest.xml

android.permission.READ_SMS

Gives this Permission for Reading SMS in your activity.