Thursday, May 17, 2012

Example 2:

Example 2:

Continuation of Example 1,

Add one more button to main.xml layout and name it as Activity.
Then add another layout called activity1.xml, For that right click on the layout folder --> new --> Android Xml File

Wednesday, May 16, 2012

Example 1:

Example 1:

Open 'main.xml' from layout folder.
Then from toolbox add,
And rename the button by right clicking on the button and select 'Edit text..' to 'Done'

First Project in Android

First Project in Android

1. Goto Eclipse,then
2. File --> New--> Android Project
3. Project Name : MyFirstAndroidProject (Create new Project in workspace) ,Then Next,
4. Check Android2.2 and next
5. Don't Change Application name,
   Package name : com.jeeth.examples.myfirstandroidproject
   Then Press Finish.

Tuesday, May 15, 2012

Setup Android SDK and Eclipse IDE for Android Application Development

First, Setuping IDE for Android Development

1.Download Eclipse IDE for Java Developers
2.Download Android sdk and install.
(It may take 2 or more hours to finish the installation)
3.Ten unzip the eclipse file. Then execute it.
4.After that goto Help in eclipse, and Select Install new softwares. Then select 'Add'.
(Name : Android
Then Press Ok.

Monday, May 7, 2012

Creating Notification in Android

Here is a code for creating notification for your application. Copy the below code to your project, 

private void createNotification(String tickerText, String contentTitle,
String contentText, int notiIcon) {
String notiservice = Context.NOTIFICATION_SERVICE;
NotificationManager notimanager = (NotificationManager) getSystemService(notiservice);

int icon = notiIcon;
CharSequence tickerText = tickerText;
long when = System.currentTimeMillis();
Context context = getApplicationContext();
CharSequence contentTitle = contentTitle;
CharSequence contentText = contentText;

Intent notiIntent = new Intent(this, Options.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0,
notiIntent, 0);

Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText,

final int ID = 1;
notimanager.notify(ID, notification);

And then call it with following parameters,
createNotification("My Notification", "Jimmanz", "Notification Started",

Shake effect in Android

Shake effect in Android

We can give shaking effect for any layout component in android.
For that first we have to create a folder anim under res folder. In anim first create an xml 'cycle_7.xml'
<?xml version="1.0" encoding="utf-8"?>
<cycleInterpolator xmlns:android="" android:cycles="7" />

Then create another xml called 'shake.xml'
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="
android:interpolator="@anim/cycle_7" />

Then in class file,import these two,
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

Then add this in code,(when and where that you can decide),
Animation shake = AnimationUtils.loadAnimation(CurrentActivity.this, R.anim.shake);

Now run.............!

Creating Analog clock Widget in Android

Creating Analog clock Widget in Android

<uses-sdk android:minSdkVersion="7" />

    android:label="@string/app_name" >
        android:label="@string/app_name" >

        android:label="CR CLOCK" 
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            android:resource="@xml/jeethappwidget" />

No need of programing in WidgetClockClass.class,
import android.appwidget.AppWidgetProvider;

public class WidgetClockClass extends AppWidgetProvider {


Create a folder 'xml' in res folder, then inside that create an xml for appwidget provider,
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="" 

Then create a layout called clock.xml in layout folder,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" >


        android:layout_height="wrap_content" />


Tracking call from a particular number in Android

Tracking call from a particular number in Android

Here manifest looks like,
<uses-permission android:name="android.permission.READ_PHONE_STATE" >
android:permission="android.permission.READ_PHONE_STATE" >
    <action android:name="android.intent.action.PHONE_STATE" >

And broadcast receiver will invoked when a call comes,
For a call, there are three states,
1. Ringing
2. Idle
3. Offhook

public class ReceiveCallToMute extends BroadcastReceiver {

public void onReceive(Context context, Intent intent) {
  Bundle b=intent.getExtras();
  String state=b.getString(TelephonyManager.EXTRA_STATE);
  String number=b.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
  if(number.indexOf("9447024365") != -1) {
  }else if(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){
  }else if(state.equals(TelephonyManager.EXTRA_STATE_RINGING)){  

Sunday, May 6, 2012

Deleting an sms from a particular number in Android

For deleting an sms from a particular number.
Here we have to use a Broadcast receiver. When an sms is receiving, this broacast receiver will invoked.
So our manifest will look like this,

<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />

<receiver android:name="Receiverdetectsms" android:permission="android.permission.BROADCAST_SMS" >
<intent-filter android:priority="999" >
    <action android:name="android.provider.Telephony.SMS_RECEIVED" />

And (Broadcast receiver) "Receiverdetectsms"  will look like,
public class Receiverdetectsms extends BroadcastReceiver {

public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
if (bundle != null) {
/* Retrieve the SMS. */
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i = 0; i < msgs.length; i++) {
msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
if (msgs[i].getOriginatingAddress().indexOf("9447024365") != -1) {
abortBroadcast();//delete sms from 9447024365


Async Task in Android

Here in asynctask, there are some overrided functions,
1. doInBackground
2. onPreExecute(execute before doInBackground)
3. onPostExecute(execute after doInBackground)
4. onProgressUpdate(doInBackground can call this function while its executing using  'publishProgress(integer value)'. Mainly for showing progress bar while downloading or uploading something)

private class SyncIncoData extends AsyncTask<String, String, String> {
ProgressBar pb;
ProgressBar pbar;

protected String doInBackground(String... urls) {
for (int i = 0; i <= 100; i++) {
return null;

protected void onPreExecute() {


pb = (ProgressBar) findViewById(;


protected void onPostExecute(String result) {

pb = (ProgressBar) findViewById(;


protected void onProgressUpdate(String... values) {
pbar = (ProgressBar) findViewById(;

For calling async task,
SyncIncoData task = new SyncIncoData();
task.execute(new String[] { null });