}
IAWIA
Wednesday, January 02, 2013
Android: Checking if Internet is available
}
Android: Downloading a file to an external directory
So lets see the code for the same. I will be using the same HttpResponseContainerVO described previously.
Since we are downloading a file, instead of encoding the response in the VO, I am storing the file in the path and returning the absolute path of the file in response.
Downloading file:
HttpResponse response = client.execute(get);
}
Getting external file path:
}
Now you have successfully downloaded and stored the file in the external / internal storage. How do you open this file from your app? Simple, follow the code below.
}
Android: Posting data to server & reading response
That's all :)
Friday, December 28, 2012
Android: Using HttpClient to execute GET requests
Class that is used to hold the HTTP Response from the server.
//Add any additional headers you require.
private String response;
// Getters and Setters for all the fields.
}
Method to query and retrieve the Contents of a URL
Thursday, December 27, 2012
Android Tips n Tricks
Putting together some android tricks that I had to adopt to make my application work on all the different screen resolutions.
One of the first troubles I had with android was making sure that the header we had developed looked the same for every screen resolution in both the portrait and landscape mode.
The header image we developed consisted of 3 parts
- Logo on the left
- Logout button on the right
- Page heading at the center.
Sample shown below:
Now that you have seen the image, lets come to the problem. Even if we generate the image in the 3:4:6:8 ratios that android suggest we still face the problem on screens with different resolutions with the image being stretched and looking awkward. < br/>
In order to overcome this we simply split the images into 3 parts. You can split it into 'n' parts depending on your requirement.
The three parts corresponding to the three things we needed to display as as follows.
Now to get a consistent header all we had to do was use a Relative Layout and arrange the images as follows:
1. Arrange the image with logo to the left of the screen.
2. Arrange the image with logout to the right of the screen.
3. Arrange the blank background image such that its left edge touches the right edge of the logo and the right edge touches the left edge of the logout. Thus stretching the plain image on every screen resolution.
Monday, December 17, 2012
The Angel
I had made my peace with my maker. I was just counting days till I met him. Locked up in the darkest room in the dungeon I was at peace finally.
In a world where surviving each day is difficult, I tried to stand up to the weak. To uphold the values of truth & justice. That was my fatal flaw. Hoping that the common man would rise with me if I started the rebellion. I had heard that all it took was one person to start a revolution. When I saw no one else stepping up, I tried and failed.
Captured, Tortured and Branded a traitor to the realm, I was sentenced to die by hanging at the next full moon. It was seven days away.
It was then that I realized that there was only one way to survive in this world. Be selfish. Do whatever is good for you and your family. Do not care about others - for no one will stand with you when the chips are down. As the saying goes - we win as a team and fail as individuals. I had failed and accepted it.
As I laid there - chained and hungry - unaware of the time that had passed since I was condemned, I heard footsteps for the first time. With great effort I pulled myself up to stand. I did not want them to see my weakness. I did not want them seeing me lying down ready to die. I had to be defiant to my executioners. I know I had stood up for a right thing and I would die in that knowledge.
As the footsteps grew louder I tried to focus my vision to see my executioners. At last I saw something moving towards me. They had a light. Dear sweet light. Light I had not seen in an eternity. All I could make with my blurred vision was a piercing light moving towards me. I just stood there frozen with eyes closed. Finally the shadows spoke - "Water". It was not my executioners. It was the voice of an angel. I opened my eyes and tried to see who it was but she was already moving away from me. All I could see was her shadow falling on me as she moved away with the light and a bowl of water laid down in front of me.
That was all I needed, dropping to me knees I picked up the bowl and drank from it as if there was no tomorrow. As I put the bowl down and lifted my head I saw her turn to have a look at the man who was branded a traitor and condemned to die.
For the first time since my capture I could see someone who felt pity for me. I could see that much in her face. I was not expecting it but after seeing me in the eye she turned around and walked back to me.
She walked up to me and sat down with her legs crossed putting the light between us. I could see her clearly now. I knew at that instant - in an other time, in an other life, if things had been different I would have knelt in front of her with a flower and asked her to marry me.
Looking at her and dreaming, I forgot to speak. It was her voice that broke the silence. She said she understood why I had started the rebellion and from the bottom of her heart she supported my cause. She said had she had any training with the swords she would have picked up one and fought beside me, unfortunately she was just a simple girl who worked in the prison serving food.
After that I was hardly able to comprehend what she was saying, my mind drifted. I did not know if it was the hunger or the water. I just laid down and I could hear her voice - as if she was speaking from a very distant location. Slowly the light around me started to fade and the voice grew distant. Finally the light went out and all I could hear was a distant blur of a noise and then everything just went blank.
Silence. Peace. No more pain, no more worries. As death embraced me in its arms and carried me to a better place, I was given one final glimpse of the dungeon. There I saw my lifeless body and the angel sitting next to me and patting my head.
The End.



