You are on page 1of 19

Do Something App

a Location Map using Web Server.


Thank you for purchasing Do Something App. If you have any questions that are beyond the scope of this user guide file, please feel free to email via my user page contact form here. Thanks so much!

Author : Jhonson ID Envanto : xcl0ude Version : 1.1 Created : 8 July 2012 Email : v_jonz1@yahoo.com

Table of Content
1. 2. 3. 4. 5. 6. 7. 8. 9.
About the File. Getting Started. Importing the Project. Getting Google Map API Key Inserting Your API Key Customizing the Color. Configuration PHP and MySQL Using Hardware Debugging. Compiling Application.

1. About the File


Flower Collection App is an full application that you can use to create your own Information about Flower using Sqlite Database application under Android Platform. In this application you can find many features to take a Photo or Picture from your Album in your sdcard or take Photo from your Camera devices. Inside this package you will get a project file containing this full application, apk file and this user guide file.

2. Getting Started
Before starting developing this app you need first install the following softwares to your computer. If you have already installed these softwares you can skip this step.

1. Java Development Kit (JDK) 5 or greater, which can be downloaded here. 2. Eclipse 3.5 (Galileo/ Indigo/Helios) or greater, which can be downloaded here.
Choose the Eclipse IDE for Java EE developers .

3. Android SDK, download link is here . 4. ADT plugin for Eclipse, which can be downloaded here .
Install Java Development Kit and Eclipse to your computer and extract Android SDK package to any location on your computer. After that, run Eclipse and select Window > Preferences. Preferences window will appear, select Android and click Browse... button. Find the location of Android SDK which has already extracted before. Then, click Apply and OK.

Window Preferences Now, open Android SDK and AVD Manager by selecting Window > Android SDK and AVD Manager. Select Available Packages option on the left side. Give check to Android Repository then click Install Selected. New window will appear, click Install button.

Android SDK and AVD Manager

Next step is installing ADT plugin on eclipse. Run eclipse and select Help > Install New Software.... Install window will appear. Click Add button and then click Archive button on Add Site... window. Find the location of ADT plugin package. Then click OK. Follow the instructions on that window till finish.

Installation window

Now, create an emulator to run Android application you are going to develop. Select Window > Android SDK and AVD Manager. On Android SDK and AVD Manager click New button. Fill all the form on new window that appears. For Target choose Google APIs (Google Inc.) - API Level 8. if you have already filled all the form click Using Hardware For Debugging.

Create AVD

Software requirements have already installed on your computer. now, you are ready to develop this app and create your own android map application. Reference Links : Installing the SDK http://developer.android.com/sdk/installing.html Installing the ADT Plugin http://developer.android.com/sdk/eclipse-adt.html#installing

3. Importing the Project


To edit this application you need to import package of this app into Eclipse. Run Eclipse on your computer and select File > Import. Import window will appear. Select General > Existing Projects into Workspace and click Next > button. On the next step choose Select root directory and click Browse... button. Find the location of Shake Player package which has already extracted. Then click Finish.

4. Getting Google Maps API Key

To implement Google Maps on Android app you need to get your own Google Maps API key. There are two types of Google Maps API key, first is debug API Key for debugging and second is release API Key for signing the application when you create .apk file.

Debug API
Key To get API key for debugging you need to find debug.keystore file which is located in C:\Documents and Settings\<user>\.android\debug.keystore for Windows XP and C:\Users\<user>\.android\debug.keystore for Windows Vista. Copy that file to a folder in C:\, for example in C:\Android. Now, go to "C:\Program Files\Java\<JDK_version_number>\bin" through Command Prompt and type command below.

The result of this command is Certificate fingerprint (MD5) code. Copy it and go to http://code.google.com/android/maps-api-signup.html to sign up your API key. You need to login with your Google account. After getting your API key for debugging, save that API key into a file on your computer. It will always be used when you debug map applications. Release API Key Your debug API key will only work for debugging. If you plan to create apk file of your application you need to change that API key with release API key. To get it, go to "C:\Program Files\Java\<JDK_version_number>\bin" through Command Prompt and type command below. To get it, go to "C:\Program Files\Java\<JDK_version_number>\bin" through Command Prompt and type command below.

keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
change my-release-key and alias_name with a name you like. After that, enter keystore password and other given informations. When finish, type command bellow. keytool -list -alias alias_name -keystore my-release- key.keystore change alias_name with alias name you have already had before and also my- release-key. Always remember your alias name, release key, and your keystore password. The result of command above is Certificate fingerprint (MD5) code. Copy that code and again, go to

http://code.google.com/android/maps-api-signup.html to sign up your API key. When you get your release API key, copy it to a file on your computer. Reference Links : Obtaining a Maps API Key http://code.google.com/android/add-ons/google-apis/mapkey.html#getfingerprint Using Google Maps in Android http://mobiforge.com/developing/story/using-google-maps-android

