google map version 2 does not work with fragment - android

I do not know, what i am doing wrong in either my manifest, activity or xml to load map version 2,
i found multiple exceptions if you see my concise logcat,
E/AndroidRuntime(16522): FATAL EXCEPTION: main
E/AndroidRuntime(16522): java.lang.RuntimeException: Unable to start activityComponentInfo{com.production.MyApp/com.project.MyApp.AddEvent.AddEventMapActivity}:
android.view.InflateException: Binary XML file line #7: Error inflating class fragment
E/AndroidRuntime(16522): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
E/AndroidRuntime(16522): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
E/AndroidRuntime(16522): at android.app.Activity.setContentView(Activity.java:1892)
E/AndroidRuntime(16522): at com.project.MyApp.AddEvent.AddEventMapActivity.onCreate(AddEventMapActivity.java:20)
E/AndroidRuntime(16522): 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" />
E/AndroidRuntime(16522): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
E/AndroidRuntime(16522): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
E/AndroidRuntime(16522): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
E/AndroidRuntime(16522): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
while manifest looks like,
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.production.MyApp"
android:versionCode="3"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<permission
android:name=" com.production.MyApp.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name=" com.production.MyApp.permission.MAPS_RECEIVE" />
<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-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:name="com.project.MyApp.MyApplication"
android:enabled="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Light.NoTitleBar" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="no issue with api_key here" />
and xml,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
while i am extending FragmentActivity,
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_layout);
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 = ((SupportMapFragment) getSupportFragmentManager().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();
}
}
}

You need to add the below to manifest file
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Place this at the end of your manifest, after your Map API key meta-data tag.
Check out HERE
It's a new requirement added from the last revision 13 update to google-play-services.

You need to add the following in your manifest
...
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
This information can be found in the logcat error msg.
And also on google play services website

Related

error Api key not found

i am trying to use google maps in my app, i am using google play services in app
MapViewActivity:
public class MapsViewActivity extends FragmentActivity {
// Google Map
private GoogleMap googleMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maps);
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();
}
}
}
XMl:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
and getting the following errors :
08-05 16:41:54.384: E/dalvikvm(24979): Could not find class 'gpq', referenced from method gpr.a
08-05 16:41:54.384: W/dalvikvm(24979): VFY: unable to resolve new-instance 4090 (Lgpq;) in Lgpr;
08-05 16:41:54.384: D/dalvikvm(24979): VFY: replacing opcode 0x22 at 0x0000
08-05 16:41:54.404: W/dalvikvm(24979): VFY: unable to resolve static field 20875 (t) in Lyo;
08-05 16:41:54.404: D/dalvikvm(24979): VFY: replacing opcode 0x62 at 0x000e
08-05 16:41:54.404: W/dalvikvm(24979): VFY: unable to resolve static field 20875 (t) in Lyo;
08-05 16:41:54.484: E/AndroidRuntime(24979): FATAL EXCEPTION: main
08-05 16:41:54.484: E/AndroidRuntime(24979): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.careandcure/com.example.careandcure.MapsViewActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
08-05 16:41:54.484: E/AndroidRuntime(24979): at com.example.careandcure.MapsViewActivity.onCreate(MapsViewActivity.java:16)
08-05 16:41:54.484: E/AndroidRuntime(24979): at android.app.Activity.performCreate(Activity.java:4538)
08-05 16:41:54.484: E/AndroidRuntime(24979): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
08-05 16:41:54.484: E/AndroidRuntime(24979): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
08-05 16:41:54.484: E/AndroidRuntime(24979): 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
08-05 16:41:54.484: E/AndroidRuntime(24979): at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.careandcure"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<permission
android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<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_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.careandcure.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>
<activity android:name="com.example.careandcure.MapsViewActivity" >
</activity>
<!-- Goolge Maps API Key -->
<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="api_key" />
</application>
</manifest>
I am not getting where I am getting wrong or missing anything and
how to remove please help me in solving this issue.
The Log say you:
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
So be sure that you added it in AndroidManifest.xml like in the guide:
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API_KEY"/>
In your manifest file error cause this line
<!-- Goolge Maps API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my api key" />
In value of API key you must add your own API key.
See This link for generate API key
Clearly from your logcat, you have just copy pasted the manifest.xml file. You have to enter your key instead of your API key
Generate your key from google console. And use it in manifest.xml
You will need two metadata for version2 of googlemap
One with api key and another with google service
android:value="#integer/google_play_services_version"
So you should simply copy paste the line. And only try to under stand later.
:-)
Edited:
Change the package name to yours (not of androidhive :-)) Change the line in permission
<permission
android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
To:
<permission
android:name="com.example.careandcure.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
Also why are you using package name of info.androidhive.googlemapsv2 in uses-permission. Change it to your own package name i.e. com.example.careandcure . Hope it's finally your solution.

