Thursday, March 31, 2011

Get Android device ID, Settings.Secure.ANDROID_ID

Settings.Secure.ANDROID_ID is a 64-bit number (as a hex string) that is randomly generated on the device's first boot and should remain constant for the lifetime of the device. (The value may change if a factory reset is performed on the device.)

Settings.Secure.ANDROID_ID on Nexus One
Settings.Secure.ANDROID_ID on Android Emulator

ANDROID_ID seems a good choice for a unique device identifier. There are downsides as stated in Android Developers Blog, Identifying App Installations: First, it is not 100% reliable on releases of Android prior to 2.2 (“Froyo”). Also, there has been at least one widely-observed bug in a popular handset from a major manufacturer, where every instance has the same ANDROID_ID.

package com.exercise.AndroidId;

import android.app.Activity;
import android.os.Bundle;
import android.provider.Settings;
import android.widget.TextView;

public class AndroidId extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

TextView textAndroidId = (TextView)findViewById(R.id.androidid);
String AndroidId = Settings.Secure.getString(getContentResolver(),
Settings.Secure.ANDROID_ID);
textAndroidId.setText("My ID is: " + AndroidId);
}
}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<TextView
android:id="@+id/androidid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>

Wednesday, March 30, 2011

SlidingDrawer

SlidingDrawer hides content out of the screen and allows the user to drag a handle to bring the content on screen. SlidingDrawer can be used vertically or horizontally. A special widget composed of two children views: the handle, that the users drags, and the content, attached to the handle and dragged with it. SlidingDrawer should be used as an overlay inside layouts. This means SlidingDrawer should only be used inside of a FrameLayout or a RelativeLayout for instance. The size of the SlidingDrawer defines how much space the content will occupy once slid out so SlidingDrawer should usually use match_parent for both its dimensions. Inside an XML layout, SlidingDrawer must define the id of the handle and of the content.



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="300dip"
android:layout_gravity="bottom"
android:background="#808080">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Something here: \nIt's a exercise \nof SlidingDrawer"
/>
<SlidingDrawer
android:id="@+id/drawer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:handle="@+id/handle"
android:content="@+id/content">
<ImageView
android:id="@id/handle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/icon"
android:background="#404040"/>
<LinearLayout
android:id="@id/content"
android:layout_width="fill_parent"
android:layout_height="200dip"
android:orientation="vertical"
android:background="#606060"
>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" - Button - "/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" - Button - "/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" - Button - "/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="It's content of SlidingDrawer"/>
</LinearLayout>
</SlidingDrawer>
</FrameLayout>
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="5dip"
android:text=" - A Bit Button - "/>
</LinearLayout>



Related:
- SlidingDrawer in horizontal
- Inflate SlidingDrawer from XML



Tuesday, March 29, 2011

Java String Comparison: equals()? ==?

It's a issue of Java programming language, not Android.

String in Java is object, of java.lang.String class. It have some ways to be initialized, such as:
String s = "hello";
String s = new String("hello");
Is it same?

Java's String class provide a method equals() to compare two string. Sometimes we can use "==", but not always! Here are some examples:

String Comparison

package com.exercise.AndroidStringCompare;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class AndroidStringCompare extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView Result1 = (TextView)findViewById(R.id.result1);
TextView Result2 = (TextView)findViewById(R.id.result2);
TextView Result3 = (TextView)findViewById(R.id.result3);
TextView Result4 = (TextView)findViewById(R.id.result4);
TextView Result5 = (TextView)findViewById(R.id.result5);
TextView Result6 = (TextView)findViewById(R.id.result6);
TextView Result7 = (TextView)findViewById(R.id.result7);
TextView Result8 = (TextView)findViewById(R.id.result8);
TextView Result9 = (TextView)findViewById(R.id.result9);
TextView Result10 = (TextView)findViewById(R.id.result10);

String s1 = "hello";
String s2 = "hello";
String s3 = s1;
String s4 = "h" + "e" + "l" + "l" + "o";
String s5 = new String("hello");
String s6 = new String(new char[]{'h', 'e', 'l', 'l', 'o'});


