Google Maps API v2 Android Studio Map not loading - android

Please keep in mind that I have read through the hundreds of similar questions such as this but I've seemed to cross off the check list of everything that has been stated in the instructions on how to get the Google maps to start working.
First things first, I'll show my code, then I'll narrate what has been happening.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="elephant.tuskapp"
android:versionCode="49"
android:versionName="4.6">
<uses-sdk android:minSdkVersion="15"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<permission android:name="elephant.tuskapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="elephant.tuskapp.permission.MAPS_RECEIVE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_GPS"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<permission android:name="elephant.tuskapp.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
<uses-permission android:name="elephant.tuskapp.permission.C2D_MESSAGE"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:name=".NVtuskapplication"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".activity.MainActivity"
android:label="#string/activity_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<receiver android:name="elephant.tuskapp.service.AlarmReceiver"></receiver>
<receiver android:name="elephant.tuskapp.service.TimeSynchronizer">
<intent-filter>
<action android:name="android.intent.action.ACTION_TIME_CHANGED"/>
<action android:name="android.intent.action.TIMEZONE_CHANGED"/>
</intent-filter>
</receiver>
<service android:name=".service.GPSService"></service>
<service android:name=".service.RouteUpdateService"></service>
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
<receiver
android:name=".service.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="elephant.tuskapp"/>
</intent-filter>
</receiver>
<service android:name=".service.GcmIntentService"/>
<meta-data
android:name="io.fabric.ApiKey"
android:value="key" />
<!-- google maps api v2-->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="key"/>
</application>
Layout XML
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
Main Activity
package elephant.tuskapp.activity;
import android.app.Activity;
import android.os.Bundle;
import elephant.tuskapp.R;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.route_details);
}
}
When I run my app, I see a blank canvas with the Google logo on the bottom left corner. The Logcat prints out the following error:
-22 20:47:24.822 22720-22720/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: free.elephant.tuskapp, PID: 22720
java.lang.RuntimeException: Unable to start activity ComponentInfo{free.elephant.tuskapp/elephant.tuskapp.activity.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2301)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2361)
at android.app.ActivityThread.access$800(ActivityThread.java:147)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5232)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:767)
at android.view.LayoutInflater.inflate(LayoutInflater.java:486)
at android.view.LayoutInflater.inflate(LayoutInflater.java:418)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
at android.app.Activity.setContentView(Activity.java:2161)
at elephant.tuskapp.activity.MainActivity.onCreate(MainActivity.java:18)
at android.app.Activity.performCreate(Activity.java:5984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2254)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2361)
  at android.app.ActivityThread.access$800(ActivityThread.java:147)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:135)
  at android.app.ActivityThread.main(ActivityThread.java:5232)
  at java.lang.reflect.Method.invoke(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Caused by: java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
at com.google.maps.api.android.lib6.d.fk.a(Unknown Source)
at com.google.maps.api.android.lib6.a.g.a(Unknown Source)
at com.google.android.gms.maps.internal.CreatorImpl.b(Unknown Source)
at com.google.android.gms.maps.internal.CreatorImpl.b(Unknown Source)
at com.google.android.gms.maps.internal.i.onTransact(SourceFile:62)
at android.os.Binder.transact(Binder.java:380)
at com.google.android.gms.maps.internal.zzc$zza$zza.zzr(Unknown Source)
at com.google.android.gms.maps.MapFragment$zzb.zzvu(Unknown Source)
at com.google.android.gms.maps.MapFragment$zzb.zza(Unknown Source)
at com.google.android.gms.dynamic.zza.zza(Unknown Source)
at com.google.android.gms.dynamic.zza.onInflate(Unknown Source)
at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2117)
at android.app.Activity.onCreateView(Activity.java:5333)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:737)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:486)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:418)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
  at android.app.Activity.setContentView(Activity.java:2161)
  at elephant.tuskapp.activity.MainActivity.onCreate(MainActivity.java:18)
  at android.app.Activity.performCreate(Activity.java:5984)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2254)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2361)
  at android.app.ActivityThread.access$800(ActivityThread.java:147)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:135)
  at android.app.ActivityThread.main(ActivityThread.java:5232)
  at java.lang.reflect.Method.invoke(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Familiar right? You see it in a lot of other questions. I think what differentiates my question from the others is I may have a problem with different flavors of my app.
To cross out the mistakes others have encountered, I have done the following:
- Made sure my api keys are inside the tag of the manifest file.
- Ensured that the Google Maps API v2 for Android is enabled on Google Consoles
- I'm using the Google Play Services via Gradle (Scroll down for my gradle snippet)
- I made sure all of the essential permissions are set
- I made sure to enable the glEsVersion.
What I think the problem is?
I think I'm having a problem with my "free.elephant.tuskapp" flavor to authenticate with googles servers. In my gradle build, I maintain two different flavors of my application and I seem to be getting an error with authentication:
Ensure that the "Google Maps Android API v2" is enabled.
Ensure that the following Android Key exists:
API Key: myAPIKEY
Android Application (<cert_fingerprint>;<package_name>): SHA-1;free.elephant.tuskapp
I obtained my API by using the 'elephant.tuskapp' package name rather than the 'free.elephant.tuskapp'
Here's my gradle build if it's of any help:
Gradle
buildscript {
repositories {
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven {
url 'https://maven.fabric.io/public'
}
}
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc2"
defaultConfig {
applicationId "elephant.tuskapp"
minSdkVersion 15
targetSdkVersion 15
}
productFlavors {
demo {
applicationId "demo.elephant.tuskapp"
}
free {
applicationId "free.elephant.tuskapp"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:7.5.0'
compile 'com.google.zxing:core:3.2.0'
compile('com.crashlytics.sdk.android:crashlytics:2.3.2#aar') {
transitive = true;
}
}
Am I missing out on something? Or does it really have something to do with my flavor builds? If it's the flavors causing trouble, how am I supposed to handle this? I generated new api keys for all my flavors but I don't see how I'm supposed to make that work within the manifest file as well as having it look elegant.

According to your logcat, it says something wrong with your Map fragment layout. Also, I find that there is nothing in your MainActivity, I think you should initial map there. For more details, you can refer code here.
Sample code:
public class MainActivity extends FragmentActivity {
GoogleMap mGoogleMap;
private static LatLng MountainView = new LatLng(37.42, -122.08);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initial Map
try {
if (mGoogleMap == null) {
mGoogleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
}
} catch (Exception e) {
e.printStackTrace();
}
mGoogleMap.getUiSettings().setMyLocationButtonEnabled(true);
mGoogleMap.getUiSettings().setZoomControlsEnabled(true);
mGoogleMap.getUiSettings().setZoomGesturesEnabled(true);
mGoogleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(MountainView, 15));
Marker marker = mGoogleMap.addMarker(new MarkerOptions()
.position(MountainView)
.title("Have a nice day!"));
}
}

Since my app has multiple flavors, I was getting thrown an error that my api-keys were not being validated. The way to resolve this is to ensure that you add all packages of your project into the Google Developer Console.
SHA1;packagename
Then press enter
SHA1;packagename2(flavor)
In my case it was:
SHA1;elephant.tuskapp
SHA1;free.elephant.tuskapp
SHA1;demo.elephant.tuskapp

Related

Errors with Google API in android application utilizing MapActivity

I've tried and tried and tried to figure this problem out. I've searched everywhere and I haven't found a solution yet. I understand that there are many forums on this topic, but none have helped me come up with a solution.
The problem I'm having is that when I run my android application, in the emulator, the area for the map comes up only with grey tiles. I've read online that the problem is most likely the Google API key, but I've tried multiples way to generate it (Used the Android Studio Terminal to obtain SHA1, I had Android studio generate a link to google so it can automatically create the key).
I'm hoping someone can help me out, I'm pretty desperate here!
Here's my Activity class
package com.bignerdranch.android.taskmanager;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
public class AddLocationMapActivity extends MapActivity {
public static final String ADDRESS_RESULT = "address";
#Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.add_location);
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
#Override
protected boolean isLocationDisplayed() {
return true;
}
}
This is the layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/location_title"
.../>
<EditText
android:id="#+id/task_address"
.../>
<Button
android:id="#+id/map_location_button"
.../>
<com.google.android.maps.MapView
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/map_location_button"
android:layout_above="#+id/use_this_location_button"
android:clickable="true"
android:apiKey="AIza.................................." />
<Button
android:id="#id/use_this_location_button"
.../>
</RelativeLayout>
Then, this is the manifest file:
?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bignerdranch.android.taskmanager">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<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" />
<application
android:name=".TaskManagerApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIza..........................." />
<activity android:name=".ViewTasksActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".AddTaskActivity"
android:text="#string/add_task"/>
<activity android:name=".AddLocationMapActivity"
android:text="#string/add_location_to_task"/>
<uses-library android:name="com.google.android.maps" />
</application>
</manifest>
Then the build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 'Google Inc.:Google APIs:24'
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.bignerdranch.android.taskmanager"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.android.gms:play-services-maps:10.0.1'
compile 'com.google.android.gms:play-services-location:10.0.1'
}
And lastly, this is what is generated by the Monitor:
12-02 22:37:10.351 22387-22537/com.bignerdranch.android.taskmanager W/System.err: IOException processing: 26
12-02 22:37:10.351 22387-22537/com.bignerdranch.android.taskmanager W/System.err: java.io.IOException: Server returned: 3
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at java.lang.Thread.run(Thread.java:818)
I WOULD BE FOREVER GRATEFUL TO THE PERSON WHO CAN HELP ME FIGURE THIS PROBLEM OUT!
Grey tiles instead of map
The map that you're using com.google.android.maps.MapView is a v1 of Google Map API. Unfortunately, it is officially deprecated.
You should use the new version of Google Maps API which is Version 2
Here's a tutorial for Google Map V2

