Saturday, February 23, 2013

Android Maps API v2 API Key Generate

Android  Maps API v2 API Key Generate

Google introduced new Maps Android API v2.
Below  how to generate an API key in Maps Android API v2

What in API V2?
*Android API v2 they are using Vector tile so maps loading too fast even slower connection.
*Maps are encapsulated with map fragment class and its extension of android Fragment class
* Maps Now in 3D.
*Caching also improved so user can see without empty areas.

Google Developer Documentation

*NOTE: Android Maps API v2 not supporting in Emulator only supporting real device.

Getting Started Maps Android API v2

Step 1.
Before getting Google map key
First you have to generate Fingerprint SHA1 digital signatures.
Let see how to do...

Get your keystore file and GOTO cmd prompt

C:\Program Files\Java\jre7\bin>keytool.exe -list -v -alias androiddebugkey -keys
tore "D:\debug.keystore" -storepass android -keypass android




Then you will fingerprint SHA1 Value .Check the below screen shot.



Step 2

Go to this Below Link
Google API Console https://code.google.com/apis/console/ 

There you can able to see like below image. Select API Access


 Step 3

Go to the bottom of  the Page
There you can able to see like below screen shot  and select create a new android key

 
Step 4.

If you select the create new android key. Then one popup will appear like below the screenshot.

Step 5.
Successfully Google API key generated

Check the below screen shot


Step 6:
Configure you MAP API Key to your project

Main.xml


fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     class="com.google.android.gms.maps.MapFragment"
    >


</fragment>



Manifest file



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.whatsaround.whatsaround"
    android:versionCode="1"
    android:versionName="1.0" >
     
          <permission
    android:name="com.whatsaround.whatsaround.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"/>

  <uses-permission android:name="com.whatsaround.whatsaround.permission.MAPS_RECEIVE"/>
       
         <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />
      
<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"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
         <meta-data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="HERE YOUR API KEY"/>
        <activity
            android:name="com.whatsaround.whatsaround.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


*Note Map V2 not supported in emulator so please check in real device

Sunday, February 17, 2013

Android Activity method from the adapter class



Android Activity method from the adapter class


Below the example for how to call activity method from adapter class.

Some time I try to call activity method from base adapter or adapter class but I unable to call this method or I am getting some error. So finally I got the solution .
Below the code
Create Interface Class 


public interface RefreshInterface {
public void refresh();
}

Then implement this interface to your activity class.


@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

MyArrayAdapter myAdapter = new MyArrayAdapter(getApplicationContext(), R.layout.appsview_item, List, new RefreshInterface () {
                 
                  @Override
                  public void refresh() {
                        
          //do something here
                       
                  }
            });  
}
 
Call activity method from adapter class

public class MyArrayAdapterextends ArrayAdapter<Structure> {
 

RefreshInterface intr;
public MyArrayAdapter(Context context, int textViewResourceId,
                  List<App> objects, RefreshInterface refreshInt) {
            super(context, textViewResourceId, objects);
           
            intr = refreshInt;
      
}

public View getView(final int position, View appView, ViewGroup parent) {

//this is your activity method

intr.refresh();


}
}

Check out this may be help you

Related Posts Plugin for WordPress, Blogger...