Pages

Tuesday, September 27, 2011

Google Maps in Android


Here you can find how to use Google Maps in your Android applications and how to programmatically perform the following:

  • Change the views of Google Maps
  • Obtain the latitude and longitude of locations in Google Maps
  • Perform geocoding and reverse geocoding
  • Add markers to Google Maps

Read response from HTTPpost method using HttpResponse (or any InputStream) as a String


This piece of code reads all inputstream response into string. Inputstream means of reading data from a source in a byte-wise manner.

 You get the entity response an InputStream object from HttpPost execute method. Essentially StringBuilder is a lot faster, and can be converted a normal string with .toString() method.

For reading the content of HttpResponse use convertStreamToString(response.getEntity().getContent())

HttpResponse responseGet = httpclient.execute(httppost);
HttpEntity entity = responseGet.getEntity();
if (entity != null) {
InputStream inputStreamResponse = entity.getContent();
result = convertStreamToString(inputStreamResponse);
}else {
 // code here for a response othet than 200.  A response 200 means the webpage was ok
 // Other codes include 404 - not found, 301 - redirect etc...
 // Display the response line.
System.out.println("Unable to load page - " + responseGet.getStatusLine());
}

Work with HTTP Post Request in android


The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line.
learn more about Httppost 


public void postData() {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://www.mysite.com/run.php");

    try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("id", "12345"));
        nameValuePairs.add(new BasicNameValuePair("stringdata", "HTTPPOST example!"));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);
       
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }
}

Wednesday, September 21, 2011

Create API Key for Google map for android


Generate the Certificate Fingerprint 
On Windows, open up a Command Prompt.
In the Command Prompt window, use the cd command to change to the .android subdirectory underneath your "home" directory, e.g. C:\Documents and Settings\xxxx\ where xxxx is your user name.

C:\> cd "\Documents and Settings\xxxx\.android"
Type in the following keytool command.

C:\> keytool -list -keystore debug.keystore

Note: if the system PATH is not set with the Java Development Kit's bin folder, then the full path to the keytool executable in the JDK/bin/ directory need to be used. For example,

Wednesday, November 24, 2010

ADT Plugin for Eclipse

Android Development Tools (ADT) is a plugin for the Eclipse IDE that is designed to give you a powerful, integrated environment in which to build Android applications.

ADT extends the capabilities of Eclipse to let you quickly set up new Android projects, create an application UI, add components based on the Android Framework API, debug your applications using the Android SDK tools, and even export signed (or unsigned) APKs in order to distribute your application.

Developing in Eclipse with ADT is highly recommended and is the fastest way to get started. With the guided project setup it provides, as well as tools integration, custom XML editors, and debug ouput pane, ADT gives you an incredible boost in developing Android applications.

This document provides step-by-step instructions on how to download the ADT plugin and install it into your Eclipse development environment. Note that before you can install or use ADT, you must have compatible versions of both the Eclipse IDE and the Android SDK installed. For details, make sure to read Installing the ADT Plugin, below.

If you are already using ADT, this document also provides instructions on how to update ADT to the latest version or how to uninstall it, if necessary.

Adding SDK Components

Adding and updating components in your Android SDK is fast and easy. To perform an update, use the Android SDK and AVD Manager to install or update the individual SDK components that you need. The Android SDK and AVD Manager tool is included in the Android SDK download.

It only takes a couple of clicks to install individual versions of the Android platform, new development tools, new documentation, and SDK add-ons. The new SDK components are automatically installed into your existing SDK directory, so you don't need to update your development environment to specify a new SDK location.

Because each version of the Android platform can be installed as an individual component of your SDK, you can customize your development environment to the Android platforms you are targetting. Testing your app on multiple versions of the platform is very important in order to successfully operate on as many devices as possible. Be sure to install each version of the Android platform with which your app is compatible, then test your apps on AVDs that run each platform.