Result1.setText(s1 + " == " + s2 + ": " + (s1 == s2));
Result2.setText(s1 + " equals " + s2 + ": " + (s1.equals(s2)));
Result3.setText(s1 + " == " + s3 + ": " + (s1 == s3));
Result4.setText(s1 + " equals " + s3 + ": " + (s1.equals(s3)));
Result5.setText(s1 + " == " + s4 + ": " + (s1 == s4));
Result6.setText(s1 + " equals " + s4 + ": " + (s1.equals(s4)));
Result7.setText(s1 + " == " + s5 + ": " + (s1 == s5));
Result8.setText(s1 + " equals " + s5 + ": " + (s1.equals(s5)));
Result9.setText(s1 + " == " + s6 + ": " + (s1 == s6));
Result10.setText(s1 + " equals " + s6 + ": " + (s1.equals(s6)));
}
}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<TextView
android:id="@+id/result1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/result2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/result3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/result4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/result5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/result6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/result7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/result8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/result9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/result10"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>

Monday, March 28, 2011

Set Wallpaper using WallpaperManager

In this exercise, a picture (packed inside our app) will be set as system wallpaper, using WallpaperManager.

* Please note that in order to use WallpaperManager, minimum API level have to be set to 5.

Set Wallpaper using WallpaperManager
Set Wallpaper using WallpaperManager

First of all, prepare a picture (wallpaper.png in my case) and save it in /res/drawable/ folder of your project.

main code
package com.exercise.AndroidWallpaper;

import java.io.IOException;

import android.app.Activity;
import android.app.WallpaperManager;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class AndroidWallpaper extends Activity {
 
 Bitmap bitmap;
 
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
      
       Button buttonSetWallpaper = (Button)findViewById(R.id.set);
       ImageView imagePreview = (ImageView)findViewById(R.id.preview);

       imagePreview.setImageResource(R.drawable.wallpaper);
      
       buttonSetWallpaper.setOnClickListener(new Button.OnClickListener(){

   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    WallpaperManager myWallpaperManager
     = WallpaperManager.getInstance(getApplicationContext());
    try {
     myWallpaperManager.setResource(R.drawable.wallpaper);
    } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
    
   }});

   }
}


main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   >
<TextView 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="@string/hello"
   />
<Button
  android:id="@+id/set"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="Set Wallpaper"
  />
<ImageView
  android:id="@+id/preview"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  />
</LinearLayout>


Finally, you have to modify AndroidManifest.xml to grant permission of "android.permission.SET_WALLPAPER".
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.exercise.AndroidWallpaper"
     android:versionCode="1"
     android:versionName="1.0">
   <uses-sdk android:minSdkVersion="5" />
   <uses-permission android:name="android.permission.SET_WALLPAPER"></uses-permission>

   <application android:icon="@drawable/icon" android:label="@string/app_name">
       <activity android:name=".AndroidWallpaper"
                 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>


Download the files.

Updated@2016-03-03:
Load photo and set Wallpaper


Sunday, March 27, 2011

Pick a file using Intent.ACTION_GET_CONTENT

If you have to pick a file in your app, but you don't want to implement your own file explorer; you can start a activity with intent of Intent.ACTION_GET_CONTENT. Android OS will choice a suitable app with such function for you.

Pick a file using Intent.ACTION_GET_CONTENT

package com.exercise.AndroidPick_a_File;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class AndroidPick_a_File extends Activity {
 
 TextView textFile;
 
 private static final int PICKFILE_RESULT_CODE = 1;
 
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
      
       Button buttonPick = (Button)findViewById(R.id.buttonpick);
       textFile = (TextView)findViewById(R.id.textfile);
      
       buttonPick.setOnClickListener(new Button.OnClickListener(){

   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
             intent.setType("file/*");
       startActivityForResult(intent,PICKFILE_RESULT_CODE);
    
   }});
   }

 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  // TODO Auto-generated method stub
  switch(requestCode){
  case PICKFILE_RESULT_CODE:
   if(resultCode==RESULT_OK){
    String FilePath = data.getData().getPath();
    textFile.setText(FilePath);
   }
   break;
   
  }
 }
}


main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   >
<TextView 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="@string/hello"
   />
<Button
   android:id="@+id/buttonpick"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="- PICK a file -"
   />
<TextView 
   android:id="@+id/textfile"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   />
</LinearLayout>


Download the files.

Related:
- More for Pick a file using Intent.ACTION_GET_CONTENT


Updated@2017-06-19:
Please read update post about open document:
Using Intent.ACTION_OPEN_DOCUMENT, for KitKat API 19 or higher
Open images with Intent.ACTION_OPEN_DOCUMENT, Intent.ACTION_GET_CONTENT and Intent.ACTION_PICK
Open mp3 using Intent.ACTION_OPEN_DOCUMENT, ACTION_GET_CONTENT and ACTION_PICK, with checking and requesting permission at runtime