Cannot get my location using the emulataor

I am trying to develop a Google Map application.
The demo application works fine on a real device but fails on the emulator.
the logcat output is as follows:
java.lang.RuntimeException: Unable to start activity ComponentInfo{il.co.talkie.mapdemo/il.co.talkie.mapdemo.MapDemoActivity}: java.lang.SecurityException: "passive" location provider requires ACCESS_FINE_LOCATION permission.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.SecurityException: "passive" location provider requires ACCESS_FINE_LOCATION permission.
at android.os.Parcel.readException(Parcel.java:1599)
at android.os.Parcel.readException(Parcel.java:1552)
at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:606)
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:880)
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:464)
at il.co.talkie.mapdemo.MapDemoActivity.getMyLocation(MapDemoActivity.java:170)
at il.co.talkie.mapdemo.MapDemoActivity.onCreate(MapDemoActivity.java:106)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Line 170 of MapDemoActivity is
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0,0, this);
The manifest file has these permissions (otherwise it will not work on a real device) as can be seen here:
Manifest.XML
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="il.co.talkie.mapdemo" >
<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" />
<permission
android:name="com.javapapers.currentlocationinmap.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="#string/google_maps_key" />
<activity
android:name=".MapDemoActivity"
android:label="#string/title_activity_map_demo" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I would like to use the emulator to get my location - it displays the google map and it finds locations of addresses I provide, but it refuses to get my location - so I can not calculate distances properly.
What is wrong?
The emulator I use was created for API 23 and target Google API.
Any help will be welcomed.
If you are using emulator on Android M , you will need to request permission from user despite your manifest. See
ACCESS_FINE_LOCATION permission error emulator only
Android M Google API's to use Google Maps and other permissions
You may check out articles / tutorials e.g. this to work with the new system or just target a lower API <= 22
Error is occuring because of this problem:
Caused by: java.lang.SecurityException: "passive" location provider requires ACCESS_FINE_LOCATION permission.
Just add a new permission to your app manifest:
uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

