<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2enclosuresfull.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Androidians</title><link>http://smartandroidians.blogspot.com/</link><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/AndroidiansFeed" /><description>Tutorials for Android - Share and Enjoy</description><language>en</language><managingEditor>noreply@blogger.com (Nithin M Warrier)</managingEditor><lastBuildDate>Thu, 26 Jan 2012 17:55:14 PST</lastBuildDate><generator>Blogger http://www.blogger.com</generator><openSearch:totalResults xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/">97</openSearch:totalResults><openSearch:startIndex xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/">1</openSearch:startIndex><openSearch:itemsPerPage xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/">25</openSearch:itemsPerPage><feedburner:info uri="androidiansfeed" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><media:keywords>Android,Tutorials</media:keywords><media:category scheme="http://www.itunes.com/dtds/podcast-1.0.dtd">Technology/Software How-To</media:category><itunes:owner><itunes:email>noreply@blogger.com</itunes:email></itunes:owner><itunes:explicit>no</itunes:explicit><itunes:keywords>Android,Tutorials</itunes:keywords><itunes:subtitle>Tutorials for Android - Share and Enjoy</itunes:subtitle><itunes:category text="Technology"><itunes:category text="Software How-To" /></itunes:category><item><title>Pass a custom class from one activity to another using Intent</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/YEREiBltu5U/pass-custom-class-from-one-activity-to.html</link><category>custom class</category><category>Serializable</category><category>pass from one activity to another</category><category>Intent</category><category>getSerializable()</category><category>Android</category><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Wed, 07 Dec 2011 18:48:07 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-3972137053425179970</guid><description>In this article, I am going to discuss about sending a custom class from one activity to another or any custom class to send from one activity to another using Intent.
&lt;br /&gt;&lt;br /&gt;
We can pass a custom class using two ways, rather using two interfaces that are provided by Android which are java.io.Serializable and android.os.Parcelable.
&lt;br /&gt;&lt;br /&gt;
First create a custom class then implements the class with Serializable interface. To make the class serializable include two functions, which are &lt;b&gt;writeObject()&lt;/b&gt; and &lt;b&gt;readObject()&lt;/b&gt;. Whatever objects we need to pass has to write to the ObjectOutputStream in writeObject() and we have to read from readObject() using ObjectInputStream.

&lt;pre&gt;
public class MyClass implements Serializable {
     
     String firstName;
     int empID;
     
     public MyClass(String name, int id) {
      firstName = name;
      empID = id;
     }
     
     private void writeObject(ObjectOutputStream out) {
      try {
    out.writeUTF(firstName);
   } catch (IOException e) {
    e.printStackTrace();
   }
     }
     
     private void readObject(ObjectInputStream in) {
      try {
    firstName = in.readUTF();
   } catch (IOException e) {
    e.printStackTrace();
   }
     }
     
     public String getName() {
      return firstName;
     }
     
     public int getEmpId() {
      return empID;
     }
    }
&lt;/pre&gt;