Send SMS in Alarm Service at a pre-defined time

In former exercises, it have been shown how to "Send SMS using android.telephony.SmsManager" and "A simple example of Alarm Service, using AlarmManager".

It's a exercise merge them together, start a alarm service in a pre-defined time (10 second), and send SMS using SmsManager inside service when time reached.

Send SMS in Alarm Service at a pre-defined time

In the main activity, data can be passed as bundle as normal.
But there are no getIntent().getExtras() in Service class! It can be retrieved in onStart() call-back method, it will be passed as parameter.

main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   >
<TextView 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="@string/hello"
   />
<TextView
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="Enter Phone Number:"
   />
<EditText
   android:id="@+id/smsnumber"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:inputType="phone"
   />
<TextView
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="Enter Phone SMS Text:"
   />
<EditText
   android:id="@+id/smstext"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   />
<Button
   android:id="@+id/startalarm"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="Start"
   />
<Button
   android:id="@+id/cancelalarm"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="Cancel"
   />
</LinearLayout>


main activity AndroidAlarmSMS.java
package com.exercise.AndroidAlarmSMS;

import java.util.Calendar;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class AndroidAlarmSMS extends Activity {

 String smsNumber, smsText;
 private PendingIntent pendingIntent;
 
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       final EditText edittextSmsNumber = (EditText)findViewById(R.id.smsnumber);
       final EditText edittextSmsText = (EditText)findViewById(R.id.smstext);
      
       Button buttonStart = (Button)findViewById(R.id.startalarm);
       Button buttonCancel = (Button)findViewById(R.id.cancelalarm);
      
       buttonStart.setOnClickListener(new Button.OnClickListener(){

   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    smsNumber = edittextSmsNumber.getText().toString();
    smsText = edittextSmsText.getText().toString();
    
    Intent myIntent = new Intent(AndroidAlarmSMS.this, MyAlarmService.class);
    
    Bundle bundle = new Bundle();
             bundle.putCharSequence("extraSmsNumber", smsNumber);
             bundle.putCharSequence("extraSmsText", smsText);
             myIntent.putExtras(bundle);
    
    pendingIntent = PendingIntent.getService(AndroidAlarmSMS.this, 0, myIntent, 0);
    
    AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);

             Calendar calendar = Calendar.getInstance();
             calendar.setTimeInMillis(System.currentTimeMillis());
             calendar.add(Calendar.SECOND, 10);
             alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
         
             Toast.makeText(AndroidAlarmSMS.this,
               "Start Alarm with \n" +
               "smsNumber = " + smsNumber + "\n" +
               "smsText = " + smsText,
               Toast.LENGTH_LONG).show();
    
   }});
      
       buttonCancel.setOnClickListener(new Button.OnClickListener(){

   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);
    Toast.makeText(AndroidAlarmSMS.this, "Cancel!", Toast.LENGTH_LONG).show();
    
   }});
   }
  
}


the service, MyAlarmService.java
package com.exercise.AndroidAlarmSMS;

import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
import android.telephony.SmsManager;
import android.widget.Toast;

public class MyAlarmService extends Service {
 
 String smsNumberToSend, smsTextToSend;

 @Override
 public void onCreate() {
  // TODO Auto-generated method stub
  
  Toast.makeText(this, "MyAlarmService.onCreate()", Toast.LENGTH_LONG).show();
 }

 @Override
 public IBinder onBind(Intent arg0) {
  // TODO Auto-generated method stub
  Toast.makeText(this, "MyAlarmService.onBind()", Toast.LENGTH_LONG).show();
  return null;
 }
 
 @Override
 public void onDestroy() {
  // TODO Auto-generated method stub
   super.onDestroy();
   Toast.makeText(this, "MyAlarmService.onDestroy()", Toast.LENGTH_LONG).show();
 }

