Wednesday, 30 July 2014

Steps to create signed apk using eclipse adt


 
 * In ADT, right click on project

    Android tools ->Export signed Application Package->Project checks->select project to be exported by clicking on browse->click Next->create new keystore->enter the location for your apk for example test.apk(create a new folder for storing your signed apk )->enter password and confirm->click next and type all the details in key creations dialog. validity should be minimum 25 years->save

Signed apk will be created. Retain the keystore file for further updates of the application. Playstore will not accept any other keystore file.

Using developer account, after entering all the details and snapshots of the application, it could be published.

Thursday, 28 November 2013

HTC physical device not listed in android device chooser in windows os

Steps to make the HTC device available in android device chooser:

1. Download the latest HTC sync from http://www.htc.com/www/support/content.aspx?id=6196 and install the same. Your device should be recognised in HTC sync. Make the connection type in your phone as HTC sync.Uncheck USB debugging mode in development.

2. Right click Computer->Manage->Device Manager->Android USB devices->My Htc->right click-> update driver software->Browse my computer for  driver software->select the path adt-bundle->sdk->extras->google->usb driver and click on next and finish the installation sucessfully.

If google folder is not found in extras, then open Android SDK Manager in eclipse and install Google usb drivers package in extras section. This will create the google folder with the usb driver folders in the above specified path.

3. Now check the USB debugging mode and restart the eclipse. Run the Android project , your device will be listed in the android device chooser.




Friday, 22 November 2013

Fix for com.google.android.maps cannot be resolved to a type

Error:  com.google.android.maps cannot be resolved to a type

Fix: Right click on project->properties->android->Project Build target->select the relevant Google api (vendor Google inc)

If Google Apis is not present in project build target, install the Google API using Android sdk manager.
Restart the eclipse ,clean and rebuild the project with the Google API selected to fix the error.

Tuesday, 16 October 2012

Values set in EditText visible only when clicked..android problem fix..tested on HTC wildfire

Problem:
Sometimes, values set in EditText is displayed properly in android emulator but it does not show on device(tested with HTC wildfire). It shows only when the field is clicked and disappears when not focused.

Solution:
Set the theme before calling the setcontent() in oncreate.
It can be done in the following way...
setTheme(android.R.style.Theme);

Monday, 24 September 2012

Connect to remote mysql db with PHP webservice, and parse the JSON response object returned using JAVA

Hi, here is a sample code on how to connect to a remote mysql db using a php and parse the JSON response object returned


                  HttpClient httpclient = new DefaultHttpClient();

                 Inputstream is;
                 HttpPost httppost = new HttpPost("http://www.hostname.com/files/getbrowsedata.php");
               HttpResponse response = httpclient.execute(httppost);
               HttpEntity entity = response.getEntity();
                 is = entity.getContent();
        }catch(Exception e){
               Log.e("log_tag", "Error in http connection "+e.toString());
                      }
       

        //convert response to string
        try{
               BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"),8);
               StringBuilder sb = new StringBuilder();
               String line = null;
               while ((line = reader.readLine()) != null) {
                       sb.append(line + "\n");
               }
               System.out.println("sb::" +sb);
                String result=sb.toString();
               is.close();
       

        }catch(Exception e){
               Log.e("log_tag", "Error in http connection "+e.toString());
         }

//parse the JSON response object
 try{
       
        JSONObject json = new JSONObject(result);
        JSONArray json_array = json.getJSONArray("display");
       
            for (int i = 0; i < json_array.length(); i++) {
                JSONObject result_json_object = json_array.getJSONObject(i);
                String column1= result_json_object.getString("col_name_1");
              String column2= result_json_object.getString("col_name_2");
   
                System.out.println(" column1 ::"+ column2 );
             
                }
            }
        }catch(JSONException e){
             Log.e("log_tag", "Error parsing data "+e.toString());
                
        }


Thursday, 20 September 2012

How to access a .properties file on remote server using Java

One of the simplest ways to access a .properties file on remote server is by sending a HTTP request. Similarly any other type of file can also be accessed by using the appropriate API
It can be done in the following way...


Properties prop = new Properties();

    try {
               //load a properties file
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new  HttpPost("http://hostname/xxx.properties");
    HttpResponse response =   httpclient.execute(httppost);
    HttpEntity entity = response.getEntity();
    InputStream is = entity.getContent();
    prop.load(is);

    //get the property value and print it out
    System.out.println(prop.getProperty("url"));
   
    } catch (IOException ex) {
    ex.printStackTrace();
        }

    }

Monday, 3 September 2012

Fix for Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONException

Problem:
Fix for Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONException in eclipse IDE

Cause:
json jar not found in the class path

Fix:
Download json jar
www.java2s.com/Code/Jar/j/Downloadjavajsonjar.htm

Select project->Build path->Add external jar->add the jar->clean and build the project