5. Inserting Your API Key


To make map on this application viewable you need to insert your own Google Map API Key. Find this code below on insertsomething.xml, mapsomething.xml, updatesomething.xml & lookingallmap.xml and change your Google Map API Key here with your own Google Map API Key. Note : put your API Key inside the . <com.google.android.maps.MapView android:id="@+id/mapView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:enabled="true" android:clickable="true" android:apiKey=your Google Map API Key here" /> because, in this case you are still costumizing this app it's better to insert debug API key. The example of code above looks like this. <com.google.android.maps.MapView android:id="@+id/mapView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:enabled="true" android:clickable="true" android:apiKey="0-rGkBw0QHorsDVUU_--JEHpiGT3dTDcn1oWnug" />

6. Customizing the Color.

Default color of this application is Green. You can change the color to your favorite one by finding the code below on jd_bar.xml in drawable directory, android:endColor using for down color and android:StartColor for upper color.

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape> <solid android:color="#997A5C" /> <stroke android:width="1dip" android:color="#A3876C" /> <corners android:radius="5dip" /> <padding android:left="10dip" android:right="10dip" android:top="10dip" android:bottom="10dip" /> </shape> </item> </selector>

latar_isi.xml
the I am using another color implementation into button.xml to change event color when button onclick or default or onselected. I am using this implementation for many xml code like latar_form.xml, title.xml, and latar_list.xml. The code Example is: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" > <shape> <gradient android:startColor="#474747" android:endColor="#292929" android:angle="270" /> <stroke android:width="1dip" android:color="#2c2b2c" /> <corners

android:radius="10dip"/> <padding android:left="10dip" android:top="5dip" android:right="10dip" android:bottom="5dip" /> </shape> </item> <item android:state_focused="true" > <shape> <gradient android:startColor="#474747" android:endColor="#292929" android:angle="270" /> <stroke android:width="1dip" android:color="#2c2b2c" /> <corners android:radius="10dip"/> <padding android:left="10dip" android:top="5dip" android:right="10dip" android:bottom="5dip" /> </shape> </item> <item> <shape> <gradient android:startColor="#1F0F00" android:endColor="#291400" android:angle="270" /> <stroke android:width="1dip" android:color="#140A00" /> <corners android:radius="10dip" /> <padding android:left="10dip" android:top="5dip" android:right="10dip" android:bottom="5dip" /> </shape> </item> </selector>

button.xml
Change value of android:startColor and android:endColor with the colors of yours.

7. Configuration Php and MySQL


This application is using MySQL database in Web Server Apache for save all contain data and using php files to give bridge into activity to MySQL. This application is using a simple php but it's not ver simple because is using to create some small or middle web based location like this app. First you must download a WebServer like xampp or wampserver like this and install that : http://www.apachefriends.org/en/xampp-windows.html http://www.wampserver.com/en/
You must configure a webserver and activate Apache and MySQL. Then you must going to folder WebServer into your folder htdocs or www and create a example folder like DoSomething(i used for this application). This folder is using for save and location to all php files and one folder to upload file then you must create one folder like Upload(i used this folder into DoSomething App) to located all file image into this app. Like this :

Then configure and create database MySQL into your http://localhost/phpmyadmin into your browser and create table tbl_do-something (I used to this app) like this :

Then configure variable tbl_do_something like this : (I used for this app)

If you finish that you can create a php files (I give a php files in this app) to access this database and table to save all data. Now you can create a php file like insert, select or delete a data. Example code to access using php like this : <?php // this is using for access localhost $host = "127.0.0.1"; // this is a root admin localhost $user = "root"; // this is a password $pass = "12345"; // this is a database $db = "db_do_something"; // method to connect in database MySQL $con = mysql_connect($host, $user, $pass) or die("Error : ".mysql_error()); $pilihDB = mysql_select_db($db, $con) or die("Error : ".mysql_error()); // this is target path to upload file like image. $target_path = "upload/"; chmod($target_path, 0777); $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). "has been uploaded"; }

else { echo "There was an error uploading the file, please try again!"; } // this is variables using for insert into database using POST. $subject = $_POST['subject']; $ins_date = $_POST['ins_date']; $ins_time = $_POST['ins_time']; $longitude = $_POST['longitude']; $latitude = $_POST['latitude']; $address = $_POST['address']; $description = $_POST['description']; $image = $_POST['image']; $pieces = explode("/", $image); $images = $pieces[3]; // this is a function to insert into database using that variables. if($images <> '') { $perintahSQL = "INSERT INTO tbl_do_something(subject, ins_date, ins_time, longitude, latitude, address, description, image) VALUES ('$subject', '$ins_date', '$ins_time', '$longitude', '$latitude','$address','$description', '$images')"; $eksekusiSQL = mysql_query($perintahSQL) or die("Error : ".mysql_error()); // this is a log string if($eksekusiSQL){ echo "Insert Map Successfuly"; }else{ echo "Insert Map Failed"; } } ?>