 @Override
 public void onStart(Intent intent, int startId) {
  // TODO Auto-generated method stub
  super.onStart(intent, startId);
  
  Bundle bundle = intent.getExtras();
       smsNumberToSend = (String) bundle.getCharSequence("extraSmsNumber");
       smsTextToSend = (String) bundle.getCharSequence("extraSmsText");
  
  Toast.makeText(this, "MyAlarmService.onStart()", Toast.LENGTH_LONG).show();
  Toast.makeText(this,
         "MyAlarmService.onStart() with \n" +
         "smsNumberToSend = " + smsNumberToSend + "\n" +
         "smsTextToSend = " + smsTextToSend,
         Toast.LENGTH_LONG).show();
  
  SmsManager smsManager = SmsManager.getDefault();
  smsManager.sendTextMessage(smsNumberToSend, null, smsTextToSend, null, null);
 }

 @Override
 public boolean onUnbind(Intent intent) {
  // TODO Auto-generated method stub
  Toast.makeText(this, "MyAlarmService.onUnbind()", Toast.LENGTH_LONG).show();
  return super.onUnbind(intent);
 }

}


Modify AndroidManifest.xml to add <service android:name=".MyAlarmService" />
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.exercise.AndroidAlarmSMS"
     android:versionCode="1"
     android:versionName="1.0">
   <uses-sdk android:minSdkVersion="4" />

   <application android:icon="@drawable/icon" android:label="@string/app_name">
       <activity android:name=".AndroidAlarmSMS"
                 android:label="@string/app_name">
           <intent-filter>
               <action android:name="android.intent.action.MAIN" />
               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
       </activity>
       <service android:name=".MyAlarmService" />
   </application>
   <uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
</manifest>


download filesDownload the files.

Wednesday, March 23, 2011

Send email using Intent.ACTION_SEND

A example to send email using Intent.ACTION_SEND.

Send email using Intent.ACTION_SEND

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   >
<TextView 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="@string/hello"
   />
<TextView 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="Enter email address:"
   />
<EditText 
   android:id="@+id/email_address"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:inputType="textEmailAddress"
   />
<TextView 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="Enter email Subject:"
   />
<EditText 
   android:id="@+id/email_subject"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:inputType="textEmailSubject"
   />
<TextView 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="Enter Text:"
   />
<EditText 
   android:id="@+id/email_text"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   />
<Button 
   android:id="@+id/sendemail_intent"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text=" Send email using Intent.ACTION_SEND "
   />
</LinearLayout>


package com.exercise.AndroidEMail;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class AndroidEMail extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
      
       final EditText edittextEmailAddress = (EditText)findViewById(R.id.email_address);
       final EditText edittextEmailSubject = (EditText)findViewById(R.id.email_subject);
       final EditText edittextEmailText = (EditText)findViewById(R.id.email_text);
       Button buttonSendEmail_intent = (Button)findViewById(R.id.sendemail_intent);
      
       buttonSendEmail_intent.setOnClickListener(new Button.OnClickListener(){

  @Override
  public void onClick(View arg0) {
   // TODO Auto-generated method stub

   String emailAddress = edittextEmailAddress.getText().toString();
   String emailSubject = edittextEmailSubject.getText().toString();
   String emailText = edittextEmailText.getText().toString();

   String emailAddressList[] = {emailAddress};
  
   Intent intent = new Intent(Intent.ACTION_SEND); 
   intent.setType("plain/text");
   intent.putExtra(Intent.EXTRA_EMAIL, emailAddressList);  
   intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject); 
   intent.putExtra(Intent.EXTRA_TEXT, emailText); 
   startActivity(Intent.createChooser(intent, "Choice App t send email:"));
  
  }});
   }
}


Download the files.

Related article:
- No applications can perform this action - Check Instent available and force to install
- Send email with Image by starting activity using Intent of ACTION_SEND

Send SMS using Intent.ACTION_SENDTO

In last exercise, how to "Send SMS using android.telephony.SmsManager" is shown. Alternatively, we can startActivity with Intent.ACTION_SENDTO; the default SMS app will be called out to handle the job. In this method, it's no need to grant permission of "android.permission.SEND_SMS".

Send SMS using Intent.ACTION_SENDTO

Modify main.xml from last exercise "Send SMS using android.telephony.SmsManager" to add a button to startActivity with Intent.ACTION_SENDTO.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Enter Phone Number:"
/>
<EditText
android:id="@+id/smsnumber"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="phone"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Enter Phone SMS Text:"
/>
<EditText
android:id="@+id/smstext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/sendsms"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" Send SMS "
/>
<Button
android:id="@+id/sendsms_intent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" Send SMS using Intent.ACTION_SENDTO "
/>
</LinearLayout>


Modify the code, AndroidSMS.java.
package com.exercise.AndroidSMS;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class AndroidSMS extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