Why my map app crashes if I set maxSdkVersion in the WRITE_EXTERNAL_STORAGE permission?

I've set my map following the instructions in this link. And set the WRITE_EXTERNAL_STORAGE permission in accordance with the recomended by the Official Android Documentation, that is request this permission only for API level 18 and lower. So, I have this manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<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" >
<uses-library android:name="com.google.android.maps"/>
<activity
android:name=".activities.HomeActivity" >
<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.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="#string/map_api_key"/>
</application>
</manifest>
But I am facing this error:
Caused by: java.lang.SecurityException: The Maps API requires the additional following
permissions to be set in the AndroidManifest.xml to ensure a correct behavior:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
But, as it is showed in my manifest, I have this permission. One detail is if I put only the WRITE_EXTERNAL_STORAGE permission, without specifying the maxSdkVersion value, the app works properly.
Is this an Android bug or am I forgetting something in my app configuration?
UPDATE 1
This is the logcat:
FATAL EXCEPTION: main
Process: com.example.map, PID: 15534
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.map/com.example.map.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
at android.app.Activity.setContentView(Activity.java:1929)
at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:216)
at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:76)
at com.example.map.MainActivity.onCreate(MainActivity.java:16)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
... 11 more
Caused by: java.lang.SecurityException: The Maps API requires the additional following permissions to be set in the AndroidManifest.xml to ensure a correct behavior:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
at maps.e.ci.a(Unknown Source)
at maps.e.ay.a(Unknown Source)
at maps.e.ay.a(Unknown Source)
at maps.e.al.a(Unknown Source)
at maps.e.bh.a(Unknown Source)
at maps.e.bg.a(Unknown Source)
at etu.onTransact(SourceFile:107)
at android.os.Binder.transact(Binder.java:361)
at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment$a.onCreateView(Unknown Source)
at com.google.android.gms.dynamic.a$4.b(Unknown Source)
at com.google.android.gms.dynamic.a.a(Unknown Source)
at com.google.android.gms.dynamic.a.onCreateView(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1093)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1195)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:291)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
UPDATE 2
My layout:
<fragment
android:id="#+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
class="com.google.android.gms.maps.SupportMapFragment" />
UPDATE 3
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
If you check the link you've provided to the <uses-permission> documentation, you'll see that it states that:
it's no longer necessary for your app to request the WRITE_EXTERNAL_STORAGE permission when your app wants to write to its own application-specific directories on external storage (the directories provided by getExternalFilesDir()).
It would appear that the Maps API needs write access to other directories. And if you check the Specify permissions section of the other link you gave, it still lists the WRITE_EXTERNAL_STORAGE permission as required, with no mention of exception for API Level 19.
After having checked many, many online resources with regard to the Maps API, Android API Level 19, and the restriction of the WRITE_EXTERNAL_STORAGE permission, I found no source or example that listed or referenced a working example using the Maps API with that permission restricted to API Level 18 and below. Again, I quote the link you've provided that says the permission is not needed in API Level 19 "when your app wants to write to its own application-specific directories on external storage". (I would point out that it merely says it is not necessary in that case, and in no way "recommends" that you set this restriction absolutely.) The Maps API needs write-permission to external storage directories that are not owned by your app. The fact that "without specifying the maxSdkVersion value, the app works properly" indicates that even in KitKat, Maps needs that permission. The error is telling you exactly that.
I did some research around the maxSdkVersion. And I found the following
From google
http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
Warning: Declaring this attribute is not recommended. First, there is no need to set the attribute as means of blocking deployment of your application onto new versions of the Android platform as they are released. By design, new versions of the platform are fully backward-compatible. Your application should work properly on new versions, provided it uses only standard APIs and follows development best practices. Second, note that in some cases, declaring the attribute can result in your application being removed from users' devices after a system update to a higher API Level. Most devices on which your application is likely to be installed will receive periodic system updates over the air, so you should consider their effect on your application before setting this attribute.
I have something like this in my current working google app
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<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" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
So if you really want, you can try put that maxSdkVersion in the note, unless its what google is documented in the above link.
Hope this help
The XML code provided in the link is for Android API 12 or later.
Since your minSDKVersion is 8. Use this:
<fragment
android:id="#+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
class="com.google.android.gms.maps.SupportMapFragment" />
Check here for more.

