Well, hey all !
So having a less than a friendly start with Android Google Maps API v2 developpement, I thought I could gain some wisdom by posting on the result of my trial and get some feedback, hopefully you'll be able and genereous enough to give me some guidance.
So, here we go !
First, code of my Activity :
package com.example.ok;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
@SuppressLint("NewApi")
public class MainActivity extends Activity {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Second, code for the Manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ok"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.example.ok.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.example.ok.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library android:name="com.google.android.gms.maps" />
<activity
android:name="com.example.ok.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="I Got it and I had to change debug keystore for it and ... long story but I really think it's a good apikey" />
</application>
</manifest>
Third, code for the layout XML :
<RelativeLayout 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"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
So as you would notice, nothing more than a standard code for a beginner to start with and roll on to more and deeper stuff...Still, it doesn't work !
Now, having done my research, I've got to assess few eventual causes of my hardship, here's what I've come through :
1- Emulator does not generally deal with this, that's being the case since openGL es 2.0 is not well supported by these virtual machines yet,
2- apiKey is not good, in fact having tried to do the code with api v1 at first, I got into all sorts of problems because of it (deprecated..), I now shifted into coding with v2, I've deleted debug keystore file and then rebuild on eclipse, got a new one and then used the SHA-1 code with the package name to generate new apiKey code on Google Console... So I don't think this is the source of the evil for me,
3- tried a device, I've downloaded few demos of openGL es 2.0 and it's doing fine, so must not be openGL (but who knows ?). When I try to install the apk, it at declare that the application must have permission to use internat and location data and such, I click on install but... Sorry, "Application is not installed" !
4- I've brought into my project libraries the necessary stuff, meaning : android-support-v4.jar and google-play-services.jar amongst others...
5-made sure the project build target is google apis 17 (compatible with a 4.2 platform, while writing this I've noticed that my device is on a 4.0.2 Android version, could that be it ?).
So, that was long, hope you could still find it in you to indicate whatever potential solution might be usefull in my case.
Thanks in advance !
Here I add the last (and repeated part) of my logcat, only took the error :
04-11 17:11:15.289: E/StrictMode(700): null
04-11 17:11:15.289: E/StrictMode(700): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d195d0 that was originally bound here
04-11 17:11:15.289: E/StrictMode(700): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
04-11 17:11:15.289: E/StrictMode(700): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
04-11 17:11:15.289: E/StrictMode(700): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
04-11 17:11:15.289: E/StrictMode(700): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
04-11 17:11:15.289: E/StrictMode(700): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
04-11 17:11:15.289: E/StrictMode(700): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
04-11 17:11:15.289: E/StrictMode(700): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
04-11 17:11:15.289: E/StrictMode(700): at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
04-11 17:11:15.289: E/StrictMode(700): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
04-11 17:11:15.289: E/StrictMode(700): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
04-11 17:11:15.289: E/StrictMode(700): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
04-11 17:11:15.289: E/StrictMode(700): at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-11 17:11:15.289: E/StrictMode(700): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
04-11 17:11:15.289: E/StrictMode(700): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
04-11 17:11:15.289: E/StrictMode(700): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
04-11 17:11:15.289: E/StrictMode(700): at java.lang.Thread.run(Thread.java:856)