Saturday, September 15, 2012

Socket Programming with Android

This weekend I tried my hand on socket programming with Android. I got it challenging, because emulator has its own settings for forwarding the packet. So it is so important to know how emulator forwards packet to any target IP address.

Ex.
If we send packet to 127.0.0.1, a simple thought that will come to mind is packet will be sent to developer host machine, but actually packet is targeted to android device.

I got good help by following page. Please read this before start socket programming on android emulator.
http://developer.android.com/tools/devices/emulator.html#connecting

:) B-)

Enabling PC's Key Board on Android Emulator

Today I faced one problem with android emulator, my pc keyboard is not working with the android emulator. The reason behind this was the update of upgrading the sdk.

This can be fixed by following steps :
  1. Eclipse > Window menu > AVD Manager
  2. Select your virtual device and click Edit
  3. Under Hardware, Click New
  4. Select Keyboard Support then click OK
  5. Edit its value to yes
And start your emulator with enabled PC's keyboard.

:) B-)

Reference:

Sunday, August 12, 2012

How to call Rest Service

Following is android sample application to call rest service(yahoo api).
https://github.com/subh007/rest_service

How to create custom background button

1. Create a new xml in drawable folder (customize_button.xml)

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
     <item android:state_focused="true"
          android:state_pressed="false"
          android:drawable="@drawable/ic_launcherweb" />
    <item android:state_focused="true"
          android:state_pressed="true"
          android:drawable="@drawable/ic_launcher" />
    <item android:state_focused="false"
          android:state_pressed="true"
            android:drawable="@drawable/ic_launcherweb" />
    <item android:drawable="@drawable/ic_launcher"
           android:state_focused="false"
           android:state_pressed="false"/>
</selector>

2. now add a new line in your main.xml (android:background="name_of_background"

<Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView1"
        android:layout_alignLeft="@+id/textView1"
        android:layout_marginBottom="82dp"
        android:text="customized button"
        android:background="@drawable/customize_button" />

now you will have your own customized background button