Friday 28 December 2012

How To Create an App for google map v2 in android

Hello Friends,
Today we will going to learn to how to create a map in android for google  maps V2 .
But before that, i would like to tell you that google had deprecated their google map v1 from 3rd december 2012 onwards.It means that we unable create map api key for google map v1.(It will fully removed from 3rd march 2013) for more info: check following link

Google map V1 is deprecated :

Google Map api V2 is good thing to interact with new level of google's new map beby... :)

they provide good documentation to develop your new map app which is based on google map v2 api.  

Above link contain good stuff to create your android app which is based on map v2.

I would like to share my experience, how i play with google maps v2 for android as follows

1) I create a project in ecilpse with name of MyMap.

2) then i downloded google play services by using sdk manager.I hope you are aware of it how to download google play service ??? 
if not,then refer image below 




 After Dowloading completes,These packages get stored in yours android sdk-windows/extras/google folder.we have to use these folder in our project as library so we can use google play services features in our app.

3) In ecilpse i click on file->Import->Android->Existing Android Code into workspace & I Browse my downloaded  google play service folder which is in android-sdk-windows/.extras/google.

4) Or in simple way,I copied these google play services folder into my project MyMap folder's lib folder, & in property i change my compiler level 1.6 & attached library of google play service.

5) now the actual role comes here, as for obtaining mapv1 api key we used sha1 key samely we working for map v2. as follows

use cmd & find your sha1 key, for more info refer these

     After that open Google APIs Console then make it on Google Maps Android V2 in services.
    Click on, API Access-> Create new Android Key & create your api key using SHA-1 fingerprint & your desirable(here,my package name is com.examples.mymap) For more info check below


6) now lets move with the code,
then i use some permissions in my Android Manifest.xml  such as ,below

 <permission
        android:name="com.examples.mymap.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.examples.mymap.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />



 & in side <application> tag & in the end of <activity> tag i used 
<meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyDphuv0Qi43bgLM8TkYxCoUMr4MEcNIWLo" />


7)Inside activity_main.xml i used ,

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <Button
            android:id="@+id/droppin"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Drop Pin" />

        <Button
            android:id="@+id/pinremove"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="remove pin" />
    </LinearLayout>

</fragment>


   8)In MainAcitivity.java i added few lines of code as below,


package com.examples.mymap;

import android.content.Context;
import android.graphics.Point;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Display;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener;
import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
import com.google.android.gms.maps.GoogleMap.OnMarkerClickListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.maps.MapController;

public class MainActivity extends android.support.v4.app.FragmentActivity
implements OnMapClickListener, LocationListener, OnMarkerClickListener,
OnClickListener {
GoogleMap mmap;
LocationManager locationManager;
String provider;
Location location;
double latitude, longitude;
LatLng latLng;
Marker marker;
TextView mTapTextView;
Button Pinremove, Droppin;
MapController mvcontroller;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
provider = LocationManager.NETWORK_PROVIDER;
locationManager.requestLocationUpdates(provider, 0, 0,
MainActivity.this);
GooglePlayServicesUtil
.isGooglePlayServicesAvailable(getApplicationContext());
setContentView(R.layout.activity_main);
setUpMapIfNeeded();
Pinremove = (Button) findViewById(R.id.pinremove);
Pinremove.setOnClickListener(this);
Droppin = (Button) findViewById(R.id.droppin);
Droppin.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

Display display = getWindowManager().getDefaultDisplay();

int width = display.getWidth();
int height = display.getHeight();
Point point = new Point(width / 2, height / 2);
LatLng latLng = mmap.getProjection().fromScreenLocation(point);
System.out.println("++++++++++++++++" + width / 2 + "+++ "
+ height / 2);
marker = mmap.addMarker(new MarkerOptions().position(latLng)
.title("").snippet("").draggable(true));
marker.getPosition();
marker.showInfoWindow();

}
});

}

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
locationManager.removeUpdates(MainActivity.this);
}

@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}

private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the
// map.
if (mmap == null) {
// Try to obtain the map from the SupportMapFragment.
mmap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();

// Check if we were successful in obtaining the map.
if (mmap != null) {
setUpMap();

}
}
}

private void setUpMap() {

mmap.setOnMapClickListener(this);
mmap.setMyLocationEnabled(true);

mmap.getMyLocation();

// mmap.getMyLocation();
mmap.setOnMarkerClickListener(this);
mmap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

@Override
public void onInfoWindowClick(Marker arg0) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),
"You clicked on InfoWindow ...", Toast.LENGTH_LONG)
.show();

}

});

}

@Override
public void onMapClick(LatLng arg0) {
// TODO Auto-generated method stub

}

@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
latitude = location.getLatitude();
longitude = location.getLongitude();
}

@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub

}

@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub

}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub

}