api-insert.php
Now you can create any php files like this to access your database to create a application MapView like this. Now is create some file java to access that php files like this : // this is variables return to send into POST public String uploadToServer(String subject, String ins_date, String ins_time, String longitude ,String latitude, String address, String description, String image, String URL){ HttpURLConnection connection = null; DataOutputStream outputStream = null; String pathToOurFile = image;

String urlServer = URL; String lineEnd = "\r\n"; String twoHyphens = "--"; String boundary = "*****"; String serverResponseMessage = null; int bytesRead, bytesAvailable, bufferSize; byte[] buffer; int maxBufferSize = 1*1024*1024; // this function to upload file like image into WebServer. try { FileInputStream fileInputStream = new FileInputStream(new File(pathToOurFile) ); URL url = new URL(urlServer); connection = (HttpURLConnection) url.openConnection(); // Allow Inputs & Outputs connection.setDoInput(true); connection.setDoOutput(true); connection.setUseCaches(false); // Enable POST method connection.setRequestMethod("POST"); connection.setRequestProperty("Connection", "Keep-Alive"); connection.setRequestProperty("Content-Type", data;boundary="+boundary); "multipart/form-

outputStream = new DataOutputStream( connection.getOutputStream() ); outputStream.writeBytes(twoHyphens + boundary + lineEnd); outputStream.writeBytes("Content-Disposition: name=\"uploadedfile\";filename=\"" + pathToOurFile +"\"" + lineEnd); outputStream.writeBytes(lineEnd); bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); buffer = new byte[bufferSize]; // Read file bytesRead = fileInputStream.read(buffer, 0, bufferSize); while (bytesRead > 0) { outputStream.write(buffer, 0, bufferSize); bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize);

form-data;

bytesRead = fileInputStream.read(buffer, 0, bufferSize); } outputStream.writeBytes(lineEnd); outputStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd); serverResponseMessage = connection.getResponseMessage(); fileInputStream.close(); outputStream.flush(); outputStream.close(); String hasil = ""; Log.d("getRequest",urlServer); HttpClient client = new DefaultHttpClient(); HttpPost request = new HttpPost(urlServer); // this is a method to send variables to POST. try{ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(8); nameValuePairs.add(new BasicNameValuePair("subject", subject)); nameValuePairs.add(new BasicNameValuePair("ins_date", ins_date)); nameValuePairs.add(new BasicNameValuePair("ins_time", ins_time)); nameValuePairs.add(new BasicNameValuePair("longitude", longitude)); nameValuePairs.add(new BasicNameValuePair("latitude", latitude)); nameValuePairs.add(new BasicNameValuePair("address", address)); nameValuePairs.add(new BasicNameValuePair("description", description)); nameValuePairs.add(new BasicNameValuePair("image", image)); request.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(request); hasil = request(response); }catch(Exception ex){ hasil = "Failed Connect to server!"; } return hasil; } catch (Exception ex) { //Exception handling } return serverResponseMessage+image; } public static String request(HttpResponse response){ String result = ""; try{

InputStream in = response.getEntity().getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); StringBuilder str = new StringBuilder(); String line = null; while((line = reader.readLine()) != null){ str.append(line + "\n"); } in.close(); result = str.toString(); }catch(Exception ex){ result = "Error"; } return result; } Then you can create some access php using that simple code. Have fun :D

8. Using Hardware Debugging


In another way to run this application and use your device is using Hardware Debugging, you can see this reference link for Debugging Hardware : http://developer.android.com/guide/developing/device.html You must register your device for debugging the code, if you don't you can't see and use the shake device in this application.When you succesfull registration your device into debugging installation in eclipse you can see this image when you debugging the code in eclipse :

Now you can debugging this application with your device.

9. Compiling Application
When you have finished doing some modification to this application, now you can compile it in .apk so that you can install it to Android device or upload it to the market. To do this thing, you need to change debug API key with release API key first. Then, right click on the application project in the Package Explorer and select Android Tools > Export Unsigned Application Package. Then specify the file location for the unsigned .apk. It should be save in the same location of your release keystore. After that, go to the location of release keystore and unsigned .apk through Command Prompt and type the following command. After that, go to the location of release keystore and unsigned .apk through Command Prompt and type the following command. jarsigner -verbose alias_name -keystore my-release-key.keystore my_application.apk

change my-release-key with your release keystore name, my_application with your unsigned .apk name, and alias_name with your alias. To verify that your .apk is signed, you can type a command like this. jarsigner -verify my_signed.apk Reference Links : Signing Your Applications http://developer.android.com/guide/publishing/app-signing.html

Thank You for Your Purchase

You might also like