GoogleMapsDemo gives IllegalStateException

I have did all steps which is give at google but lastly it give's this
errorCaused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4132500 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" />
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googlemapsdemo"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.example.googlemapsdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.googlemapsdemo.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="17" />
<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" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<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.example.googlemapsdemo.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="AIzaSyBLHwjdXsQK0sszxfrkoncHlqU3d2mDJok" />
</application>
</manifest>
MainActivity.java:
package com.example.googlemapsdemo;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Toast;
public class MainActivity extends Activity
{
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();
}
}
manifest file
For eclipse add this :
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
If you are using Android Studio(latest version) with gradle0.7+ then add this line:
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="Your Key" />
Add the Google Play services version to your app's manifest
Edit your application's AndroidManifest.xml file, and add the
following declaration within the element. This embeds the version of
Google Play services that the app was compiled with.
You just need to add <meta-data> under <application> tag into your AndroidManifest.xml
....<application>
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>

Error Fatal Exception: main & Inflating Class Fragment

I am following this tutorial , i used the original files provided in the tutorial but facing same problem.searched for many pre asked questions but could not find way to repair my error.I m having error of "Unfortunately app has stopped" I got errors in logcat as follow.
Logcat of my project
11-30 17:35:36.852: E/Trace(836): error opening trace file: No such file or directory (2)
11-30 17:35:37.432: D/AndroidRuntime(836): Shutting down VM
11-30 17:35:37.432: W/dalvikvm(836): threadid=1: thread exiting with uncaught exception
(group=0x40a13300)
11-30 17:35:37.452: E/AndroidRuntime(836): FATAL EXCEPTION: main
11-30 17:35:37.452: E/AndroidRuntime(836): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gmap/com.example.gmap.MainActivity}: android.view.InflateException: Binary XML file line #18: Error inflating class fragment
.java file as follows
public class MainActivity extends FragmentActivity
implements OnMapClickListener {
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
mMap.setOnMapClickListener(this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public void onMapClick(LatLng position) {
mMap.addMarker(new MarkerOptions()
.position(position)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));
}
}
Manifest file as follow
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gmap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- External storage for caching. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- My Location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Maps API needs OpenGL ES 2.0. -->
<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" >
<!-- You must insert your own Google Maps for Android API v2 key in here. -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="I inserted key obtained" />
<activity
android:name="com.example.gmap.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>
Your Java code seems to be correct. Try to remove the implements onClickListener and onClick method just for a try. Your manifest needs some changing. I suggest adding these elements:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.nurakanbpo.mygenie.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.nurakanbpo.mygenie.MAPS_RECEIVE" />
Your minSdkVersion is 13 for which you dont need supportmapfragment. You can use mapfragment.
Also since revision 13 of google play services was released you need to add this element to your you application tag:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />

Google Play Service library and Google Maps