@Override
public boolean onMarkerClick(Marker marker) {
// TODO Auto-generated method stub

marker.getPosition();
marker.showInfoWindow();

marker.setTitle("Longitude=" + marker.getPosition().longitude);
marker.setSnippet("Latitude=" + marker.getPosition().latitude);

return true;
}

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

// marker.remove();
mmap.clear();

}

}



9) & output will looks like, 


  output window-1 

            

                            output window-2                                          output window-3

                            
                         
                           output window-4                                 output window-5            


                                 

                                          output window-6 
     

                                 

                                            output window-7

10) Happy Coding,Enjoy :)


Monday 24 December 2012

The Android related useful words & concepts

If you're new to Android, you are likely seeing a lot of unfamiliar words being thrown about... from CID to RUU to ROM. This dictionary will help you understand what these words actually mean, and when you would expect to see them.


**********************************************************
ADB
ADB (Android Debug Bridge) is a PC command-line tool included with the Google Android SDK.  ADB provides an interface for managing and debugging a USB connected Android device. Common ADB tasks include: *Collecting a log via logcat* Installing APK packages* Pushing or pulling files* Accessing the device shell.
For additional details about ADB please see the ADB guide.
**********************************************************
APK
An APK is an Android application package (Android Package). It is commonly used to store an app, or program run on the device. These files are essentially zip files, in that they contain other files which make up the program. They can be obtained through various methods, such as installing an app through the market, downloading from a website, or creating yourself in Java. If you have an apk file on your computer, and wish to install it on your phone, you can run the command 'adb install apkname.apk' to copy the file over USB to your phone. 
The APK files reside on the phone in the directory /data/app/filename.apk. This directory is not normally accessible unless a #root|rooted ROM is used on the phone, in order to protect paid-for applications. On a rooted ROM, it is possible to copy applications manually into this folder using the command 'adb push' or similar. Once a file is in the /data/app directory, it is installed on the phone. There is not normally an installation process for apps on Android.
It is also possible to install an app to the system partition of a rooted phone. This has the added benefit that the application cannot be uninstalled from the device, making it useful for security/anti-theft applications such as WaveSecure and MobileDefense. These [[#system]] applications are stored in /system/app. The applications in this folder are normally part of the Android operating system, and should not be modified or deleted unless you either put the file there yourself, or know what you are doing.
APK files can be uninstalled using the market application (if the application was installed from the market), the 'adb uninstall apkname.apk' command, the Settings | Applications | Manage Applications menu, or by manually removing the files from the /data/app directory as a last resort. Normally, the preferred method is through the market or applications menu.
**********************************************************
Bart
Bart is used from Recovery to backup your phone or to restore a backup.This basically creates an exact copy of your phone (Sdcard + Sd-Ext excluded, unless it says it will backup SD-Ext), which later can be restored with no losses in data.

**********************************************************
Boot
In contrast to other linux-based operating systems, Android has a boot partition (containing the contents of a boot.img file), as opposed to a direct booting system. This partition contains a read-only 'ramdisk', and a couple of other files. The ramdisk contains files critical to booting, such as init.rc and default.prop. This 'partition' actually sets up the directory structure of the device, having empty folders for /data, /dev, /proc, /sbin, /sys and /system.

**********************************************************
Bootloader
The bootloader, or HBOOT, is firmware on the phone which runs on every startup. 
Since the bootloader controls access to Fastboot, it can be desirable to change the version of the bootloader on a phone. The current version of the bootloader can be viewed by entering bootloader mode. To do so, turn on the phone with the back button held down. Release the back button after about 1 second. The version information will be displayed at the top of the screen next to the word HBOOT, and will appear in the form 'V1.76.0004' or similar.
From within the bootloader, Fastboot can be used to execute an img file stored on your PC or flash an img file to the device.
If your device has HBOOT version 1.73.007, it is no longer possible to use Fastboot, so it is often desirable to downgrade the HBOOT using the Goldcard method in order to get the 1.73.004 version, which is Security-Off, allowing Fastboot.

**********************************************************
CID
The Carrier ID is a number embedded in your Phone's SPL that identifies what if your phone is a network branded Hero. For example, T-Mobile UK phones have a different CID to generic HTC phones. The CID prevents you from [[#Flash|flashing]] an 'incorrect' [[#RUU]] to your phone. Note that the RUUs will all function on any of the phones, but the CID locking prevents you from 'debranding' your phone by installing a generic [[#RUU]]. Additionally, the CID-related software also prevents you from installing an older RUU than what you are currently running.
It is possible to bypass the CID check on an [[#RUU]] using a [[#Goldcard]]. This pretends your phone has the 'Super-CID', which allows any branding of ROM to be installed, and allows you to downgrade the software on your phone.

**********************************************************
Data
The data partition on the device contains the user-related data, such as installed applications and settings for those apps, as well as your SQLite database containing Android settings and messages. Normally, the directory /data/app is off-limits through the 'adb shell' command, as well as other terminal applications that can run on the device, since this directory contains the apk files for apps. On a rooted phone, using the [[#su]] command will allow full access to this partition. This partition can be flashed using Fastboot or Nandroid.
**********************************************************
Ext
Ext is an abbreviation of the extended filesystem, one of the filesystems supported by Android and other Linux based systems.  An ext filesystem partition is required for using Apps2SD or Dalvik2sd.
**********************************************************
Fastboot
Fastboot is a means to execute or Flash an img file on your device. First, set up your PC for ADB, and ensure that it works correctly. After putting your phone into Bootloader mode, and selecting Fastboot by pressing back (if you let go of the back key early), the device awaits a command via USB. 
On your computer, execute the command 'fastboot devices', which should display your device serial number. This confirms you are ready to use Fastboot. To execute (ie. run without changing your system) and img file, type the command 'fastboot boot imagename.img'. This command allows you to run a custom recovery image without flashing it to the device. 
If you wish to flash an img file to the device, the command 'fastboot flash IMGTYPE imgtype.img' should be used. Note that IMGTYPE should be replaced by the type of img file you are flashing. For example, to flash a recovery image, the command 'fastboot flash recovery patched_recovery.img' should be used. The following are valid types of image to flash; boot, recovery, system, 
**********************************************************
Flash
Flashing is the process of writing data to the internal memory on your phone. Normally, you would flash a [[#ROM]] image to the phone, which would give you a different version of system software on your phone. Flashing can also refer to updating/writing to any of the other parts of the phone, such as the SPL, Radio etc.
**********************************************************
Flash Memory
Flash memory, also known as NAND memory, is nonvolatile - keeping information even when the device is off. Flash memory in the device is equivalent to the hard drive in a computer. This is where the device's operating system (sometimes called firmware) and applications are stored. Flash memory is slower than RAM, but is (almost always) faster than SD cards.
**********************************************************
Flashrec
Flashrec is an application/tool you use to flash the recovery image to your phone. (Found on http://zenthought.org/content/project/flashrec)All current firmwares are patched so you can not use flashrec on these, you will receive the error message "Could not run command"Most 1.5 (cupcake) firmwares can still use this, but some has been patched already.The current version is 1.1.3 and was updated 2009-08-16.Note: Do not flash cyanogen's theme templates after you have started the installed recovery image, this will brick your phone!

**********************************************************
Goldcard
A goldcard is the name given to a specially modified microSD memory card for your phone that allows you to install software to your phone that is in an RUU file, but not from the same network provider as your phone is from. It does this by bypassing the CID check of the RUU update. Additionally, the goldcard allows you to install an earlier version of system software onto your phone than what is already on it (called downgrading). This can make it easier to root a phone and install a custom ROM on it, if the software installed on it at present cannot easily be rooted.

**********************************************************
HBOOT
See Bootloader.
**********************************************************
logcat
Using adb (see ADB), type in "adb logcat >logcat.txt". This will help us when resolving issues and bugs.There is also a tool in the market you can use for this, called aLogcat. It can show different categories (severity of errors ect.) too, adb logcat can not do this.

**********************************************************
Market
The market on Android is a place where you can purchase or download applications for your phone in the [[#APK]] format. When you download through the market, the installation process is transparent (as in you don't have to deal with the APK files yourself), and there is the facility to rate apps and post comments which are visible to other users. Frequently, the developers of apps actually take onboard the feedback in the comments (mainly the smaller apps with slightly less feedback to sift through).
When an app is installed from the market, it is copied to '/data/app/apkname.apk', as the act of 'installing'. An app can store its data in the folder '/data/data/apkname'. It is possible to clear the data stored by an application by using the Manage Applications feature in Settings | Applications | Manage Applications.

**********************************************************
Nand
See Flash Memory.

**********************************************************
Nandroid
Nandroid is used to backup or restore backups from Recovery.You can chose to either do a regular backup (Phone only) or a backup + sd-ext (Phone + Apps2sd ext.)Both will backup your whole system, the second will include apps saved on your sdcard's sd-ext.

**********************************************************
Radio
The Radio on a Hero is the part of the phone that deals with mobile connections. It handles talking to the GSM/3G network, Bluetooth, WiFi and GPS. The radio contains software that controls how it operates, and newer versions of radio firmware are made available from time to time in [[#RUU]] updates. These updates are transparent to the user, although users who elect to install custom software can update their radio using an update.zip file made available by members of the modding community. 
Flashing the radio is potentially risky, and you should NEVER pull the battery out of a phone that is [[#Flash|flashing]] the radio. If you do so, it is possible your phone will be bricked. Nevertheless, it can give improved battery life, signal strength and data performance, so is often done by users moving to later versions of ROMs.
Care should be taken to only flash the correct type of radio to a phone. NEVER attempt to flash a CDMA phone with a GSM radio or vice-versa. It is likely you will brick the phone if you attempt to do so.

**********************************************************
ROM
ROM is literally "read-only memory" but it's usage has changed over time.  Today ROM can refer to the non-volatile area of a device's flash memory on which read-only data resides or the packed image to be written to that flash area.

**********************************************************
Root
Root is the name of the highest level superuser (su) on Unix-like systems such as Android.  The root user, and applications run by the root user, have administrative access to protected files and services which makes it dangerous for normal daily use.
A 'rooted' device one which has been hacked to provide privilege escalation from a standard user to superuser.  Rooting a device is usually the first step in installing cooked ROMs.
**********************************************************
RUU
An RUU is a ROM Upgrade Utility, which is a Windows executable (exe) file that upgrades the software on your phone. Using the USB connection with the phone, the RUU communicates with the phone's SPL, checking the CID of the device to ensure the user is not installing the ROM on a network branded device (since the networks release their own RRUs with customisations and branding). The RUU is capable of flashing almost everything on the phone, including System, Data, Recovery, HBOOT and Boot. As such, an RUU is a good way to return your phone to the way it came out the box if a warranty repair is needed (be aware that using a new RUU could make it difficult, or even prevent you from rooting the phone in future. It is normally better to upgrade using update.zip files to prevent this, as they do not update the HBOOT to prevent Fastboot in future. 
**********************************************************
S-OFF/S-ON
This refers to an unlocked/locked NAND drive. HTC lock the NAND on some phones to prevent writing to the /system. S-OFF can generally be obtained by an exploit, by flashing an engineering SPL, or by using an XTC Clip. 
**********************************************************
SPL
The Secondary Program Loader is a piece of bootcode that initiates the startup of the phone, displaying the initial splashscreen for the device, and loading the initial files from ROM.
It checks to see if a button combination is pressed on bootup (such as that to enter Recovery Mode or the bootloader ), and loads the relevant system software. If no special instruction is given by holding keys, the bootloader loads the normal system software by initialising the boot process from the boot partition.
Flashing your SPL is risky, as the process failing will probably result in a broken, or bricked phone, since the SPL is executed very early on in the boot process, and any error here will prevent access to the recovery or bootloader features.
If you do flash the SPL though, it unlocks the Carrier-ID CID from the device, essentially allowing any RUU to be installed to the device, and allows flashing alternative or custom bootscreens.
**********************************************************
Stock
The term stock is often used to refer to a file or part of the software which is unmodified or untouched by developers. For example, a stock ROM would be one which was produced by HTC and which had not been modified or rooted by someone. The term is often used when comparing performance of different ROMs, as a way to refer to the phone as it came out the box.
**********************************************************
su
su (substitute user) is a Linux command which, when run without a username parameter, gives the user full 'root' permissions. By default, this command binary (ie. Linux equivalent of an executable file) is not included on Android systems, but the process of "rooting" a phone copies this file to the '/system/bin/' directory thereby enabling the command. Since root privileges can be abused by malicious applications it's highly recommended to install an app to grant and manage access to su, similar to UAC on Windows. VillainROM includes the app called "Superuser" for this.
**********************************************************
System
The /system directory on your device is where the main operational software for the Android OS is stored.  It has a number of sub-direcories of which /system/apps (where application apk's are stored) is probably the only one users would have need to access.  The /system folder is read-only by default and needs remounted via 'adb' to allow write access.
**********************************************************
Recovery
The recovery partition is a boot-mode for your phone that allows you to wipe your settings from the Data partition of the phone (a hard wipe), or perform an update using an update.zip file on the root of the microSD card. It is common (although not necessary) to flash a patched Recovery image, such as Amon RA's one. This allows you to run Nandroid backup from the device, and flash modifications, such as [[#update.zip]] files to the device, essentially becoming a means to install sotware to the device. Recovery mode is separate from 'normal' mode, and can be entered by holding down home whilst turning the phone on. 
**********************************************************
update.zip
An update.zip (does not have to actually be called update.zip if you have a patched Recovery image) is a file containing some files which will be copied to the phone's internal memory. Normally, a new system update or ROM is stored in the file, but update.zip files are commonly used to install modifications such as themes or applications that are installed on the System partition to prevent uninstallation. 
To flash one of these files, which commonly would contain a custom ROM for your phone, you would boot your phone to a patched recovery image (whether using Fastboot, or the home+power method if you have a patched Recovery image flashed on your phone)
Update.zip files are cryptographically signed, and more information on how to sign your own files can be found online.

**********************************************************
WWE
Stands for World Wide English version of the ROM. There can be local versions of ROMs too. For example VR10 is based on the Taiwan version, VR12 on the WWE one.  Interestingly, WWE excludes the English (US) locale.