Showing posts from 2012


A service is an application component that can perform long-running operations in the background and does not provide a user interface. Another application component can start a service and it will continue to run in the background even if the user switches to another application. Additionally, a component can bind to a service to interact with it and even perform interprocess communication (IPC). For example, a service might handle network transactions, play music, perform file I/O, or interact with a content provider, all from the background


View is the base class for widgets, which are used to create interactive UI components (buttons, text fields, etc.). All of the views in a window are arranged in a single tree. You can add views either from code or by specifying a tree of views in one or more XML layout files. There are many specialized subclasses of views that act as controls or are capable of displaying text, images, or other content. The base LayoutParams class just describes how big the view wants to be for both width and height. For each dimension, it can specify one of:
an exact number MATCH_PARENT, which means the view wants to be as big as its parent (minus padding) WRAP_CONTENT, which means that the view wants to be just big enough to enclose its content (plus padding).

Example For ListView Using BaseAdapter

Above is an example of ListView in android which extends BaseAdapter. Here we are inflating Layout to ListView.
Code: public class ListExample extends ListActivity {
private ArrayList<String> dataname = new ArrayList<String>(); private ArrayList<String> datacode = new ArrayList<String>(); Context con = this;


Dalvik Debug Monitor Service, a GUI debugging application shipped with
the SDK. It provides screen capture, log dump, and process examination


A class (Intent) describes what a caller desires to do. The caller
sends this intent to Android's intent resolver, which finds the most
suitable activity for the intent. E.g. opening a PDF file is an
intent, and the Adobe Reader is the suitable activity for this inten

Android application package file (APK)

Android application package file (APK) is the file format used to
distribute and install application software and middleware onto
Google's Android operating system. To make an APK file, a program for
Android is first compiled, and then all of its parts are packaged into
one file. This holds all of that program's code such as (.dex files),
resources, assets, certificates, and manifest file. As is the case
with many file formats, APK files can have any name needed, but must
end with the four character, three letter extension, .apk.[1][2][3][4]
APK files are ZIP file formatted packages based on the JAR file format.

Android Debug Bridge

Android Debug Bridge, a command-line debugging application shipped with the SDK. It provides tools to browse the device, copy tools on the device, and forward ports for debugging. Android Debug Bridge. A tool used to connect and sends commands to your Android phone from a desktop or laptop computer.

Android Application Architecture

Services - like Network OperationIntent - To perform inter-communication between activities or servicesResource Externalization - such as strings and graphicsNotification signaling users - light, sound, icon, notification, dialog etc.Content Providers - They share data between applications

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

Example 1:

Example 1:
Open 'main.xml' from layout folder. Then from toolbox add, 1.EditText 2.Button 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.

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 Location :  Then Press Ok.

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, pIntent);
final int ID = 1; notimanager.notify(ID, notification); }
And then call it with following parameters, createNotification("My Notification", "Jimmanz", &q…

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:fromXDelta="0"  android:toXDelta="10"  android:duration="1000"  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)…

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 App…

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) {


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" /> </intent-filter> </receiver>

And (Broadcast receiver) "Receiverdetectsms"  will look like, public class Receiverdetectsms extends BroadcastReceiver {
@Override 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"); msg…

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;
@Override protected String doInBackground(String... urls) { for (int i = 0; i <= 100; i++) { publishProgress(i); } return null; }
@Override protected void onPreExecute() {
pb = (ProgressBar) findViewById(; pb.setVisibility(View.VISIBLE);
@Override protected void onPostExecute(String result) {
pb = (ProgressBar) findViewById(; pb.setVisibility(View.INVISIBLE);
@Override protected void onProgressUpdate(String... values) { pbar = (ProgressBar) findViewById(…