final EditText edittextSmsNumber = (EditText)findViewById(R.id.smsnumber);
final EditText edittextSmsText = (EditText)findViewById(R.id.smstext);
Button buttonSendSms = (Button)findViewById(R.id.sendsms);
Button buttonSendSms_intent = (Button)findViewById(R.id.sendsms_intent);

buttonSendSms.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
SmsManager smsManager = SmsManager.getDefault();
String smsNumber = edittextSmsNumber.getText().toString();
String smsText = edittextSmsText.getText().toString();
smsManager.sendTextMessage(smsNumber, null, smsText, null, null);
}});

buttonSendSms_intent.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub

String smsNumber = edittextSmsNumber.getText().toString();
String smsText = edittextSmsText.getText().toString();

Uri uri = Uri.parse("smsto:" + smsNumber);
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra("sms_body", smsText);
startActivity(intent);
}});
}
}


Download the files.

Tuesday, March 22, 2011

Send SMS using android.telephony.SmsManager

Android OS provide android.telephony.SmsManager, to manages SMS operations such as sending data, text, and pdu SMS messages. Get this object by calling the static method SmsManager.getDefault(). Here is a example to send SMS sing android.telephony.SmsManager.

Send SMS using android.telephony.SmsManager

Modify main.xml to have two EditText for user to enter phone number and text.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Enter Phone Number:"
/>
<EditText
android:id="@+id/smsnumber"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="phone"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Enter Phone SMS Text:"
/>
<EditText
android:id="@+id/smstext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/sendsms"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" Send SMS "
/>
</LinearLayout>


main code, AndroidSMS.java
package com.exercise.AndroidSMS;

import android.app.Activity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class AndroidSMS extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

final EditText edittextSmsNumber = (EditText)findViewById(R.id.smsnumber);
final EditText edittextSmsText = (EditText)findViewById(R.id.smstext);
Button buttonSendSms = (Button)findViewById(R.id.sendsms);

buttonSendSms.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
SmsManager smsManager = SmsManager.getDefault();
String smsNumber = edittextSmsNumber.getText().toString();
String smsText = edittextSmsText.getText().toString();
smsManager.sendTextMessage(smsNumber, null, smsText, null, null);
}});
}
}


Modify AndroidManifest.xml to grant permission of "android.permission.SEND_SMS".
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exercise.AndroidSMS"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".AndroidSMS"
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>
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
</manifest>


Download the files.

Related Articles:
- Send SMS using Intent.ACTION_SENDTO
- Send SMS in Alarm Service at a pre-defined time

Monday, March 21, 2011

ViewFlipper Animation

ViewFlipper is a subclass of android.widget.ViewAnimator, so we can apply Animation on ViewFlipper also. Here is a example; the ViwFlipper change in shifting from one view to another view slowly.

create a folder /res/anim, create two xml file to define the flip-in and flip-out animation.
/res/anim/flipin.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
 android:interpolator="@android:anim/decelerate_interpolator">
<translate
 android:fromXDelta="-100%"
 android:toXDelta="0%"
 android:duration="500" />
</set>


/res/anim/flipout.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
 android:interpolator="@android:anim/decelerate_interpolator">
<translate
 android:fromXDelta="0%"
 android:toXDelta="100%"
 android:duration="500" />
</set>


main.xml (It's sam as that in the exercise "ViewFlipper")
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   >
<TextView 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="@string/hello"
   />
<ViewFlipper
 android:id="@+id/viewflipper"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
<LinearLayout
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:orientation="vertical">
<TextView
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="First Screen"/>
<Button
 android:id="@+id/button1"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="Flip to second page"/>
</LinearLayout>
<LinearLayout
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:orientation="vertical">
<TextView
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Second Screen"/>
<Button
 android:id="@+id/button2"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:text="Flip back"/>
</LinearLayout>
</ViewFlipper>
</LinearLayout>



main code, AndroidViewFlipper.java
package com.exercise.AndroidViewFlipper;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ViewFlipper;

public class AndroidViewFlipper extends Activity {
 
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       final ViewFlipper MyViewFlipper = (ViewFlipper)findViewById(R.id.viewflipper);
       Button button1 = (Button)findViewById(R.id.button1);
       Button button2 = (Button)findViewById(R.id.button2);

       Animation animationFlipIn  = AnimationUtils.loadAnimation(this, R.anim.flipin);
       Animation animationFlipOut = AnimationUtils.loadAnimation(this, R.anim.flipout);
       MyViewFlipper.setInAnimation(animationFlipIn);
       MyViewFlipper.setOutAnimation(animationFlipOut);
      
       button1.setOnClickListener(new Button.OnClickListener(){

   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    MyViewFlipper.showNext();
   }});
      
       button2.setOnClickListener(new Button.OnClickListener(){

   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    MyViewFlipper.showPrevious();
   }});
   }
}