I try to create a simple GoogleMap by Using Google Play Service and Google Maps API. But all the times I get errors...
I´m working with IntelliJ 12.1, here my full Code:
RecorderMap.java
package com.example.GPSApp;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class RecorderMap extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
}
}
map.xml
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.maps.SupportMapFragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.GPSApp"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="16" />
<permission
android:name="com.example.GPSApp.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.newmapview.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application android:label="#string/app_name">
<uses-library android:name="com.google.android.maps" />
<activity android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".RecorderMap"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar"/>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="XXX" />
</application>
</manifest>
I think the Problem is how I include the GooGlePlayService... I´ve tried to add as module, as libary as External Libary but I don't know how to include and to use it right... :(
EDIT:
LogCat
08-28 07:41:59.869: ERROR/AndroidRuntime(23080): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.GPSApp/com.example.GPSApp.RecorderMap}: android.view.InflateException: Binary XML file line #2: Error inflating class com.google.android.gms.maps.SupportMapFragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class com.google.android.gms.maps.SupportMapFragment
at android.view.LayoutInflater.createView(LayoutInflater.java:508)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:210)
at android.app.Activity.setContentView(Activity.java:1660)
at com.example.GPSApp.RecorderMap.onCreate(RecorderMap.java:18)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
... 11 more
Caused by: java.lang.NoSuchMethodException: SupportMapFragment(Context,AttributeSet)
at java.lang.Class.getMatchingConstructor(Class.java:643)
at java.lang.Class.getConstructor(Class.java:472)
at android.view.LayoutInflater.createView(LayoutInflater.java:480)
... 20 more
****EDIT2**
Problem solved by using this: java.lang.noclassdeffounderror: com.google.android.gms.R$styleable**
The only thing I find missing in your RecorderMap.java file is that you haven't imported the SupportFragment class. So add this line to it
import com.google.android.gms.maps.SupportMapFragment;
If that doesn't work, then check out the following.
From what you are saying, it means you have already installed the google play services. If not, then try installing it using this link http://developer.android.com/google/play-services/setup.html
After that, referencing the google play services library should be as easy as editing your build.gradle file. The current version of android studio makes this possible. Under dependencies in your build.gradle file, add the following code
compile 'com.google.android.gms:play-services:3.1.36'
You seem to have your API key intact.
Finally, remember you need to test your app on an actual android device and not an emulator. The android API version 2 is not yet able to display maps on emulators.
I think this should be okay for your app to work.

Google Map API v2 inflator fails on old phones

I have just implemented a map in the application, and it runs flawlessly in a Galaxy S3. Testing my app with an old phone HTC Sense with API8 the app throws a inflator problem. I think it may be related to either the OS or OGL2. isGooglePlayServicesAvailable(this) returns a correct value. Help me here, please:
Activity.java
public class MyActivity extends Activity
{
#Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.initializeInterface();
}
private void initializeInterface() {
final int available = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
this.setContentView(R.layout.main);
}
}
main.xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
class="com.google.android.gms.maps.MapFragment"
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/footer"
android:layout_below="#id/header" />
manifest.xml
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="com.stuff.permission.MAPS_RECEIVE" />
<permission
android:name="com.stuff.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:icon="#drawable/icon"
android:label="#string/application_name" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="#string/map_api_key_device"/>
<activity
android:name=".MyActivity"
android:configChanges="orientation"
android:launchMode="singleTop"
android:theme="#android:style/Theme.NoTitleBar" >
<intent-filter> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Error
12-13 12:14:13.865: E/My ERROR(22878): Binary XML file line #85: Error inflating class fragment
12-13 12:14:13.875: E/android.view.LayoutInflater.createViewFromTag(22878): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
12-13 12:14:13.895: E/android.view.LayoutInflater.rInflate(22878): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
12-13 12:14:13.915: E/android.view.LayoutInflater.inflate(22878): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
12-13 12:14:13.915: E/android.view.LayoutInflater.inflate(22878): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
12-13 12:14:13.935: E/android.view.LayoutInflater.inflate(22878): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
12-13 12:14:13.945: E/com.android.internal.policy.impl.PhoneWindow.setContentView(22878): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
12-13 12:14:13.945: E/android.app.Activity.setContentView(22878): at android.app.Activity.setContentView(Activity.java:1654)
It has to do with the fact that you are trying to use native API Level 11 fragments on an API Level 8 device. Switch to FragmentActivity and SupportMapFragment if you wish to have your code work on earlier versions than Android 3.0.
I solved this problem by adding the v13 libraries from /extras/android/compatibility/v13 and changing my Activity to FragmentActivity and MapFragment to SupportMapFragment.
for me help app project -> right click -> properties -> android -> project build target -> and chack earlier android release. (with google api)
if you dont have, download one by SDK manager

Categories

Resources