Next step is create an object of the custom class and put it into the intent using putExtra(). In the next activity we can get the custom class object using &lt;b&gt; getIntent().getSerializableExtra()&lt;/b&gt;
&lt;br/&gt; &lt;br/&gt;
You can get the full source code from &lt;a href="http://code.google.com/p/nithin-warriers-code-base/source/browse/#svn%2Ftrunk%2FPassCustomObject"&gt;here&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-3972137053425179970?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/YEREiBltu5U" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-08T08:18:07.776+05:30</app:edited><feedburner:origLink>http://smartandroidians.blogspot.com/2011/11/pass-custom-class-from-one-activity-to.html</feedburner:origLink></item><item><title>Solution for the error "Method called after release()" in Android Camera API</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/6JvLnfhf3G8/solution-for-error-method-called-after.html</link><category>Error Release() method</category><category>Camera</category><category>Android</category><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Mon, 28 Nov 2011 06:45:02 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-2987886601149435440</guid><description>Today when I am working on camera API in android, I got an error telling "ERROR/AndroidRuntime java.lang.RuntimeException: Method called after release()". &lt;br /&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;b&gt;Solution&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The solution for this is, I am trying to access the camera somewhere after I have released it. So in onResume() set the previewCallback to null. In my case this solved my problem. &lt;b&gt;setPreviewCallback(null);&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Happy Coding !!!&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-2987886601149435440?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/6JvLnfhf3G8" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-28T20:15:02.820+05:30</app:edited><feedburner:origLink>http://smartandroidians.blogspot.com/2011/11/solution-for-error-method-called-after.html</feedburner:origLink></item><item><title>Solution for the error "Debug certificate expired"</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/27tNDOqnT0g/solution-for-error-debug-certificate.html</link><category>Debug certificate expired error</category><category>Android</category><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Mon, 28 Nov 2011 06:23:57 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-2714148226858080097</guid><description>Today when I am working suddenly all my projects in eclipse got errors and nothing is compiling. I came to know the the error is "Debug certificate is expired". &lt;br /&gt;&lt;/br&gt;&lt;br /&gt;&lt;b&gt;Solution&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The solution for this is, if you are in windows, then in user profile, you have a folder called ".android", that contains the debug certificate. Delete the debug certificate, then clean and build a project in eclipse. All started working fine.&lt;br /&gt;&lt;br /&gt;&lt;/br&gt;&lt;br /&gt;&lt;b&gt;Example&lt;/b&gt;&lt;br /&gt;C:\Users\Nithin\.android&lt;br /&gt;&lt;br /&gt;Happy Coding !!!&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-2714148226858080097?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/27tNDOqnT0g" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-28T19:53:57.827+05:30</app:edited><feedburner:origLink>http://smartandroidians.blogspot.com/2011/11/solution-for-error-debug-certificate.html</feedburner:origLink></item><item><title>Access the features of Android device</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/tqahF42Gk8A/access-features-of-android-device.html</link><category>System features</category><category>PackageManager</category><category>Android</category><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Sat, 26 Nov 2011 23:25:49 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-2863962031612455371</guid><description>&lt;script type="text/javascript"&gt;&lt;br /&gt;&lt;br /&gt;  var _gaq = _gaq || [];&lt;br /&gt;  _gaq.push(['_setAccount', 'UA-27326204-1']);&lt;br /&gt;  _gaq.push(['_trackPageview']);&lt;br /&gt;&lt;br /&gt;  (function() {&lt;br /&gt;    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;&lt;br /&gt;    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';&lt;br /&gt;    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);&lt;br /&gt;  })();&lt;br /&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;To access the available features in an Android device, the code snippet,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;PackageManager mPackageManager = getPackageManager();&lt;br /&gt;FeatureInfo[] systemFeature = mPackageManager&lt;br /&gt;    .getSystemAvailableFeatures();&lt;br /&gt;for (int i = 0; i &lt; systemFeature.length; i++) {&lt;br /&gt;String feature = systemFeature[i].name;&lt;br /&gt;if (feature == null) {&lt;br /&gt;    feature = "OpenGL Version : " + systemFeature[i].reqGlEsVersion;&lt;br /&gt;}&lt;br /&gt;systemFeaturesList.add(feature);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;I just list it into a list, the complete code is,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public class FeaturesListActivity extends Activity {&lt;br /&gt;&lt;br /&gt; private final String TAG = "FeaturesListActivity";&lt;br /&gt; private ListView mList;&lt;br /&gt; private ArrayList&lt;String&gt; systemFeaturesList = new ArrayList&lt;String&gt;();&lt;br /&gt;&lt;br /&gt; /** Called when the activity is first created. */&lt;br /&gt; @Override&lt;br /&gt; public void onCreate(Bundle savedInstanceState) {&lt;br /&gt;  super.onCreate(savedInstanceState);&lt;br /&gt;  setContentView(R.layout.main);&lt;br /&gt;  mList = (ListView) findViewById(R.id.list);&lt;br /&gt;  PackageManager mPackageManager = getPackageManager();&lt;br /&gt;  FeatureInfo[] systemFeature = mPackageManager&lt;br /&gt;    .getSystemAvailableFeatures();&lt;br /&gt;  for (int i = 0; i &lt; systemFeature.length; i++) {&lt;br /&gt;   String feature = systemFeature[i].name;&lt;br /&gt;   if (feature == null) {&lt;br /&gt;    feature = "OpenGL Version : " + systemFeature[i].reqGlEsVersion;&lt;br /&gt;   }&lt;br /&gt;   systemFeaturesList.add(feature);&lt;br /&gt;   Log.i(TAG, "**************** System Feature = " + feature);&lt;br /&gt;  }&lt;br /&gt;  mList.setAdapter(new SystemFeatureListAdapter(this));&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; private class SystemFeatureListAdapter extends BaseAdapter {&lt;br /&gt;&lt;br /&gt;  private Context mContext;&lt;br /&gt;&lt;br /&gt;  public SystemFeatureListAdapter(Context context) {&lt;br /&gt;   mContext = context;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  @Override&lt;br /&gt;  public int getCount() {&lt;br /&gt;   return systemFeaturesList.size();&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  @Override&lt;br /&gt;  public Object getItem(int index) {&lt;br /&gt;   return systemFeaturesList.get(index);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  @Override&lt;br /&gt;  public long getItemId(int id) {&lt;br /&gt;   return id;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  @Override&lt;br /&gt;  public View getView(int position, View view, ViewGroup parent) {&lt;br /&gt;   TextView text = new TextView(mContext);&lt;br /&gt;   text.setText(systemFeaturesList.get(position));&lt;br /&gt;   return text;&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The screen-shot of the application is,&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/-wor3Pxij_ws/TtE3hPwqFkI/AAAAAAAAAu8/lVzLxb42hE4/s1600/device-FeatureList.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 240px; height: 320px;" src="http://2.bp.blogspot.com/-wor3Pxij_ws/TtE3hPwqFkI/AAAAAAAAAu8/lVzLxb42hE4/s320/device-FeatureList.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5679381649396733506" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-2863962031612455371?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/tqahF42Gk8A" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-27T12:55:49.623+05:30</app:edited><media:thumbnail url="http://2.bp.blogspot.com/-wor3Pxij_ws/TtE3hPwqFkI/AAAAAAAAAu8/lVzLxb42hE4/s72-c/device-FeatureList.png" height="72" width="72" /><feedburner:origLink>http://smartandroidians.blogspot.com/2011/11/access-features-of-android-device.html</feedburner:origLink></item><item><title>Fetch the unique ID of Android device</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/NU5uf2b_jRI/fetch-unique-id-of-android-device.html</link><category>Android</category><category>unique device ID</category><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Sat, 26 Nov 2011 10:54:42 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-2640811481360783812</guid><description>To fetch the device ID of any android device, the code snippet is,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);&lt;br /&gt;String android_id = telephonyManager.getDeviceId();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The screen-shot that I got from my HTC phone is,&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/-_UL2pbu75fc/TtE1tMtSUoI/AAAAAAAAAuw/1PW0BIa4VrM/s1600/device-ID-HTC.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 240px; height: 320px;" src="http://2.bp.blogspot.com/-_UL2pbu75fc/TtE1tMtSUoI/AAAAAAAAAuw/1PW0BIa4VrM/s320/device-ID-HTC.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5679379655712461442" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-2640811481360783812?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/NU5uf2b_jRI" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-27T00:24:42.968+05:30</app:edited><media:thumbnail url="http://2.bp.blogspot.com/-_UL2pbu75fc/TtE1tMtSUoI/AAAAAAAAAuw/1PW0BIa4VrM/s72-c/device-ID-HTC.png" height="72" width="72" /><feedburner:origLink>http://smartandroidians.blogspot.com/2011/11/fetch-unique-id-of-android-device.html</feedburner:origLink></item><item><title>Open Gallery and get the selected image in appplication</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/ZEY_DMn53PA/open-gallery-and-get-selected-image-in_16.html</link><category>OutOfMemory Error</category><category>Android</category><category>Gallery</category><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Wed, 16 Nov 2011 06:18:01 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-2698785862633441292</guid><description>In this, the screen will have a button to open the android device Gallery and from there if we select any image, that image we can get it in the application. &lt;br /&gt;&lt;br /&gt;The code snipped for opening the Gallery is,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);&lt;br /&gt;photoPickerIntent.setType("image/*");&lt;br /&gt;startActivityForResult(photoPickerIntent, 1);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We are opening the gallery as a sub activity of our application, because onActivityResult() will get called after selecting the image from gallery. So in onACtivityResult(), we will get the Uri of the selected image and from Mediastore contentprovider, we can get the selected image as bitmap. After that, for showing it in the application, just setting the image in a ImageView. &lt;br /&gt;&lt;br /&gt;The complete code is,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public class GalWalActivity extends Activity {&lt;br /&gt;    &lt;br /&gt; private ImageView selectedImage;&lt;br /&gt;        private Bitmap currentImage;&lt;br /&gt; &lt;br /&gt; @Override&lt;br /&gt;        public void onCreate(Bundle savedInstanceState) {&lt;br /&gt;        super.onCreate(savedInstanceState);&lt;br /&gt;        setContentView(R.layout.main);&lt;br /&gt;        selectedImage = (ImageView) findViewById(R.id.selectedImage);&lt;br /&gt;        Button openGallery = (Button) findViewById(R.id.opengallery);&lt;br /&gt;        &lt;br /&gt;        openGallery.setOnClickListener(new View.OnClickListener() {&lt;br /&gt;   &lt;br /&gt;   @Override&lt;br /&gt;   public void onClick(View v) {&lt;br /&gt;    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);&lt;br /&gt;    photoPickerIntent.setType("image/*");&lt;br /&gt;    startActivityForResult(photoPickerIntent, 1);&lt;br /&gt;   }&lt;br /&gt;  });&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;@Override&lt;br /&gt; protected void onActivityResult(int requestCode, int resultCode, Intent data) {&lt;br /&gt;     super.onActivityResult(requestCode, resultCode, data);&lt;br /&gt;     &lt;br /&gt;     if (resultCode == RESULT_OK) {&lt;br /&gt;            Uri photoUri = data.getData();&lt;br /&gt;            if (photoUri != null) {&lt;br /&gt;                try {&lt;br /&gt;currentImage = MediaStore.Images.Media.getBitmap(this.getContentResolver(), photoUri);&lt;br /&gt;                    selectedImage.setImageBitmap(currentImage);&lt;br /&gt;                } catch (Exception e) {&lt;br /&gt;                    e.printStackTrace();&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The catch here is if we open the gallery for first time from the applicaiotn, the applicaiton will work fine. But if we open gallery for second time and try to get the selected image, we will get an exception &lt;b&gt; OutOfMemory Exception&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;This is because we are not free the bitmap memory or we need to recycle the bitmap. The solution for this is, every time when we open gallery from our application, onPause() and onStop() of the Activity lifecycle methods will get called. So in either onPause() or onStop(), we need to add the code snippet to recycle the bitmap and to free the memory.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;if (currentImage != null) {&lt;br /&gt;currentImage.recycle();&lt;br /&gt;currentImage = null;&lt;br /&gt;System.gc();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So onStop() will look like this.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public void onStop() {&lt;br /&gt;super.onStop();&lt;br /&gt;if (currentImage != null) {&lt;br /&gt;currentImage.recycle();&lt;br /&gt;currentImage = null;&lt;br /&gt;System.gc();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The layout will look like this,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;br /&gt;&amp;lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"&lt;br /&gt;    android:orientation="vertical"&lt;br /&gt;    android:layout_width="fill_parent"&lt;br /&gt;    android:layout_height="fill_parent"&lt;br /&gt;    &amp;gt;&lt;br /&gt;&amp;lt;Button android:id="@+id/opengallery" &lt;br /&gt;    android:layout_width="wrap_content" &lt;br /&gt;    android:layout_height="wrap_content" &lt;br /&gt;    android:text="Open Gallery"&lt;br /&gt;    /&amp;gt;&lt;br /&gt;&amp;lt;ImageView android:id="@+id/selectedImage" &lt;br /&gt;    android:layout_width="wrap_content" &lt;br /&gt;    android:layout_height="wrap_content" &lt;br /&gt;    /&amp;gt;    &lt;br /&gt;&amp;lt;/LinearLayout&amp;gt;&lt;br /&gt;&lt;/pre&gt;  &lt;br /&gt;&lt;br /&gt;Happy Coding&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-2698785862633441292?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/ZEY_DMn53PA" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-16T19:48:01.840+05:30</app:edited><feedburner:origLink>http://smartandroidians.blogspot.com/2011/11/open-gallery-and-get-selected-image-in_16.html</feedburner:origLink></item><item><title>Way to get Bluetooth Address in Android Phone</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/ET9bWFheu_4/way-to-get-bluetooth-address-in-android.html</link><category>Mac Address</category><category>Android</category><category>Bluetooth</category><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Wed, 09 Nov 2011 20:45:14 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-4180470934524131514</guid><description>For getting bluetooth address first we need to enable bluetooth. The code snippet for getting bluetooth address is,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();&lt;br /&gt;String btMacAddress = btAdapter.getAddress();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The permission that we need to put in Manifest file is,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;uses-permsission android:name="android.permission.BLUETOOTH" /&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-4180470934524131514?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/ET9bWFheu_4" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-10T10:15:14.270+05:30</app:edited><feedburner:origLink>http://smartandroidians.blogspot.com/2011/11/way-to-get-bluetooth-address-in-android.html</feedburner:origLink></item><item><title>Way to get WiFi address in Android Phones</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/rkVPCNeVw7k/way-to-get-wifi-address-in-android.html</link><category>Wifi</category><category>Mac Address</category><category>Android</category><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Wed, 09 Nov 2011 09:00:00 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-1198560738502951555</guid><description>We will get the WiFi Mac address only if the WiFi is enabled in the device. The code snippet for getting the WiFi address is &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);&lt;br /&gt;WifiInfo info = wifi.getConnectionInfo();&lt;br /&gt;String WifiMacAddress = info.getMacAddress();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The permission that we need to put in manifest file is,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;uses-permsission android:name="android.permission.ACCESS_WIFI_STATE" /&amp;gt;&lt;br /&gt;&amp;lt;uses-permsission android:name="android.permission.CHANGE_WIFI_STATE" /&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-1198560738502951555?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/rkVPCNeVw7k" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-09T22:30:00.968+05:30</app:edited><feedburner:origLink>http://smartandroidians.blogspot.com/2011/11/way-to-get-wifi-address-in-android.html</feedburner:origLink></item><item><title>Different ways of Playing a media file in Android</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/epxZkF6di4Q/different-ways-of-playing-media-file-in.html</link><category>MediaPlayer</category><category>Android</category><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Mon, 01 Aug 2011 10:00:51 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-5109529317912493271</guid><description>In this I am going to explain different ways of playing a media file in Android. Media here I mean video files. First of all we need a instance of mediaPlayer. &lt;br /&gt;&lt;br /&gt; - Unlike audio files, media files require SurfaceView to play the media file. &lt;br /&gt;&lt;br /&gt; - Then we need to implement the interface to SurfaceHolder.Callback. To implement the callback methods in SurfaceHolder.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/b&gt;One common error in beginners is, they will try to start mediaPlayer in onCreate() of the activity. But actually at this time, the surfaceView might not be created. So we need to call &lt;b&gt;mediaPlayer.start()&lt;/b&gt; in the callback method of surfaceHolder in onSurfaceCreated()&lt;br /&gt;&lt;br /&gt;If the media file is in raw folder of the resources, we can get it through,&lt;br /&gt;&lt;br /&gt; - AssetFileDescriptor afd = this.getResources().openRawResourceFd(R.raw.monster);&lt;br /&gt;&lt;br /&gt;Here monster is the media file name. The media file can be either .mp4 type or .3gp. We can set this fileDescriptor to mediaPlayer instance through the method, &lt;b&gt; setDataSource()&lt;/b&gt;&lt;br /&gt;&lt;br /&gt; - mediaplayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());&lt;br /&gt;&lt;br /&gt;Then if the file is in SDCard, then we can set the media file to mediPlayer through&lt;br /&gt;&lt;br /&gt; - String path = "file:///sdcard/monster.3gp";&lt;br /&gt; - mediaPlayer.setDataSource(path);&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-5109529317912493271?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/epxZkF6di4Q" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-01T22:30:51.335+05:30</app:edited><feedburner:origLink>http://smartandroidians.blogspot.com/2011/08/different-ways-of-playing-media-file-in.html</feedburner:origLink></item><item><title>Launching third party application through Intent</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/nNH3n7UkxrU/launching-third-party-application.html</link><category>Launch third part application</category><category>Intent</category><category>Android</category><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Tue, 14 Jun 2011 07:56:27 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-1166876333091942241</guid><description>The snippet for launching a third party application through intent is,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Intent intent = new Intent(Intent.ACTION_MAIN);&lt;br /&gt;intent.setClassName("com.smartandroidians", "com.smartandroidians.NotificationWithAction");&lt;br /&gt;startActivity(intent);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The first parameter in &lt;b&gt;setClassName()&lt;/b&gt; is the package name and the second parameter is the launcher activity class name&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-1166876333091942241?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/nNH3n7UkxrU" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-14T20:26:27.849+05:30</app:edited><feedburner:origLink>http://smartandroidians.blogspot.com/2011/06/launching-third-party-application.html</feedburner:origLink></item><item><title>Cursor management in Honeycomb</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/9qckZLGumVA/cursor-management-in-honeycomb.html</link><category>Honeycomb</category><category>Android</category><category>cursor management</category><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Thu, 02 Jun 2011 19:51:28 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-1889824578592671717</guid><description>If you are targeting your application for honeycomb, then some APIs related to cursor management are deprecated and your application won't work smoothly in honeycomb, eventhough it will work well in other versions of Android. In Honeycomb, cursor management is more tightly coupled and Some of the APIs that are deprecated are&lt;br /&gt;&lt;br /&gt; - startManagingCursor()&lt;br /&gt; - stopManagingCursor()&lt;br /&gt; - managedQuery()&lt;br /&gt; - reQuery()&lt;br /&gt;&lt;br /&gt;If you are using any of these methods in HoneyComb, then you will get an exception, like &lt;br /&gt;&lt;br /&gt;&lt;b&gt; java.lang.IllegalStateException: trying to requery an already closed cursor &lt;/b&gt; &lt;br /&gt;&lt;br /&gt;If you are using managedQuery() in lower versions of Android(2.3,2.2)  as,&lt;br /&gt;&lt;br /&gt;cursor = context.managedQuery(android.provider.Browser.BOOKMARKS_URI, projection, null, null,&lt;br /&gt;                            null);  &lt;br /&gt;&lt;br /&gt;then in Honeycomb you need to modify as,&lt;br /&gt;&lt;br /&gt;CursorLoader cursorLoader = new CursorLoader(context, android.provider.Browser.BOOKMARKS_URI, projection, null, null,&lt;br /&gt;                            null);&lt;br /&gt;cursor = cursorLoader .loadInBackground();&lt;br /&gt;&lt;br /&gt;Other modification is , you don't need to call reQuery in honeyComb. You have LoaderManager callbacks are there in honeyComb. That will be called if there is any change in the underlying data.&lt;br /&gt;&lt;br /&gt;For implementing LoaderManager callbacks&lt;br /&gt;&lt;br /&gt; - First implement the interface in your class as LoaderManager.LoaderCallbacks&lt;Cursor&gt; &lt;br /&gt; - in onCreate you need to initialize the loader as&lt;br /&gt;       getLoaderManager().initLoader(0, null, this);&lt;br /&gt; - for reQuery, you can use, getLoaderManager().restartLoader(0, null, this);&lt;br /&gt; - Then you need to override three methods in it as,&lt;br /&gt;    - onCreateLoader()&lt;br /&gt;    - onLoadFinished()&lt;br /&gt;    - onLoaderReset()&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-1889824578592671717?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/9qckZLGumVA" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-03T08:21:28.303+05:30</app:edited><feedburner:origLink>http://smartandroidians.blogspot.com/2011/06/cursor-management-in-honeycomb.html</feedburner:origLink></item><item><title>Way to check whether an application is running in Android</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/JGNydbRRDHE/way-to-check-whether-application-is.html</link><category>RunningAppProcessInfo</category><category>Android</category><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Tue, 10 May 2011 10:29:28 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-7928117048827223174</guid><description>Today I came across one interesting thing in Android and I would like to share with you all. In this post I am going to explain the power of the class &lt;b&gt;RunningAppProcessInfo&lt;/b&gt;. Through this class we can check whether the application is running, if it is running what is the importance of it, like whether it is in foreground, background, visible etc.&lt;br /&gt;&lt;br /&gt;The code snippet is,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);&lt;br /&gt;List&amp;lt;RunningAppProcessInfo&amp;gt; runningProcInfo = activityManager .getRunningAppProcesses();&lt;br /&gt;for(int i = 0; i &lt; runningProcInfo.size(); i++){&lt;br /&gt;        if(runningProcInfo.get(i).processName.equals("com.android.XXXXX")) {&lt;br /&gt;            Log.i(TAG, "XXXX is running");&lt;br /&gt;        }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;To check the omportance of the process, that is whether it is foreground or in background etc, we can check through the field &lt;b&gt;lru&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;for(int i = 0; i &lt; runningProcInfo.size(); i++){&lt;br /&gt;        if(runningProcInfo.get(i).processName.equals("com.android.XXXXX")) {&lt;br /&gt;            Log.i(TAG, "XXXX is running");&lt;br /&gt;            if (runningProcInfo.get(i).lru==RunningAppProcessInfo.IMPORTANCE_FOREGROUND){&lt;br /&gt;                    Log.i(TAG, "XXXX is in foreground");&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-7928117048827223174?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/JGNydbRRDHE" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-10T22:59:28.261+05:30</app:edited><feedburner:origLink>http://smartandroidians.blogspot.com/2011/05/way-to-check-whether-application-is.html</feedburner:origLink></item><item><title>Capture Screen in Android</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/nTVg5ibly6c/capture-screen-in-android.html</link><category>View</category><category>Android</category><category>setDrawingCacheEnabled()</category><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Mon, 09 May 2011 10:11:15 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-6721152774153586693</guid><description>Capturing screen is a very useful thing in lot of projects. We can use it for thumbnail, in some cases can use it for Animations etc. This post mainly shows the power of setDrawingCacheEnabled() method in Android's View class. Most common use is take the screen shot and use it as a thumbnail. Take a view from the layout xml file and use the code snippet,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;TextView tv = (TextView) findViewById(R.id.text);&lt;br /&gt;View img = (View) findViewById(R.id.view);&lt;br /&gt;img = tv.getRootView();&lt;br /&gt;img.setDrawingCacheEnabled(true);&lt;br /&gt;Bitmap bmp = img.getDrawingCache();&lt;br /&gt;ImageView image = (ImageView) findViewById(R.id.img);&lt;br /&gt;image.setImageBitmap(bmp);&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-6721152774153586693?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/nTVg5ibly6c" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-09T22:41:15.899+05:30</app:edited><feedburner:origLink>http://smartandroidians.blogspot.com/2011/05/capture-screen-in-android.html</feedburner:origLink></item><item><title>Read bookmark details from Browser provider</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/7MD933zJlI8/read-bookmark-details-from.html</link><category>Android</category><category>Browser Provider</category><category>Bookmarks</category><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Sat, 23 Apr 2011 04:53:47 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-5064621220242753284</guid><description>Here simply I am reading the contents from the browser provider, bookmark table and listing it in a textView. The contents I am reading here are the title and the URL&lt;br /&gt;&lt;br /&gt;The code snippet is,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;String[] projection = new String[] { Browser.BookmarkColumns.TITLE,&lt;br /&gt;    Browser.BookmarkColumns.URL };&lt;br /&gt;Cursor mCur = managedQuery(android.provider.Browser.BOOKMARKS_URI,&lt;br /&gt;    projection, null, null, null);&lt;br /&gt;mCur.moveToFirst();&lt;br /&gt;int titleIdx = mCur.getColumnIndex(Browser.BookmarkColumns.TITLE);&lt;br /&gt;int urlIdx = mCur.getColumnIndex(Browser.BookmarkColumns.URL);&lt;br /&gt;while (mCur.isAfterLast() == false) {&lt;br /&gt; tv.append("\n" + mCur.getString(titleIdx));&lt;br /&gt; tv.append("\n" + mCur.getString(urlIdx));&lt;br /&gt; mCur.moveToNext();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You also need to put the permission,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS" /&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Screen shot&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/-lHRsXqIh-XI/TbK9r7w1F-I/AAAAAAAAAtY/ER1NZW0OAuo/s1600/scr-shot-1.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 214px; height: 320px;" src="http://1.bp.blogspot.com/-lHRsXqIh-XI/TbK9r7w1F-I/AAAAAAAAAtY/ER1NZW0OAuo/s320/scr-shot-1.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5598745849249470434" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Get the complete source code from &lt;a href="http://www.mediafire.com/?vxar1rzh48dohtw"&gt;here&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-5064621220242753284?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/7MD933zJlI8" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-04-23T17:23:47.561+05:30</app:edited><media:thumbnail url="http://1.bp.blogspot.com/-lHRsXqIh-XI/TbK9r7w1F-I/AAAAAAAAAtY/ER1NZW0OAuo/s72-c/scr-shot-1.png" height="72" width="72" /><feedburner:origLink>http://smartandroidians.blogspot.com/2011/04/read-bookmark-details-from.html</feedburner:origLink></item><item><title>Custom Adapter crashes</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/4S7wYj5aFhk/custom-adapter-crashes.html</link><category>Custom adapter crash</category><category>ListView</category><category>Android</category><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Sat, 23 Apr 2011 03:14:19 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-3029570887808413101</guid><description>Wehen I created a custom adapter for a listView, with each list item inflating from a layout. using the statement,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;convertView = vi.inflate(R.layout.list_item, parent);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;my application crashed, later I put a false to the statement and worked well. The new statement looks like&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;convertView = vi.inflate(R.layout.list_item, parent, false);&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-3029570887808413101?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/4S7wYj5aFhk" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-04-23T15:44:19.654+05:30</app:edited><feedburner:origLink>http://smartandroidians.blogspot.com/2011/04/custom-adapter-crashes.html</feedburner:origLink></item><item><title>IOException When uploading a apk</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/fQEKUtOacD8/ioexception-when-uploading-apk.html</link><category>Uploading apk</category><category>IOException</category><category>Android</category><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Sat, 23 Apr 2011 04:08:45 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-1700545103539999454</guid><description>I got a strange exception when I try to upload a apk. The exception looks like this,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Failed to upload xxxxxxxx.apk on device 'emulator-5554'&lt;br /&gt;java.io.IOException: Unable to upload file: timeout&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;After some googling I fount the solution. I need to increase the ADB connection time-out.&lt;br /&gt;&lt;br /&gt;The way to increase is,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Window-&gt;Preferences-&gt;Android-&gt;DDMS-&gt;ADB connection time-out&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;By default, the value is 5000, just increase to the sufficient amount.&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-1700545103539999454?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/fQEKUtOacD8" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-04-23T16:38:45.520+05:30</app:edited><feedburner:origLink>http://smartandroidians.blogspot.com/2011/02/ioexception-when-uploading-apk.html</feedburner:origLink></item><item><title>Playing Ringtone in Android</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/wZ2PBvrMbnE/playing-ringtone-in-android.html</link><category>Alarm</category><category>Ringtone</category><category>Android</category><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Wed, 19 Jan 2011 09:34:29 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-7489082552942253661</guid><description>Android have some system ringtones. We can get the uri for these files through RingtoneManager class. Then using AudioManager and mediaplayer, we can play ringTone up on getting some notifications or for alarm etc.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note :&lt;/b&gt; This code won't work on emulator, this will work only on devices. In emulator, we will get IOException&lt;br /&gt;&lt;br /&gt;The complete code is,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;try {&lt;br /&gt;Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);&lt;br /&gt;mMediaPlayer = new MediaPlayer();&lt;br /&gt;mMediaPlayer.setDataSource(this, alert);&lt;br /&gt;final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);&lt;br /&gt;if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {&lt;br /&gt; mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);&lt;br /&gt; mMediaPlayer.setLooping(true);&lt;br /&gt; mMediaPlayer.prepare();&lt;br /&gt; mMediaPlayer.start();&lt;br /&gt;}&lt;br /&gt;} catch(Exception e) {&lt;br /&gt;}   &lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-7489082552942253661?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/wZ2PBvrMbnE" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-01-19T23:04:29.943+05:30</app:edited><feedburner:origLink>http://smartandroidians.blogspot.com/2011/01/playing-ringtone-in-android.html</feedburner:origLink></item><item><title>Difference between SurfaceView and View in Android</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/mdsMxIBgTrE/difference-between-surfaceview-and-view.html</link><category>SurfaceView</category><category>View</category><category>Android</category><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Wed, 19 Jan 2011 08:39:26 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-4185946788641056233</guid><description>The main difference between SurfaceView and View is,&lt;br /&gt;&lt;br /&gt;- Views are drawn in UI thread and surfaceView are drawn in a seperate thread. So if rendering takes long time, its better to use SurfaceView. Then for animations also, its better to use surfaceView.&lt;br /&gt;&lt;br /&gt;- SurfaceView uses more resoources than View, so use it when you really want.&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-4185946788641056233?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/mdsMxIBgTrE" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-01-19T22:09:26.803+05:30</app:edited><feedburner:origLink>http://smartandroidians.blogspot.com/2011/01/difference-between-surfaceview-and-view.html</feedburner:origLink></item><item><title>Interprocess Communication in Android - Part I</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/cITX7kYIhe0/interprocess-communication-in-android.html</link><category>Interprocess communication</category><category>Service</category><category>Android</category><category>IPC</category><category>AIDL</category><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Tue, 08 Feb 2011 21:01:01 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-6584287627332690635</guid><description>Interprocess communication can be done in two ways in Android.&lt;br /&gt;&lt;br /&gt;- Through AIDL(Android Interface Description Language)&lt;br /&gt;- Through Service and Broadcast Receiver&lt;br /&gt;&lt;br /&gt;First I am going to explain inter process communication through AIDL. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Android Interface Description Language(AIDL)&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;For implementing inter process communication(IPC) through AIDL, the main things that we need are,&lt;br /&gt;&lt;br /&gt;- Create a AIDL file containing the functions, that we are going to implement in the Stub class in Service.&lt;br /&gt;&lt;br /&gt;- Create a service, in which we need to implement all the the methods that we declare in the AIDL interface. Android will create a stub class and we need to define the methods here. Stub class is nothing but an object of the IBinder. IBinder is an interface for remote objects. It desribes the protocol for interacting with the remote objects.&lt;br /&gt;&lt;br /&gt;- Then for calling the AIDL service, we need to implement ServiceConnection interface, for monitoring the state of the application service. This interface contains two methods&lt;br /&gt;   a) &lt;b&gt;onServiceConnected()&lt;/b&gt; - Called when a connection to the service is established with IBinder of the communication channel.&lt;br /&gt;   b) &lt;b&gt;onServiceDisconnected()&lt;/b&gt; - Called when a connection to the service has been lost. &lt;br /&gt;&lt;br /&gt;In onServiceConnected(), method contains IBinder as an object and using that we can connect to the service and can invoke the methods of the AIDL interface. Android will also create a Java class for our AIDL interface class.&lt;br /&gt;&lt;br /&gt;- Then like for all service, we need to declare the service in Manifest.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;service android:name=".RemoteService" /&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now, coming to our case, I declare three methods in our AIDL interface as add(), getPid() and getUid().&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You can download the full source code &lt;a href="http://www.mediafire.com/?2oomwjm4hbf0ki7" target="_blank"&gt;here&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-6584287627332690635?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/cITX7kYIhe0" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-09T10:31:01.931+05:30</app:edited><feedburner:origLink>http://smartandroidians.blogspot.com/2011/01/interprocess-communication-in-android.html</feedburner:origLink></item><item><title>Fetching screen height, finding screen orientation</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/8spbAFOYlf4/fetching-screen-height-finding-screen.html</link><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Thu, 13 Jan 2011 09:23:11 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-4433461176416293674</guid><description>Here I am going to eplain some simple but useful tips in Android.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Fetch Screen Height and width of our Android Phone&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;To fetch the screen height and width of our Android phone, the code is&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;Display display = getWindowManager().getDefaultDisplay();&lt;br /&gt;int screenHeight = display.getHeight();&lt;br /&gt;int screenWidth = display.getWidth();&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt; To find the orientation of our Android Phone &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;To find out the orientation, that is whether it is in landscape, portrait or in any another orientation, the code is,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;int orientation = getResources().getConfiguration().orientation; &lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This will give the current orientation. To check whether it is in landscape or portrait,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;if (orientation == Configuration.ORIENTATION_PORTRAIT) {&lt;br /&gt;         // do something&lt;br /&gt;} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {&lt;br /&gt;         // do something else&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-4433461176416293674?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/8spbAFOYlf4" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-01-13T22:53:11.947+05:30</app:edited><feedburner:origLink>http://smartandroidians.blogspot.com/2011/01/fetching-screen-height-finding-screen.html</feedburner:origLink></item><item><title>Playing with lists in Android - Part II</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/AmIw0afdM1Q/playing-with-lists-in-android-part-ii.html</link><category>Adapter</category><category>ListView</category><category>Android</category><category>Chat</category><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Wed, 15 Dec 2010 06:12:21 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-4737150150843038484</guid><description>I hope you already read my first topic about listView. In part II, I am just extending the &lt;a href="http://smartandroidians.blogspot.com/2010/09/playing-with-lists-in-android.html" target="_blank"&gt;part I&lt;/a&gt; topic. So please read part I before reading part II. &lt;br /&gt;&lt;br /&gt;In this, I am creating an adapter, in which each list item consists of two views, a TextView and an IMageView respectively. I am putting these two views in a relative layout. Then I am aligning the imageView to the right end of the layout using the addRule(). One more thing is, here I am putting a static image, that is the standard Android icon.&lt;br /&gt;&lt;br /&gt;The adapter class is,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;    class MyAdapter extends BaseAdapter {&lt;br /&gt;     &lt;br /&gt;     Context mContext;&lt;br /&gt;     &lt;br /&gt;     public MyAdapter(Context context) {&lt;br /&gt;       mContext = context;&lt;br /&gt;     }&lt;br /&gt;     &lt;br /&gt;     public int getCount() {&lt;br /&gt;       return list.size();&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;     public Object getItem(int id) {&lt;br /&gt;       return id;&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;     public long getItemId(int position) {&lt;br /&gt;       return position;&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;     public View getView(int position, View convertView, ViewGroup parent) {&lt;br /&gt;        RelativeLayout layout = new RelativeLayout(mContext);&lt;br /&gt;&lt;br /&gt;        android.widget.RelativeLayout.LayoutParams params = new            android.widget.RelativeLayout.LayoutParams&lt;br /&gt;(android.widget.RelativeLaout.LayoutParams.WRAP_CONTENT,&lt;br /&gt;  android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);&lt;br /&gt;&lt;br /&gt;   android.widget.RelativeLayout.LayoutParams imgParams = new android.widget.RelativeLayout.LayoutParams\(android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT,&lt;br /&gt;     android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);&lt;br /&gt;&lt;br /&gt;      TextView tv = new TextView(mContext);&lt;br /&gt;      ImageView img = new ImageView(mContext);&lt;br /&gt;      tv.setText(list.get(position));&lt;br /&gt;      img.setImageResource(R.drawable.icon);&lt;br /&gt;      layout.addView(tv, params);&lt;br /&gt;      imgParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);&lt;br /&gt;      layout.addView(img, imgParams);&lt;br /&gt;      return layout;&lt;br /&gt;    }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The complete code is,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;public class SampleListView_Chatextends Activity {&lt;br /&gt; &lt;br /&gt; ListView lView;&lt;br /&gt; ArrayList&lt;String&gt; list;&lt;br /&gt; EditText eText;&lt;br /&gt; Button but;&lt;br /&gt; ArrayAdapter&lt;String&gt; adapter;&lt;br /&gt; LinearLayout layout, subLayout;&lt;br /&gt; LayoutParams params, lParams;&lt;br /&gt; &lt;br /&gt;    @Override&lt;br /&gt;    public void onCreate(Bundle savedInstanceState) {&lt;br /&gt;        super.onCreate(savedInstanceState);&lt;br /&gt;        layout = new LinearLayout(this);&lt;br /&gt;        layout.setOrientation(LinearLayout.VERTICAL);&lt;br /&gt;        subLayout = new LinearLayout(this);&lt;br /&gt;        params = new LayoutParams(LayoutParams.WRAP_CONTENT,   LayoutParams.WRAP_CONTENT);&lt;br /&gt;        lParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);&lt;br /&gt;        eText = new EditText(this);&lt;br /&gt;        but = new Button(this);&lt;br /&gt;        lView = new ListView(this);&lt;br /&gt;        list = new ArrayList&lt;String&gt;();&lt;br /&gt;        but.setText("Send");&lt;br /&gt;        /*adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, list);*/&lt;br /&gt;        lView.setAdapter(new MyAdapter(this));&lt;br /&gt;        but.setOnClickListener(new View.OnClickListener() {&lt;br /&gt;   &lt;br /&gt;   public void onClick(View v) {&lt;br /&gt;    list.add(eText.getText().toString());&lt;br /&gt;    eText.setText(null);&lt;br /&gt;    /*lView.setAdapter(adapter);*/&lt;br /&gt;    lView.setAdapter(new MyAdapter(SampleListView_Chat.this));&lt;br /&gt;   }&lt;br /&gt;  });&lt;br /&gt;        lParams.height = 380;&lt;br /&gt;        layout.addView(lView, lParams);&lt;br /&gt;        eText.setWidth(260);&lt;br /&gt;        subLayout.addView(eText, params);&lt;br /&gt;        subLayout.addView(but, params);&lt;br /&gt;        layout.addView(subLayout, params);&lt;br /&gt;        setContentView(layout);&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    class MyAdapter extends BaseAdapter {&lt;br /&gt;     &lt;br /&gt;            Context mContext;&lt;br /&gt;     &lt;br /&gt;  public MyAdapter(Context context) {&lt;br /&gt;   mContext = context;&lt;br /&gt;  }&lt;br /&gt;     &lt;br /&gt;             public int getCount() {&lt;br /&gt;   return list.size();&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public Object getItem(int id) {&lt;br /&gt;   return id;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public long getItemId(int position) {&lt;br /&gt;   return position;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public View getView(int position, View convertView, ViewGroup parent) {&lt;br /&gt;   &lt;br /&gt;                        RelativeLayout layout = new RelativeLayout(mContext);&lt;br /&gt;   &lt;br /&gt;                        android.widget.RelativeLayout.LayoutParams params = new android.widget.RelativeLayout.LayoutParams(android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT, android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);&lt;br /&gt;   &lt;br /&gt;                        android.widget.RelativeLayout.LayoutParams imgParams = new android.widget.RelativeLayout.LayoutParams(android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT, android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);&lt;br /&gt;   &lt;br /&gt;                        TextView tv = new TextView(mContext);&lt;br /&gt;   ImageView img = new ImageView(mContext);&lt;br /&gt;   tv.setText(list.get(position));&lt;br /&gt;   img.setImageResource(R.drawable.icon);&lt;br /&gt;   layout.addView(tv, params);&lt;br /&gt;   imgParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);&lt;br /&gt;   layout.addView(img, imgParams);&lt;br /&gt;   return layout;&lt;br /&gt;  }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Screenshot&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_zTrHGwhW4Tc/TQDkd97YoNI/AAAAAAAAArs/_QzBTnIFpUM/s1600/chat_img_adapter.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 215px; height: 320px;" src="http://2.bp.blogspot.com/_zTrHGwhW4Tc/TQDkd97YoNI/AAAAAAAAArs/_QzBTnIFpUM/s320/chat_img_adapter.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5548685944411431122" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-4737150150843038484?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/AmIw0afdM1Q" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-15T19:42:21.023+05:30</app:edited><media:thumbnail url="http://2.bp.blogspot.com/_zTrHGwhW4Tc/TQDkd97YoNI/AAAAAAAAArs/_QzBTnIFpUM/s72-c/chat_img_adapter.png" height="72" width="72" /><feedburner:origLink>http://smartandroidians.blogspot.com/2010/12/playing-with-lists-in-android-part-ii.html</feedburner:origLink></item><item><title>Some Android Tips</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/VRn_euifktU/some-android-tips.html</link><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Tue, 07 Dec 2010 06:55:23 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-417767204524916025</guid><description>If we connect the device and if it show offline in DDMS, from the options menu click "Reset ADB" or from command prompt first execute "adb kill-server". After executing that execute "adb start-server"&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_zTrHGwhW4Tc/TP5KjYCRXlI/AAAAAAAAArc/QRvfxpUsMx8/s1600/menu_resetADB.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 197px;" src="http://3.bp.blogspot.com/_zTrHGwhW4Tc/TP5KjYCRXlI/AAAAAAAAArc/QRvfxpUsMx8/s320/menu_resetADB.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5547953762574884434" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-417767204524916025?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/VRn_euifktU" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-07T20:25:23.825+05:30</app:edited><media:thumbnail url="http://3.bp.blogspot.com/_zTrHGwhW4Tc/TP5KjYCRXlI/AAAAAAAAArc/QRvfxpUsMx8/s72-c/menu_resetADB.png" height="72" width="72" /><feedburner:origLink>http://smartandroidians.blogspot.com/2010/11/some-android-tips.html</feedburner:origLink></item><item><title>Playing with Lists in Android - Part I</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/e2B07bANMIU/playing-with-lists-in-android.html</link><category>transscriptmode</category><category>ListView</category><category>Android</category><category>Chat</category><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Thu, 06 Jan 2011 08:43:44 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-6085831099409385112</guid><description>In this tutorial, first I am going to show you a simple but useful tutorial on ListView in Android. &lt;br /&gt;&lt;br /&gt;Whatever we are entering in the editText will be shown in the list, like a starting for chat application UI. &lt;br /&gt;&lt;br /&gt;Things required for this are ListView, adapter, arrayList, editText and a button. I created the layout in XML, as this is a small UI with few components. Another reason for this is, for my few previous projects, I need to use java for creating layouts. &lt;br /&gt;&lt;br /&gt;The complete code will look like this..&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;public class SampleListView_Chat extends Activity {&lt;br /&gt; &lt;br /&gt; ListView lView;&lt;br /&gt; ArrayList&lt;String&gt; list;&lt;br /&gt; EditText eText;&lt;br /&gt; Button but;&lt;br /&gt; ArrayAdapter&lt;String&gt; adapter;&lt;br /&gt; LinearLayout layout, subLayout;&lt;br /&gt; LayoutParams params, lParams;&lt;br /&gt; &lt;br /&gt;    @Override&lt;br /&gt;    public void onCreate(Bundle savedInstanceState) {&lt;br /&gt;        super.onCreate(savedInstanceState);&lt;br /&gt;        layout = new LinearLayout(this);&lt;br /&gt;        layout.setOrientation(LinearLayout.VERTICAL);&lt;br /&gt;        subLayout = new LinearLayout(this);&lt;br /&gt;        params = new LayoutParams(LayoutParams.WRAP_CONTENT,  LayoutParams.WRAP_CONTENT);&lt;br /&gt;        lParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);&lt;br /&gt;        eText = new EditText(this);&lt;br /&gt;        but = new Button(this);&lt;br /&gt;        lView = new ListView(this);&lt;br /&gt;        list = new ArrayList&lt;String&gt;();&lt;br /&gt;        but.setText("Send");&lt;br /&gt;        adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, list);&lt;br /&gt;        but.setOnClickListener(new View.OnClickListener() {&lt;br /&gt;   &lt;br /&gt;   public void onClick(View v) {&lt;br /&gt;    list.add(eText.getText().toString());&lt;br /&gt;    eText.setText(null);&lt;br /&gt;    lView.setAdapter(adapter);&lt;br /&gt;   }&lt;br /&gt;  });&lt;br /&gt;        lParams.height = 380;&lt;br /&gt;        layout.addView(lView, lParams);&lt;br /&gt;        eText.setWidth(260);&lt;br /&gt;        subLayout.addView(eText, params);&lt;br /&gt;        subLayout.addView(but, params);&lt;br /&gt;        layout.addView(subLayout, params);&lt;br /&gt;        setContentView(layout);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Another thing that is very useful in chat applicationa and for other purposes is to see the last entry that we entered. For scrolling the listview, in XML &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;android:transcriptMode="alwaysScroll"&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In java, the code is,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;listView.setStackFromBottom(true);&lt;br /&gt;listView.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_zTrHGwhW4Tc/TP5e2XmZ01I/AAAAAAAAArk/jpA87BT_Xng/s1600/listForChat.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 215px; height: 320px;" src="http://3.bp.blogspot.com/_zTrHGwhW4Tc/TP5e2XmZ01I/AAAAAAAAArk/jpA87BT_Xng/s320/listForChat.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5547976079108068178" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-6085831099409385112?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/e2B07bANMIU" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2011-01-06T22:13:44.738+05:30</app:edited><media:thumbnail url="http://3.bp.blogspot.com/_zTrHGwhW4Tc/TP5e2XmZ01I/AAAAAAAAArk/jpA87BT_Xng/s72-c/listForChat.png" height="72" width="72" /><feedburner:origLink>http://smartandroidians.blogspot.com/2010/09/playing-with-lists-in-android.html</feedburner:origLink></item><item><title>Creating shortcuts through Intent in Android</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/iuPr4gWoy-k/creating-shortcuts-through-intent-in.html</link><category>Android</category><category>Shortcut</category><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Sun, 12 Sep 2010 22:37:12 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-4103196722630859817</guid><description>We can create shortcut for an application through intent. Its not so difficult. First create an intent with the package name of the application and add some flags to it. Then create another intent and add the first intent to it as extras and broadcast the intent. That is it. &lt;br /&gt;&lt;br /&gt;The complete code is,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;public class CreateShortcut extends Activity {&lt;br /&gt;    &lt;br /&gt;    @Override&lt;br /&gt;    public void onCreate(Bundle savedInstanceState) {&lt;br /&gt;        super.onCreate(savedInstanceState);&lt;br /&gt;        setContentView(R.layout.main);&lt;br /&gt;        Intent shortcutIntent = new Intent();&lt;br /&gt;        Log.i("CreateShortcut", "Creating first intent called shortcutIntent");&lt;br /&gt;        shortcutIntent.setClassName(getPackageName(), "CreateShortcut");&lt;br /&gt;        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);&lt;br /&gt;        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);&lt;br /&gt;        Intent intent = new Intent();&lt;br /&gt;        Log.i("CreateShortcut", "Creating intent for broadcasting");&lt;br /&gt;        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);&lt;br /&gt;        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "ShortcutName");&lt;br /&gt;        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, false);&lt;br /&gt;        intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");&lt;br /&gt;        sendBroadcast(intent);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;b&gt;Steps for launching the shortcut is,&lt;/b&gt;&lt;/blockquote&gt; &lt;br /&gt;&lt;br /&gt;-&gt; Long press on the empty part of the home screen &lt;br&gt;&lt;br /&gt;-&gt; Select "Shortcuts" from the dialog that pop-up &lt;br&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_zTrHGwhW4Tc/THoewrGpgbI/AAAAAAAAAms/qyPDBCesNnQ/s1600/shortcut_1.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 215px; height: 320px;" src="http://4.bp.blogspot.com/_zTrHGwhW4Tc/THoewrGpgbI/AAAAAAAAAms/qyPDBCesNnQ/s320/shortcut_1.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5510750915594387890" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;-&gt; Select "Applications" from the dialog that pop-up &lt;br&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_zTrHGwhW4Tc/THofPIQELFI/AAAAAAAAAm0/s0Y-xuzmu40/s1600/shortcut_2.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 213px; height: 320px;" src="http://1.bp.blogspot.com/_zTrHGwhW4Tc/THofPIQELFI/AAAAAAAAAm0/s0Y-xuzmu40/s320/shortcut_2.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5510751438814587986" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;-&gt; Select "CreateShortcut" from the dialog that pop-up &lt;br&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_zTrHGwhW4Tc/THofgtsjWaI/AAAAAAAAAm8/jkjya_sUpFY/s1600/shortcut_3.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 212px; height: 320px;" src="http://2.bp.blogspot.com/_zTrHGwhW4Tc/THofgtsjWaI/AAAAAAAAAm8/jkjya_sUpFY/s320/shortcut_3.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5510751740923959714" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;-&gt; Now, we can see the shortcut for our application in home screen. &lt;br&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_zTrHGwhW4Tc/THogNjf3hrI/AAAAAAAAAnE/WcGAMd6npms/s1600/shortcut_4.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 214px; height: 320px;" src="http://2.bp.blogspot.com/_zTrHGwhW4Tc/THogNjf3hrI/AAAAAAAAAnE/WcGAMd6npms/s320/shortcut_4.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5510752511280514738" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-4103196722630859817?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/iuPr4gWoy-k" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-13T11:07:12.989+05:30</app:edited><media:thumbnail url="http://4.bp.blogspot.com/_zTrHGwhW4Tc/THoewrGpgbI/AAAAAAAAAms/qyPDBCesNnQ/s72-c/shortcut_1.JPG" height="72" width="72" /><feedburner:origLink>http://smartandroidians.blogspot.com/2010/08/creating-shortcuts-through-intent-in.html</feedburner:origLink></item><item><title>Creating LiveFolder in Android</title><link>http://feedproxy.google.com/~r/AndroidiansFeed/~3/8xCbS6eqQn4/creating-livefolder-in-android.html</link><category>Android</category><category>LiveFolder</category><author>noreply@blogger.com (Nithin M Warrier)</author><pubDate>Sun, 12 Sep 2010 22:39:22 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5182651788094880320.post-3116395494724313890</guid><description>In Android, a live folder is simply a &lt;u&gt;real-time view of a ContentProvider&lt;/u&gt;. LiveFolder allow displaying of data on home screen without launching the application. &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;public class CreateLiveFolder extends Activity {&lt;br /&gt;    &lt;br /&gt;    @Override&lt;br /&gt;    public void onCreate(Bundle savedInstanceState) {&lt;br /&gt;        super.onCreate(savedInstanceState);&lt;br /&gt;        Uri uri = Browser.BOOKMARKS_URI;&lt;br /&gt;        final Intent intent = getIntent();&lt;br /&gt;        final String action = intent.getAction();&lt;br /&gt;        if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {&lt;br /&gt;            setResult(RESULT_OK, createLiveFolder(this, uri,&lt;br /&gt;                    "Books", R.drawable.icon));&lt;br /&gt;        } else {&lt;br /&gt;            setResult(RESULT_CANCELED);&lt;br /&gt;        }&lt;br /&gt;        finish();&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    private static Intent createLiveFolder(Context context, Uri uri, String name, int icon) {&lt;br /&gt;        final Intent intent = new Intent();&lt;br /&gt;        intent.setData(uri);&lt;br /&gt;        intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME, name);&lt;br /&gt;        intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON,&lt;br /&gt;                Intent.ShortcutIconResource.fromContext(context, icon));&lt;br /&gt;        intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, LiveFolders.DISPLAY_MODE_LIST);&lt;br /&gt;        return intent;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The manifest file will look like this,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;br /&gt;&amp;lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"&lt;br /&gt;     package="com.createlivefolder" android:versionCode="1"&lt;br /&gt;     android:versionName="1.0"&amp;gt;&lt;br /&gt;&amp;lt;uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS" /&amp;gt;&lt;br /&gt;    &amp;lt;application android:icon="@drawable/icon"  android:label="@string/app_name"&amp;gt;&lt;br /&gt;   &amp;lt;activity android:name=".CreateLiveFolder"&lt;br /&gt;                  android:label="@string/app_name"&amp;gt;&lt;br /&gt;       &amp;lt;intent-filter&amp;gt;&lt;br /&gt;             &amp;lt;action android:name="android.intent.action.MAIN" /&amp;gt;&lt;br /&gt;             &amp;lt;category android:name="android.intent.category.LAUNCHER" /&amp;gt;&lt;br /&gt;       &amp;lt;/intent-filter&amp;gt;&lt;br /&gt;            &lt;br /&gt;       &amp;lt;intent-filter&amp;gt;&lt;br /&gt;             &amp;lt;action android:name="android.intent.action.CREATE_LIVE_FOLDER"/&amp;gt;&lt;br /&gt;             &amp;lt;category android:name="android.intent.category.DEFAULT" /&amp;gt;&lt;br /&gt;       &amp;lt;/intent-filter&amp;gt;&lt;br /&gt;       &amp;lt;/activity&amp;gt;&lt;br /&gt;&amp;lt;/application&amp;gt;&lt;br /&gt;&amp;lt;uses-sdk android:minSdkVersion="8" /&amp;gt;&lt;br /&gt;&amp;lt;/manifest&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In this case, I don't have any bookmark in my browser, so an empty content provider is shown.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;b&gt;Steps to launch LiveFolder :&lt;/b&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;After launching the application &lt;br&gt;-&gt; Long press on the empty space of the home screen &lt;br&gt;-&gt; Select "Folder" from the dialog that pop-up &lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_zTrHGwhW4Tc/THoT0octVvI/AAAAAAAAAmc/ZdEwyzlR_Ao/s1600/livefolder_1.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 214px; height: 320px;" src="http://4.bp.blogspot.com/_zTrHGwhW4Tc/THoT0octVvI/AAAAAAAAAmc/ZdEwyzlR_Ao/s320/livefolder_1.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5510738888973178610" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br&gt; -&gt; Select "CreateLiveFolder". &lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_zTrHGwhW4Tc/THoUHlareMI/AAAAAAAAAmk/yrR_HpjVW2U/s1600/livefolder_2.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 211px; height: 320px;" src="http://2.bp.blogspot.com/_zTrHGwhW4Tc/THoUHlareMI/AAAAAAAAAmk/yrR_HpjVW2U/s320/livefolder_2.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5510739214576875714" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br&gt;This will create the live folder in home screen in the name of "SampleLiveFolder".&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The screenshots are,&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_zTrHGwhW4Tc/TFwR4F_4iiI/AAAAAAAAAhg/05gk2G5WuQE/s1600/folder2.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 215px; height: 320px;" src="http://3.bp.blogspot.com/_zTrHGwhW4Tc/TFwR4F_4iiI/AAAAAAAAAhg/05gk2G5WuQE/s320/folder2.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5502292500120373794" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;When we click on the icon, our live folder called "SampleLiveFolder" will open. As my "bookmarks" in browser is empty, it will show an empty dialog box&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_zTrHGwhW4Tc/TFwRwRn7g6I/AAAAAAAAAhY/oZdbAv11SWA/s1600/folder1.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 214px; height: 320px;" src="http://3.bp.blogspot.com/_zTrHGwhW4Tc/TFwRwRn7g6I/AAAAAAAAAhY/oZdbAv11SWA/s320/folder1.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5502292365802177442" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;SmartAndroidians&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5182651788094880320-3116395494724313890?l=smartandroidians.blogspot.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/AndroidiansFeed/~4/8xCbS6eqQn4" height="1" width="1"/&gt;</description><app:edited xmlns:app="http://www.w3.org/2007/app">2010-09-13T11:09:22.081+05:30</app:edited><media:thumbnail url="http://4.bp.blogspot.com/_zTrHGwhW4Tc/THoT0octVvI/AAAAAAAAAmc/ZdEwyzlR_Ao/s72-c/livefolder_1.JPG" height="72" width="72" /><feedburner:origLink>http://smartandroidians.blogspot.com/2010/08/creating-livefolder-in-android.html</feedburner:origLink></item><media:rating>nonadult</media:rating></channel></rss>