download filesDownload the files.

Sunday, March 20, 2011

Auto flipping of ViewFlipper

Further work on the last exercise "ViewFlipper", we can start and stop auto flipping of ViewFlipper by calling function startFlipping() and stopFlipping(), on interval set by function setFlipInterval(int milliseconds), and the state of flipping can be read by calling function isFlipping().

Auto flipping of ViewFlipper

Modify the layout, main.xml, to add a button to toggle flipping
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:id="@+id/buttonautoflip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Start Auto Flip"/>
<ViewFlipper
android:id="@+id/viewflipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Screen"/>
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Flip to second page"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Second Screen"/>
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Flip back"/>
</LinearLayout>
</ViewFlipper>
</LinearLayout>


main code, AndroidViewFlipper.java
package com.exercise.AndroidViewFlipper;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ViewFlipper;

public class AndroidViewFlipper extends Activity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ViewFlipper MyViewFlipper = (ViewFlipper)findViewById(R.id.viewflipper);
final Button buttonAutoFlip = (Button)findViewById(R.id.buttonautoflip);
//Button button1 = (Button)findViewById(R.id.button1);
//Button button2 = (Button)findViewById(R.id.button2);

MyViewFlipper.setFlipInterval(500);
buttonAutoFlip.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub

if(MyViewFlipper.isFlipping()){
MyViewFlipper.stopFlipping();
buttonAutoFlip.setText("Start Auto Flip");
}else{
MyViewFlipper.startFlipping();
buttonAutoFlip.setText("Stop Auto Flip");
}



}});


}
}


Download the files.

next:
- ViewFlipper Animation



Friday, March 18, 2011

ViewFlipper

ViewFlipper is a simple ViewAnimator that will animate between two or more views that have been added to it. Only one child is shown at a time. If requested, can automatically flip between each child at a regular interval.

Here is a simple example to implement ViewFlipper.

ViewFlipper

Modify main.xml to have a ViewFlipper, with two LinearLayout inside.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<ViewFlipper
android:id="@+id/viewflipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Screen"/>
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Flip to second page"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Second Screen"/>
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Flip back"/>
</LinearLayout>
</ViewFlipper>
</LinearLayout>


main code
package com.exercise.AndroidViewFlipper;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ViewFlipper;

public class AndroidViewFlipper extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ViewFlipper MyViewFlipper = (ViewFlipper)findViewById(R.id.viewflipper);
Button button1 = (Button)findViewById(R.id.button1);
Button button2 = (Button)findViewById(R.id.button2);

button1.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
MyViewFlipper.showNext();
}});

button2.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
MyViewFlipper.showPrevious();
}});

}
}


Download the files.

next:
- Auto flipping of ViewFlipper
- ViewFlipper Animation

Tuesday, March 15, 2011

Custom GridView

In the old exercise "GridView" show how to implement a simple GridView (like the build in Gallery app) with a simple ImageView on each grid. Here it will be modified to implement custom GridView, have a ImageView and TextView in each grid.

Custom GridView

Create a folder /res/drawable to hold the pictures.

Modify main.xml to have a GridView.
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:columnWidth="90dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>


Implement mygrid.xml in folder /res/layout/, it's the layout of individual grid.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/imagepart"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/textpart"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>


