How to parsing JSON in android.

Friday, September 28, 2012

I am taking an example of following JSON which will give you list of contacts and each contact will have details like name, email, address, phone number ertc,.


If you observe normally JSON data will have square brackets and curly brackets. The difference between [ and { is, the square bracket represents starting of an JSONArray node whereas curly bracket represents JSONObject. While accessing these elements we need to call different methods to access these nodes.


  • Writing JSON Parser Class

In your project create a class file and name it as JSONParser.java. The parser class has a method which will make http request to get JSON data and returns a JSONObject.

Integration of android application with twitter.

Thursday, September 27, 2012


Are you an Android developer who wants to integrate your app with Twitter so that your end user can:

1. Login with Twitter
2. Post messages to Twitter

It’s not so hard to achieve these two - if you know what you are doing. And the steps below should make it easy for you to achieve the desired results.


  • Setting up the Twitter account and application.
The basic steps are:

1. You have to create an Account on Twitter before you do anything.
2. Register you application with Twitter here (https://dev.twitter.com/user)
3. Create the Activity to enter your tweet

Integration of android application with facebook.

This tutorial is about integrating facebook into your android application. I am going to explain various steps like generating your application signature, registering facebook application, downloading facebook sdk and other steps.

  • Generating App Signature for Facebook Settings

To create facebook android native app you need to provide your Android application signature in facebook app settings. You can generate your application signature (keyhash) usingkeytool that comes with java. But to generate signature you need openssl installed on your pc. If you don’t have one download openssl from here and set it in your system environment path.
Open your command prompt (CMD) and run the following command to generate your keyhash. While generating hashkey it should ask you password. Give password as android. If it don’t ask for password your keystore path is incorrect.

keytool -exportcert -alias androiddebugkey -keystore "<path-to-users-directory>\.android\
debug.keystore" | openssl sha1 -binary | openssl base64

check the following command how i generated hashkey on my pc.

keytool -exportcert -alias androiddebugkey -keystore "C:\users\raj\.android\debug.keystore"
| openssl sha1 -binary | openssl base64


Android kSoap2 web service parsing Data.


Android kSoap2 web service Parsing Data
In this tutorial for Android ksoap2 web service . we can passing data through web service and store the data in web server.
how to read and parse JSON or XML, but another (pretty big) format is SOAP. In this post we will see how you make a application that reads and parses SOAP data into a Android application!
first we need ksoap2-android-assembly-2.5.6-jar file. download this jar file and put your workspace lib folder.

  • Just click the most recent version
  • search for the jar file with dependencies.
  • download it by right clicking the link "Raw file"
  • then clicking "Save as ...".
  • Save it inside your project folder so you can link it easily. 
Note: add the jar file to the project. ( Project properties -> Java build path -> Add JAR's )

Source code :

Load images from server in android.

Wednesday, September 26, 2012

This tutorial demonstrates how to load a remote image into your application and bind this image to an ImageView object. HttpURLConnection is used to download the image data and BitmapFactory is used to produce the bitmap which will be used as ImageView resource.

Java Code :


import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

public class HTTPTest extends Activity {
     

     ImageView imView;
     String imageUrl="http://11.0.6.23/";
     Random r= new Random();
    /** Called when the activity is first created. */ 
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
       
        Button bt3= (Button)findViewById(R.id.get_imagebt);
        bt3.setOnClickListener(getImgListener);
        imView = (ImageView)findViewById(R.id.imview);
    }    

How to display images to gridview from server in android

Tuesday, September 25, 2012


This code is help you to display image in grideview from server in android.

ViewImage.java

package com.gridview;


import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.widget.AdapterView;

import android.widget.GridView;

import android.widget.Toast;


public class MyGridView extends Activity {

    private GridView girGridView;

   @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);


        girGridView=(GridView) findViewById(R.id.gridView1_bir);


        girGridView.setAdapter(new ImageAdapter(this));


        girGridView.setOnItemClickListener(new AdapterView.OnItemClickListener()  {

       public void onItemClick(AdapterView<?> arg0, View view,                    int position,long arg3) {
      Toast.makeText(getApplicationContext(), GridViewConfig.getResim_list().
                 get(position), Toast.LENGTH_SHORT).show();

            }
        });

    }

}

Enable GPS programmatically in android.

Sunday, September 23, 2012


Here's some example code i use it help you.

private void turnGPSOn(){
    String provider = Settings.Secure.getString(getContentResolver(),
                      Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

    if(!provider.contains("gps")){ //if gps is disabled
        final Intent poke = new Intent();
        poke.setClassName("com.android.settings", "com.android.
          settings.widget.SettingsAppWidgetProvider"); 
        poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
        poke.setData(Uri.parse("3")); 
        sendBroadcast(poke);
    }
}

How to generate google map key for android?


It is not only about the Android app keystore or the Android Maps API Key. It is a combination of both. We need the keystore when we want to sign a App.
The way you can sign a App is as follow; (I am giving instructions by assuming that you are working with Eclipse IDE)
  • Right click on your project in the Package Explorer window
  • Android Tools -> Export signed application package
  • In Project Checks window, brows your project and go to next window
  • There, select "Create new keystore" and follow the wizard
  • Don't give the default password which comes with the Eclipse debug key
Then you can finish creating a signed key for your app. Next procedure is Android Maps API Key Signup process. Here I am assume that you are doing implementation in a Windows environment