Friday, 29 June 2012

Android getting google map key

write the batch file as follows
keytool -list -keystore %1
pause

and then get the debug.kestore from the following location

 C:\Documents and Settings\rreddy.avula\.android

and just drop debug.kestore onto batch file then press any key then it will give MD5 fingerprint

35:39:90:89:67:6E:8B:E8:DD:61:D5:6B:4E:13:B5:D8
and then click on the following link

https://developers.google.com/android/maps-api-signup

then click on Generate API key

and enjoy

Tuesday, 27 December 2011

Detect Touch Event

 package com.TestSingleTouch;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

public class TestSingleTouch extends Activity {

TextView textEvent, textX, textY;

   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       LinearLayout MainLayout = (LinearLayout)findViewById(R.id.mainlayout);
       textEvent = (TextView)findViewById(R.id.event);
       textX = (TextView)findViewById(R.id.x);
       textY = (TextView)findViewById(R.id.y);
     
       MainLayout.setOnTouchListener(OnTouchListener);
   }
 
   private View.OnTouchListener OnTouchListener
   = new View.OnTouchListener(){

 @Override
 public boolean onTouch(View view, MotionEvent motionEvent) {
  // TODO Auto-generated method stub
 
  textX.setText("x: " + String.valueOf(motionEvent.getX()));
  textY.setText("y: " + String.valueOf(motionEvent.getY()));
 
  int action = motionEvent.getAction();
 
  switch (action){
  case MotionEvent.ACTION_DOWN:
   textEvent.setText("ACTION_DOWN");
   break;
  case MotionEvent.ACTION_MOVE:
   textEvent.setText("ACTION_MOVE");
   break;
  case MotionEvent.ACTION_UP:
   textEvent.setText("ACTION_UP");
   break;
  case MotionEvent.ACTION_CANCEL:
   textEvent.setText("ACTION_CANCEL");
   break;
  default:
   textEvent.setText("Unknown!");
  }

  return true; //means event have been processed
 }
  
   };
}



  
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:id="@+id/mainlayout"
   >
<TextView
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="@string/hello"
   />
<TextView
   android:id="@+id/event"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   />
<TextView
   android:id="@+id/x"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   />
<TextView
   android:id="@+id/y"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   />
</LinearLayout>


Detect Touch Event

How to pass bitmap between activities

In First Activity
        Intent intent = new Intent();
        intent.setClass(First.this, second.class);
        intent.putExtra("Bitmap", bitmap);
        startActivity(intent);
 
In Second Activity
 Bitmap bitmap = (Bitmap)this.getIntent().getParcelableExtra("Bitmap");
 
 
Thats all..
 

Wednesday, 12 October 2011

Android Market Login Url

To register as an Android Market developer and get started with publishing, visit the Android Market publisher site:
http://market.android.com/publish

 
It costs USD25

Thursday, 25 August 2011

Android version getting programatically

            try{
                     int currentapiVersion = android.os.Build.VERSION.SDK_INT;
                     if(currentapiVersion>=7){
                       //write your logic
                     }
                 }catch (Exception e) {
                    // TODO: handle exception
                }

HttpGet Conncetion in andorid

public static InputStream openHttpConnectionn(String urlStr) {

        InputStream in = null;

        int resCode = -1;

        try {
        if(Constants.LOG)Log.d("openHttpConnection", "URL:"+urlStr);
        URL url = new URL(urlStr);
        URLConnection urlConn = url.openConnection();//Opening Connection
                    
        if (!(urlConn instanceof HttpURLConnection)) {

                      throw new IOException ("URL is not an Http URL");
        }
        if(Constants.LOG)Log.d("openHttpConnection", "httpConn:1");

        HttpURLConnection httpConn = (HttpURLConnection)urlConn;

        httpConn.setAllowUserInteraction(false);

        httpConn.setInstanceFollowRedirects(true);
        httpConn.setRequestMethod("GET");
        httpConn.setRequestProperty("User-Agent", "Mozilla/5.0 (X11; U; Linux "+"i686; en-US; rv:1.8.1.6) Gecko/20061201 Firefox/2.0.0.6 (Ubuntu-feisty)");
        httpConn.setRequestProperty("Content-Type", "image/*");
//        HttpConnectionParams.setConnectionTimeout((HttpParams) httpConn, Constants.CONNECTIONTIMEOUT);
//        HttpConnectionParams.setSoTimeout((HttpParams) httpConn, Constants.CONNECTIONTIMEOUT);
        httpConn.setConnectTimeout(Constants.CONNECTIONTIMEOUT);
        httpConn.setReadTimeout(Constants.CONNECTIONTIMEOUT);
       
        if(Constants.LOG)Log.d("openHttpConnection", "setting requests and properties");
       
        httpConn.connect();
       
        if(Constants.LOG)Log.d("openHttpConnection", "Connected successfully");
       
        resCode = httpConn.getResponseCode();  
       
        if(Constants.LOG)Log.d("openHttpConnection", "resCode"+resCode);
       
        if (resCode == HttpURLConnection.HTTP_OK) {
       
        in = httpConn.getInputStream();
       
        if(Constants.LOG)Log.d("openHttpConnection", "Fetchinf data done");
       
        }       

        } catch (MalformedURLException e) {

                      e.printStackTrace();

                      if(Constants.LOG)Log.d("openHttpConnection", "1"+e);

        } catch (IOException e) {

                      e.printStackTrace();

                      if(Constants.LOG)Log.d("openHttpConnection", ""+e);

        }catch (Exception e) {
            // TODO: handle exception
            return null;
        }

        return in;
}

Validating Xml in andorid

Some times the response ,came from webservice may contains &lt,&gt.

Inthis case You have to convert '&lt' as '<' and '&gt' as '>'.

public static String validateXml(String xml)
    {
        int offset=0;
        StringBuffer temp=new StringBuffer();
        try{
            while(xml.indexOf("&lt;",offset)!=-1||xml.indexOf("&gt;",offset)!=-1&&offset<xml.length()){
                // if(Constants.LOG)Logger.info("Into &lt and & rt");
                if((xml.indexOf("&lt;",offset)<xml.indexOf("&gt;",offset))&&(xml.indexOf("&lt;",offset)!=-1)||((xml.indexOf("&gt;",offset)==-1)&&(xml.indexOf("&lt;",offset)!=-1))){
                // if(Constants.LOG)Logger.info("Converting &lt into <");
                temp.append(xml.substring(offset, xml.indexOf("&lt;",offset)));
                temp.append("<");
                offset=xml.indexOf("&lt;",offset)+"&lt;".length();
        }
        else if((xml.indexOf("&gt;",offset)<xml.indexOf("&lt;",offset)&&(xml.indexOf("&gt;",offset)!=-1))||((xml.indexOf("&lt;",offset)==-1)&&(xml.indexOf("&gt;",offset)!=-1))){
            // if(Constants.LOG)Logger.info("Converting &lt into >");
            temp.append(xml.substring(offset, xml.indexOf("&gt;",offset)));
            temp.append(">");
            offset=xml.indexOf("&gt;",offset)+"&gt;".length();
        }
        // if(Constants.LOG)Logger.info("offset is : "+offset);
        }
        if(offset<xml.length()){
            temp.append(xml.substring(offset));
        }
        }catch (Exception e) {
        // TODO: handle exception
            //if(Constants.LOG)Logger.info("Array out of bound of exception");
        }
            xml=temp.toString();
        return xml;
    }