issue with meta data in android studio

Hi guys I've already try all the tutorials found here and in the developers site and I can't mannage to find the answer to my issue... ok I'm trying to make a simple app that render a map using gmaps... so I had already download the proper libreries... and in my build.gradle I compile them... so first let me show you my code...
this is my manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.solmoviles.gpsmovil"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<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"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<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" >
<activity
android:name="com.solmoviles.gpsmovil.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.gms.version"
android:value="#integer/google_play_services_version" />
</application>
and here you have my build.gradle
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:4.0.30'
compile 'com.android.support:appcompat-v7:18.0.0'
}
and finaly here you have my logcat error
12-26 17:06:21.629 32452-32452/com.solmoviles.gpsmovil E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.solmoviles.gpsmovil/com.solmoviles.gpsmovil.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2088)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2113)
at android.app.ActivityThread.access$700(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1224)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4918)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
at maps.af.ay.a(Unknown Source)
at maps.af.ay.a(Unknown Source)
at maps.af.al.a(Unknown Source)
at maps.af.be.a(Unknown Source)
at maps.af.bd.a(Unknown Source)
at cmj.onTransact(SourceFile:107)
at android.os.Binder.transact(Binder.java:326)
at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment$a.onCreateView(Unknown Source)
at com.google.android.gms.dynamic.a$4.b(Unknown Source)
at com.google.android.gms.dynamic.a.a(Unknown Source)
at com.google.android.gms.dynamic.a.onCreateView(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:900)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1184)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:291)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
          