Modify the main Java code. Modify mThumbIds to update with your own drawable rsource name.
package com.exercise.CustomGridView;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class CustomGridView extends Activity {

// references to our images
private Integer[] mThumbIds = {
R.drawable.androider_01,
R.drawable.androider_02,
R.drawable.androider_03,
R.drawable.androider_04,
R.drawable.androider_05,
R.drawable.androider_06,
R.drawable.androider_07,
R.drawable.androider_08,
R.drawable.androider_09,
R.drawable.androider_10,
R.drawable.androider_11,
R.drawable.androider_12,
R.drawable.androider_13,
R.drawable.androider_14,
R.drawable.androider_15,
R.drawable.androider_16
};

public class MyAdapter extends BaseAdapter {

private Context mContext;

public MyAdapter(Context c) {
// TODO Auto-generated constructor stub
mContext = c;
}

@Override
public int getCount() {
// TODO Auto-generated method stub
return mThumbIds.length;
}

@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return mThumbIds[arg0];
}

@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub

View grid;

if(convertView==null){
grid = new View(mContext);
LayoutInflater inflater=getLayoutInflater();
grid=inflater.inflate(R.layout.mygrid, parent, false);
}else{
grid = (View)convertView;
}

ImageView imageView = (ImageView)grid.findViewById(R.id.imagepart);
TextView textView = (TextView)grid.findViewById(R.id.textpart);
imageView.setImageResource(mThumbIds[position]);
textView.setText(String.valueOf(position));

return grid;
}

}

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new MyAdapter(this));

}
}


Download the files.

Saturday, March 5, 2011

Amazon Appstore Developer Portal is alive

Amazon Appstore Developer Portal is go alive
For developer, you can market your apps to tens of millions of customers using Amazon’s proven marketing and merchandising capabilities, submit your apps using the portal’s self-service workflow, track approval status in real-time, and generate custom sales reports

Join the developer program now, and you will be waived the $99 program fee for your first year!

Check "Amazon Appstore for Android" in https://developer.amazon.com/

Friday, March 4, 2011

Install Android Compatibility package

A few weeks ago, Dianne Hackborn wrote about the new Fragments API, a mechanism that makes it easier for applications to scale across a variety of screen sizes.

The new Fragments API, which is part of Honeycomb, does not help developers whose applications target earlier versions of Android.

Today Google have released a static library that exposes the same Fragments API (as well as the new LoaderManager and a few other classes) so that applications compatible with Android 1.6 or later can use fragments to create tablet-compatible user interfaces. it’s called “Android Compatibility package”.

This library is available through the SDK Updater.

Source:
- http://android-developers.blogspot.com/2011/03/fragments-for-all.html

To install the in your existent Eclipse with ndroid SDK, click Window Android SDK and AVD Manager, select Available packages on the left.

Install Android Compatibility package

ListActivity with two List

In this exercise, the ListView of a ListActivity switch between two ArrayAdapter.

ListActivity with two List

Note that notifyDataSetChanged() function of the new ArrayAdapter have to be called after setListAdapter(), to re-draw the List on screen.

package com.exercise.AndroidDualListActivity;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class AndroidDualListActivity extends ListActivity{

String[] month = {
"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"
};

String[] DayOfWeek = new String[] {
"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"};

ArrayAdapter<String> monthAdapter, weekOfDayAdapter;
String strMonth, strDayOfWeek;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
monthAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, month);
weekOfDayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, DayOfWeek);

setListAdapter(monthAdapter);
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);

if(getListAdapter() == monthAdapter){
strMonth = (String)getListView().getItemAtPosition(position);
setListAdapter(weekOfDayAdapter);
weekOfDayAdapter.notifyDataSetChanged();
}else{
strDayOfWeek = (String)getListView().getItemAtPosition(position);
Toast.makeText(getBaseContext(), strMonth + ":" + strDayOfWeek, Toast.LENGTH_LONG).show();
setListAdapter(monthAdapter);
monthAdapter.notifyDataSetChanged();
}
}
}


Download the files.

Thursday, March 3, 2011

Get Detailed Network State of Android device

Via ConnectivityManager, the detailed state of all network device can be get.

Get Detailed Network State of Android device

Keep using AndroidManifest.xml of last exercise "Get Network Info" to grant permission of "android.permission.ACCESS_NETWORK_STATE".

Call getDetailedState() method of NetworkInfo object to get the detailed state.
package com.exercise.AndroidNetworkInfo;

import java.util.ArrayList;
import java.util.List;

import android.app.ListActivity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.widget.ArrayAdapter;

public class AndroidNetworkInfo extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ConnectivityManager connectivityManager
= (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] networkInfo
= connectivityManager.getAllNetworkInfo();

List<String> listNetworkInfo = new ArrayList<String>();
for(int i=0; i<networkInfo.length; i++){
String strNetworkState = networkInfo[i].getTypeName()
+ " : "
+ networkInfo[i].getDetailedState();

listNetworkInfo.add(strNetworkState);
}

setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
listNetworkInfo));
getListView().setTextFilterEnabled(true);
}
}


Download the files.