I am trying to check google play services but it gives error.
Here is my manifest file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gmapapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<permission
android:name="com.example.gmapapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.gmapapp.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-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.gmapapp.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="GOOGLE_API_KEY"/>
</application>
</manifest>
Here is my main activity.
public class MainActivity extends Activity {
private static final int GPS_ERRORDIALOG_REQUEST = 9001;
GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (servicesOK()) {
Toast.makeText(this, "Google play services successfully connected.", Toast.LENGTH_SHORT).show();
}
setContentView(R.layout.activity_main);
}
#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;
}
public boolean servicesOK(){
int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (isAvailable == ConnectionResult.SUCCESS) {
return true;
}else if (GooglePlayServicesUtil.isUserRecoverableError(isAvailable)) {
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST);
dialog.show();
}else{
Toast.makeText(this, "Can't connect to google play services.", Toast.LENGTH_SHORT).show();
}
return false;
}
}
My log cat errors
02-15 19:22:58.070: E/AndroidRuntime(7499): FATAL EXCEPTION: main
02-15 19:22:58.070: E/AndroidRuntime(7499): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gmapapp/com.example.gmapapp.MainActivity}: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4242000 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" />
02-15 19:22:58.070: E/AndroidRuntime(7499): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
02-15 19:22:58.070: E/AndroidRuntime(7499): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
02-15 19:22:58.070: E/AndroidRuntime(7499): at android.app.ActivityThread.access$600(ActivityThread.java:123)
02-15 19:22:58.070: E/AndroidRuntime(7499): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
02-15 19:22:58.070: E/AndroidRuntime(7499): at android.os.Handler.dispatchMessage(Handler.java:99)
02-15 19:22:58.070: E/AndroidRuntime(7499): at android.os.Looper.loop(Looper.java:137)
02-15 19:22:58.070: E/AndroidRuntime(7499): at android.app.ActivityThread.main(ActivityThread.java:4424)
02-15 19:22:58.070: E/AndroidRuntime(7499): at java.lang.reflect.Method.invokeNative(Native Method)
02-15 19:22:58.070: E/AndroidRuntime(7499): at java.lang.reflect.Method.invoke(Method.java:511)
02-15 19:22:58.070: E/AndroidRuntime(7499): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
02-15 19:22:58.070: E/AndroidRuntime(7499): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
02-15 19:22:58.070: E/AndroidRuntime(7499): at dalvik.system.NativeStart.main(Native Method)
02-15 19:22:58.070: E/AndroidRuntime(7499): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4242000 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" />
02-15 19:22:58.070: E/AndroidRuntime(7499): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
02-15 19:22:58.070: E/AndroidRuntime(7499): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
02-15 19:22:58.070: E/AndroidRuntime(7499): at com.example.gmapapp.MainActivity.servicesOK(MainActivity.java:36)
02-15 19:22:58.070: E/AndroidRuntime(7499): at com.example.gmapapp.MainActivity.onCreate(MainActivity.java:21)
02-15 19:22:58.070: E/AndroidRuntime(7499): at android.app.Activity.performCreate(Activity.java:4465)
02-15 19:22:58.070: E/AndroidRuntime(7499): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
02-15 19:22:58.070: E/AndroidRuntime(7499): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
02-15 19:22:58.070: E/AndroidRuntime(7499): ... 11 more
Add the following to your AndroidManifest.xml, within the <application> tag:
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
The log actually is quite explanatory.
Your log cat only clearly saying that:
java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4242000 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" />
so you just add it in application element in Android manifest.
Related
I submitted an similar question earlier on a more advanced project, so I thought I would simplify things by using the maps API tutorial provided by google to try and replicate the error I was getting, and I get the same error! Good and bad, at least I know it's not my project causing the error.
Now I just need to figure out why I am getting this error! I am new to programming but I followed this tutorial here verbatum:
https://developers.google.com/maps/documentation/android/start
Here is the error I am getting:
03-24 20:47:03.244: E/AndroidRuntime(6250): FATAL EXCEPTION: main
03-24 20:47:03.244: E/AndroidRuntime(6250): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test/com.example.test.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
03-24 20:47:03.244: E/AndroidRuntime(6250): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
03-24 20:47:03.244: E/AndroidRuntime(6250): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
03-24 20:47:03.244: E/AndroidRuntime(6250): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-24 20:47:03.244: E/AndroidRuntime(6250): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
03-24 20:47:03.244: E/AndroidRuntime(6250): at android.os.Handler.dispatchMessage(Handler.java:99)
03-24 20:47:03.244: E/AndroidRuntime(6250): at android.os.Looper.loop(Looper.java:137)
03-24 20:47:03.244: E/AndroidRuntime(6250): at android.app.ActivityThread.main(ActivityThread.java:5103)
03-24 20:47:03.244: E/AndroidRuntime(6250): at java.lang.reflect.Method.invokeNative(Native Method)
03-24 20:47:03.244: E/AndroidRuntime(6250): at java.lang.reflect.Method.invoke(Method.java:525)
03-24 20:47:03.244: E/AndroidRuntime(6250): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
03-24 20:47:03.244: E/AndroidRuntime(6250): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-24 20:47:03.244: E/AndroidRuntime(6250): at dalvik.system.NativeStart.main(Native Method)
03-24 20:47:03.244: E/AndroidRuntime(6250): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
03-24 20:47:03.244: E/AndroidRuntime(6250): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
03-24 20:47:03.244: E/AndroidRuntime(6250): at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
03-24 20:47:03.244: E/AndroidRuntime(6250): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
03-24 20:47:03.244: E/AndroidRuntime(6250): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
03-24 20:47:03.244: E/AndroidRuntime(6250): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
03-24 20:47:03.244: E/AndroidRuntime(6250): at android.app.Activity.setContentView(Activity.java:1895)
03-24 20:47:03.244: E/AndroidRuntime(6250): at com.example.test.MainActivity.onCreate(MainActivity.java:11)
03-24 20:47:03.244: E/AndroidRuntime(6250): at android.app.Activity.performCreate(Activity.java:5133)
03-24 20:47:03.244: E/AndroidRuntime(6250): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-24 20:47:03.244: E/AndroidRuntime(6250): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
03-24 20:47:03.244: E/AndroidRuntime(6250): ... 11 more
03-24 20:47:03.244: E/AndroidRuntime(6250): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4242000 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" />
03-24 20:47:03.244: E/AndroidRuntime(6250): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
03-24 20:47:03.244: E/AndroidRuntime(6250): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
03-24 20:47:03.244: E/AndroidRuntime(6250): at com.google.android.gms.maps.internal.q.v(Unknown Source)
03-24 20:47:03.244: E/AndroidRuntime(6250): at com.google.android.gms.maps.internal.q.u(Unknown Source)
03-24 20:47:03.244: E/AndroidRuntime(6250): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
03-24 20:47:03.244: E/AndroidRuntime(6250): at com.google.android.gms.maps.MapFragment$b.ex(Unknown Source)
03-24 20:47:03.244: E/AndroidRuntime(6250): at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
03-24 20:47:03.244: E/AndroidRuntime(6250): at com.google.android.gms.dynamic.a.a(Unknown Source)
03-24 20:47:03.244: E/AndroidRuntime(6250): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
03-24 20:47:03.244: E/AndroidRuntime(6250): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
03-24 20:47:03.244: E/AndroidRuntime(6250): at android.app.Activity.onCreateView(Activity.java:4745)
03-24 20:47:03.244: E/AndroidRuntime(6250): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
03-24 20:47:03.244: E/AndroidRuntime(6250): ... 20 more
Here is my simple MainActivity.java
package com.example.test;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
here is my simple activity_main.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"
class="com.google.android.gms.maps.SupportMapFragment"
android:name="com.example.test.MainActivity"/>
Here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<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"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.test.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="HIDDEN"/>
</application>
</manifest>
The only thing I can think of is that my manifest file is improperly set up. But I followed the instructions and Eclipse didn't give me an error on it. I am up in arms here trying to figure this out. Any help would be appreciated.
Your logcat clearly said
Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4242000 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" />
03-24 20:47:03.244: E/AndroidRuntime(6250): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
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 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>
This is because latest google play services requires a version name, which is to be mentioned using <meta-data .. /> inside AndroidManifest.xml
....<application>
..............
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="Key" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
Also Extends your Activity to FragmentActivity
MainActivity extends FragmentActivity
You need to add the below as a child of application tag as mentioned in the other answer.
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Also you have
<uses-sdk
android:minSdkVersion="8"
So change this
public class MainActivity extends Activity {
to
public class MainActivity extends FragmentActivity {
Since you use SupportMapFragment you need to use FragmentActivity which is the base class for support based fragments.
Also change this
class="com.google.android.gms.maps.SupportMapFragment"
android:name="com.example.test.MainActivity"/> // remove this
to
class="com.google.android.gms.maps.SupportMapFragment"/>
Put both meta tag with your API key....in between applicationTag.
Also add permission tag with your package name which you use in Google console in your AndroidManifest.xml.
<permission
android:name="com.xyz.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.xyz.permission.MAPS_RECEIVE"/>
<application
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="Put Your API Key here"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
Extend your class activity to fragment activity use below
public class MainActivity extends FragmentActivity
Insted of this
public class MainActivity extends Activity
You are missing following lines in your Manifest file,
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Please write these lines before your MAP-API Key tag, inside the tag.
Once you will complete these changes you will get Fragment error as you are using latest version of Map but you are using Activity inside your code, So you need to change following as well,
Extends your Activity to FragmentActivity
MainActivity extends FragmentActivity
I am android beginner, I follow a tutorial and try to show the google map using android. and I've also checked the other similar questions asked here, but am still unable to load a map :
logcat:
12-29 14:16:53.025: E/AndroidRuntime(4499): FATAL EXCEPTION: main
12-29 14:16:53.025: E/AndroidRuntime(4499): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gmapsapp/com.example.gmapsapp.MainActivity}: 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" />
12-29 14:16:53.025: E/AndroidRuntime(4499): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
12-29 14:16:53.025: E/AndroidRuntime(4499): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
12-29 14:16:53.025: E/AndroidRuntime(4499): at android.app.ActivityThread.access$600(ActivityThread.java:140)
12-29 14:16:53.025: E/AndroidRuntime(4499): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
12-29 14:16:53.025: E/AndroidRuntime(4499): at android.os.Handler.dispatchMessage(Handler.java:99)
12-29 14:16:53.025: E/AndroidRuntime(4499): at android.os.Looper.loop(Looper.java:137)
12-29 14:16:53.025: E/AndroidRuntime(4499): at android.app.ActivityThread.main(ActivityThread.java:4898)
12-29 14:16:53.025: E/AndroidRuntime(4499): at java.lang.reflect.Method.invokeNative(Native Method)
12-29 14:16:53.025: E/AndroidRuntime(4499): at java.lang.reflect.Method.invoke(Method.java:511)
12-29 14:16:53.025: E/AndroidRuntime(4499): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
12-29 14:16:53.025: E/AndroidRuntime(4499): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
12-29 14:16:53.025: E/AndroidRuntime(4499): at dalvik.system.NativeStart.main(Native Method)
12-29 14:16:53.025: E/AndroidRuntime(4499): 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" />
12-29 14:16:53.025: E/AndroidRuntime(4499): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
12-29 14:16:53.025: E/AndroidRuntime(4499): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
12-29 14:16:53.025: E/AndroidRuntime(4499): at com.example.gmapsapp.MainActivity.servicesOK(MainActivity.java:40)
12-29 14:16:53.025: E/AndroidRuntime(4499): at com.example.gmapsapp.MainActivity.onCreate(MainActivity.java:22)
12-29 14:16:53.025: E/AndroidRuntime(4499): at android.app.Activity.performCreate(Activity.java:5206)
12-29 14:16:53.025: E/AndroidRuntime(4499): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
12-29 14:16:53.025: E/AndroidRuntime(4499): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
12-29 14:16:53.025: E/AndroidRuntime(4499): ... 11 more
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gmapsapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.example.gmapsapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.gmapsapp.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-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.gmapsapp.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="mykey"/>
</application>
</manifest>
MainActivity
package com.example.gmapsapp;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.Toast;
public class MainActivity extends FragmentActivity {
private static final int GPS_ERRORDIALOG_REQUEST = 9001;
GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (servicesOK()) {
Toast.makeText(this, "Ready to map!", Toast.LENGTH_SHORT).show();
setContentView(R.layout.activity_map);
}
else {
setContentView(R.layout.activity_main);
}
}
#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;
}
public boolean servicesOK() {
int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (isAvailable == ConnectionResult.SUCCESS) {
return true;
}
else if (GooglePlayServicesUtil.isUserRecoverableError(isAvailable)) {
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST);
dialog.show();
}
else {
Toast.makeText(this, "Can't connect to Google Play services", Toast.LENGTH_SHORT).show();
}
return false;
}
}
activity_map
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
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.
This is a new requirement as of the updated google play services which is rev 13 i guess.
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
https://developers.google.com/maps/documentation/android/start#getting_the_google_maps_android_api_v2
There is no need for
<permission
android:name="com.example.gmapsapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
and this
<uses-permission android:name="com.example.gmapsapp.permission.MAPS_RECEIVE"/>
Refer Specifying permission in the above link
try to put
<meta-data
android:name="com.google.android.gms.version"
android:value="key" />
inside your application tag, in AndroidManifest.xml
I'm new to android map development.I tried to add google map to my application.It was generated errors. Followings errors were occurred.
12-19 10:53:47.950: E/AndroidRuntime(4131): FATAL EXCEPTION: main
12-19 10:53:47.950: E/AndroidRuntime(4131): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.maptest/com.example.maptest.MainActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
12-19 10:53:47.950: E/AndroidRuntime(4131): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2114)
12-19 10:53:47.950: E/AndroidRuntime(4131): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139)
12-19 10:53:47.950: E/AndroidRuntime(4131): at android.app.ActivityThread.access$700(ActivityThread.java:143)
12-19 10:53:47.950: E/AndroidRuntime(4131): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
12-19 10:53:47.950: E/AndroidRuntime(4131): at android.os.Handler.dispatchMessage(Handler.java:99)
12-19 10:53:47.950: E/AndroidRuntime(4131): at android.os.Looper.loop(Looper.java:137)
12-19 10:53:47.950: E/AndroidRuntime(4131): at android.app.ActivityThread.main(ActivityThread.java:4960)
12-19 10:53:47.950: E/AndroidRuntime(4131): at java.lang.reflect.Method.invokeNative(Native Method)
12-19 10:53:47.950: E/AndroidRuntime(4131): at java.lang.reflect.Method.invoke(Method.java:511)
12-19 10:53:47.950: E/AndroidRuntime(4131): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
12-19 10:53:47.950: E/AndroidRuntime(4131): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
12-19 10:53:47.950: E/AndroidRuntime(4131): at dalvik.system.NativeStart.main(Native Method)
12-19 10:53:47.950: E/AndroidRuntime(4131): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
12-19 10:53:47.950: E/AndroidRuntime(4131): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:710)
12-19 10:53:47.950: E/AndroidRuntime(4131): at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
12-19 10:53:47.950: E/AndroidRuntime(4131): at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
12-19 10:53:47.950: E/AndroidRuntime(4131): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
12-19 10:53:47.950: E/AndroidRuntime(4131): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
12-19 10:53:47.950: E/AndroidRuntime(4131): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:318)
12-19 10:53:47.950: E/AndroidRuntime(4131): at android.app.Activity.setContentView(Activity.java:1925)
12-19 10:53:47.950: E/AndroidRuntime(4131): at com.example.maptest.MainActivity.onCreate(MainActivity.java:12)
12-19 10:53:47.950: E/AndroidRuntime(4131): at android.app.Activity.performCreate(Activity.java:5203)
12-19 10:53:47.950: E/AndroidRuntime(4131): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
12-19 10:53:47.950: E/AndroidRuntime(4131): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2078)
12-19 10:53:47.950: E/AndroidRuntime(4131): ... 11 more
12-19 10:53:47.950: E/AndroidRuntime(4131): Caused by: java.lang.IllegalStateException: A required meta-data tag in your app's AndroidManifest.xml does not exist. 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" />
12-19 10:53:47.950: E/AndroidRuntime(4131): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
12-19 10:53:47.950: E/AndroidRuntime(4131): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
12-19 10:53:47.950: E/AndroidRuntime(4131): at com.google.android.gms.maps.internal.q.v(Unknown Source)
12-19 10:53:47.950: E/AndroidRuntime(4131): at com.google.android.gms.maps.internal.q.u(Unknown Source)
12-19 10:53:47.950: E/AndroidRuntime(4131): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
12-19 10:53:47.950: E/AndroidRuntime(4131): at com.google.android.gms.maps.MapFragment$b.cE(Unknown Source)
12-19 10:53:47.950: E/AndroidRuntime(4131): at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
12-19 10:53:47.950: E/AndroidRuntime(4131): at com.google.android.gms.dynamic.a.a(Unknown Source)
12-19 10:53:47.950: E/AndroidRuntime(4131): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
12-19 10:53:47.950: E/AndroidRuntime(4131): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
12-19 10:53:47.950: E/AndroidRuntime(4131): at android.app.Activity.onCreateView(Activity.java:4835)
12-19 10:53:47.950: E/AndroidRuntime(4131): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:686)
12-19 10:53:47.950: E/AndroidRuntime(4131): ... 21 more
This is the xml code.
<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" >
<fragment
android:id="#+id/fragment1"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="145dp" />
</RelativeLayout>
This is the main activity code.
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#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;
}
}
This is the manifest code.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.maptest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDI4t1Re46zMCY_j58DzWY07Uw5OLhyZIM">
</meta-data>
<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"
android:required="false" />
<activity
android:name="com.example.maptest.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>
I added google_play_service library as well.
Can any one help me to sove this error.
Caused by: java.lang.IllegalStateException: A required meta-data tag in your app's AndroidManifest.xml does not exist.
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" />
Your log telling you everything :
Add the version code of google play services inside <application> i.e. before </application> inside AndroidManifest.xml
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Reference
Also move following code inside <application> i.e before </application> inside AndroidManifest.xml
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDI4t1Re46zMCY_j58DzWY07Uw5OLhyZIM">
</meta-data>
You can try this code, if you know the location name you want to display in map. It worked for me.
Geocoder geocoder;
List<Address> addresses = null;
geocoder = new Geocoder(this, Locale.getDefault());
try {
//getFromLocationName returns array of address, it takes 2 parameter one place name and count of result
addresses = geocoder.getFromLocationName("Place name", 1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
latitude = addresses.get(0).getLatitude();
longitude = addresses.get(0).getLongitude();
String label = "SomePlace";
String in = "geo:" + latitude + "," + longitude;
String query = latitude + "," + longitude + "(" + label + ")";
String ey = Uri.encode(query);
String uriLoc = in + "?q=" + ey+ "&z=16";
Log.d(uriLoc, "no log");
Uri uri = Uri.parse(uriLoc);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);
startActivity(intent);
Please check this line from your log.
Caused by: java.lang.IllegalStateException: A required meta-data tag in your app's AndroidManifest.xml does not exist. You must have the following declaration within the application tag
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.map">
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<permission
android:name="com.example.map.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.INTERNET"/>
<!--to access information about networks-->
<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"/>
<!--to access approximate location through network location providers-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<!--to get precise location through GPS location provider-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.example.map.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<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" />
<application
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.geo.API_KEY"
android:value="#string/google_maps_key" />
<activity
android:name=".MainActivity"
android:label="#string/title_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I made an App. and since I just wanted to test some functions before adding them to the App,
I decided to copy my project into a new Project. When I tried to run the new project, the app crashes and the log-cat output is as follows.
Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidbook.MP"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" android:debuggable="true">
<activity
android:name=".MPActivity"
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="AddLocationActivity"></activity>
<activity android:name="MPData"></activity>
<activity android:name="MyLocations"></activity>
<activity android:name="MPInfo"></activity>
<activity android:name="Navigation"></activity>
</application>
LogCat:
05-21 15:30:03.710: E/AndroidRuntime(11294): FATAL EXCEPTION: main
05-21 15:30:03.710: E/AndroidRuntime(11294): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.androidbook.MP/com.androidbook.MP.MPActivity}:
java.lang.ClassNotFoundException: com.androidbook.MP.MPActivity in loader
dalvik.system.PathClassLoader[/data/app/com.androidbook.MP-1.apk]
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.os.Handler.dispatchMessage(Handler.java:99)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.os.Looper.loop(Looper.java:130)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.app.ActivityThread.main(ActivityThread.java:3691)
05-21 15:30:03.710: E/AndroidRuntime(11294): at java.lang.reflect.Method.invokeNative(Native Method)
05-21 15:30:03.710: E/AndroidRuntime(11294): at java.lang.reflect.Method.invoke(Method.java:507)
05-21 15:30:03.710: E/AndroidRuntime(11294): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
05-21 15:30:03.710: E/AndroidRuntime(11294): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
05-21 15:30:03.710: E/AndroidRuntime(11294): at dalvik.system.NativeStart.main(Native Method)
05-21 15:30:03.710: E/AndroidRuntime(11294): Caused by: java.lang.ClassNotFoundException: com.androidbook.MP.MPActivity in loader dalvik.system.PathClassLoader[/data/app/com.androidbook.MP-1.apk]
05-21 15:30:03.710: E/AndroidRuntime(11294): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
05-21 15:30:03.710: E/AndroidRuntime(11294): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
05-21 15:30:03.710: E/AndroidRuntime(11294): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
05-21 15:30:03.710: E/AndroidRuntime(11294): ... 11 more
Check your Manifest file, if the activity is to be declared.
for Ex:
<application>
<activity android:name=".MyActivity" 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>
Look through all the files in your new project and make sure they aren't referencing classes from the old project.
I think I found the solution, i should have checked that, the package name of the new project is included in the manifest file as for an example
"package="com.androidbook.MPTest" ..
my mistake is the i used the package name of the old project as a package name of the new project.
I'm trying to use OSMdroid for a project, and i'm utterly unable to make the simplest code work.
Well, a few days ago i was able to display maps and so on, and now i can't even instantiate a MapView.
I reduced the code to its sipmlest form.
I work with eclipse. I downloaded osmdroid-android-3.0.5.jar and slf4j-android-1.5.8.jar, and i included them in the project by adding lines to the classpath file
<classpathentry kind="lib" path="lib/osmdroid-android-3.0.5.jar"/>
<classpathentry kind="lib" path="lib/slf4j-android-1.5.8.jar"/>
Or by right clicking on them then Build Path-> Add to build path (both gave the same result, anyway)
Then i typed this code:
import android.app.Activity;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;
import android.os.Bundle;
public class TestMapActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mv=new MapView(this,256);
}
}
And i get a bug when running it on the emulator:
04-17 09:10:31.181: E/AndroidRuntime(595): FATAL EXCEPTION: main
04-17 09:10:31.181: E/AndroidRuntime(595): java.lang.NoClassDefFoundError: org.osmdroid.views.MapView
04-17 09:10:31.181: E/AndroidRuntime(595): at testmap.sagem.TestMapActivity.onCreate(TestMapActivity.java:17)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.app.Activity.performCreate(Activity.java:4465)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.os.Handler.dispatchMessage(Handler.java:99)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.os.Looper.loop(Looper.java:137)
04-17 09:10:31.181: E/AndroidRuntime(595): at android.app.ActivityThread.main(ActivityThread.java:4424)
04-17 09:10:31.181: E/AndroidRuntime(595): at java.lang.reflect.Method.invokeNative(Native Method)
04-17 09:10:31.181: E/AndroidRuntime(595): at java.lang.reflect.Method.invoke(Method.java:511)
04-17 09:10:31.181: E/AndroidRuntime(595): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-17 09:10:31.181: E/AndroidRuntime(595): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-17 09:10:31.181: E/AndroidRuntime(595): at dalvik.system.NativeStart.main(Native Method)
When i comment out the "MapView mv=new MapView(this,256);" it works, so i don't understand why the mapview can't be instantiated.
Any idea on this?
Thank you for your attention.
EDIT:
The AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="testmap.sagem"
android:versionCode="1"
android:versionName="1.0" >
<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.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".TestMapActivity"
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>
The main.xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</LinearLayout>
Change Folder name "lib" to "libs" and put all jar files in that folder and Charge path of jar
files to "libs" folder. I am not sure but I think it will work.
Try to use the 3.0.7 and clean the project.
Let me know.
http://code.google.com/p/osmdroid/downloads/list