so When I change the format of the meta data to the suggested one... it throws an error that says it was expecting a value of 4050300 and viceverse... PLEASE HELP ME...
after applying the suggestion Emmanuel provide me I have this
here you have the manifest as the way you suggested...
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.solmoviles.gpsmovil.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="AIzaSyxxxxxxxxxxxxxxxxxxxxxx7Wb8"/>
</application>
for security reasons I put the x on the api key... and the logcat is showing this
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.solmoviles.gpsmovil/com.solmoviles.gpsmovil.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2088)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2113)
at android.app.ActivityThread.access$700(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1224)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4918)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4030500 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
at com.google.android.gms.maps.internal.q.v(Unknown Source)
at com.google.android.gms.maps.internal.q.u(Unknown Source)
at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment$b.cE(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
at com.google.android.gms.dynamic.a.a(Unknown Source)
at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
You have to have both meta-data's - play services version AND map API key, so you manifest would look like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.solmoviles.gpsmovil"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<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"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<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" >
<activity
android:name="com.solmoviles.gpsmovil.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.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="your_api_key"/>
</application>
Like the Exception says, you are missing your API Key. You should have a structure like this on your AndroidManifest.xml just before the closing </application> tag:
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API_KEY"/>

Google Maps api v2 not working and closes unexpectedly

Im almost just a beginner in android. I was trying to make a very simple app with google maps, ie just displaying maps. I followed the following link:
file:///C:/Android/Android%20Google%20Maps%20V2%20Tutorial.htm
But when I test it on my device it says it has stopped working and closes.
Here is my Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googleapi"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<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" >
<activity
android:name="com.example.googleapi.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="AIzaSyA5BsIL-3rppsOxQOuX4gBZT3c0cTHNbWc" />
</application>
</manifest>
Acyivity code is: (I tried extending FragementActivity but dosent work with it too.)
package com.example.googleapi;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.Toast;
public class MainActivity extends FragmentActivity {
// Google Map
private GoogleMap googleMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* function to load map. If map is not created it will create it for you
* */
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
#Override
protected void onResume() {
super.onResume();
initilizeMap();
}
}
and XML code is( some part of it):
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
My logcat is:
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.app.Activity.setContentView(Activity.java:1929)
at com.example.googleapi.MainActivity.onCreate(MainActivity.java:20)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml
does not have the right value. Expected 4030500 but found 0.
You must have the following declaration within the <application> element:
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
at com.google.android.gms.maps.internal.q.v(Unknown Source)
at com.google.android.gms.maps.internal.q.u(Unknown Source)
at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
at com.google.android.gms.maps.MapFragment$b.cE(Unknown Source)
at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
at com.google.android.gms.dynamic.a.a(Unknown Source)
at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
at android.app.Activity.onCreateView(Activity.java:4785)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
... 21 more
I have googled a lot about it and got some direct questions on it but no answer ?? .
It seems many have the same problem.Can anyone help with this problem. I want to develop an app but not able to proceed as Google mpas api is main part of it.
Your are missing a meta tag in the application tag of manifest
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
You should use SupportMapFragment instead of MapFragment.
Change
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
to
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Change
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
TO
googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
R.id.map)).getMap();
Whatever you have done is ok with older version of GooglePlayServices, but its apparently visible from your logcat that you are using GooglePlayServices 13 or higher so you need to add the meta data tag in your manifest just the way Raghunandan have answered.

Categories

Resources