Google Cloud Messaging Error: Unable to instantiate receiver - android

I've followed google guide about new GCM with Google Play Services and after hours of developing i managed to register my device on GCM server, to obtain the REGISTER_ID and to create a php script which correctly send a post request.
The bad news is that i don't manage to receive my push notification, when i run my app logcat shows this error:
12-19 19:48:24.405: E/AndroidRuntime(9570): FATAL EXCEPTION: main
12-19 19:48:24.405: E/AndroidRuntime(9570): java.lang.RuntimeException: Unable to instantiate receiver com.baruckis.SlidingMenuImplementation.GcmBroadcastReceiver:
java.lang.ClassNotFoundException: com.baruckis.SlidingMenuImplementation.GcmBroadcastReceiver
12-19 19:48:24.405: E/AndroidRuntime(9570): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2112)
12-19 19:48:24.405: E/AndroidRuntime(9570): at android.app.ActivityThread.access$1500(ActivityThread.java:127)
12-19 19:48:24.405: E/AndroidRuntime(9570): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
12-19 19:48:24.405: E/AndroidRuntime(9570): at android.os.Handler.dispatchMessage(Handler.java:99)
12-19 19:48:24.405: E/AndroidRuntime(9570): at android.os.Looper.loop(Looper.java:137)
12-19 19:48:24.405: E/AndroidRuntime(9570): at android.app.ActivityThread.main(ActivityThread.java:4507)
12-19 19:48:24.405: E/AndroidRuntime(9570): at java.lang.reflect.Method.invokeNative(Native Method)
12-19 19:48:24.405: E/AndroidRuntime(9570): at java.lang.reflect.Method.invoke(Method.java:511)
12-19 19:48:24.405: E/AndroidRuntime(9570): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
12-19 19:48:24.405: E/AndroidRuntime(9570): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
12-19 19:48:24.405: E/AndroidRuntime(9570): at dalvik.system.NativeStart.main(Native Method)
12-19 19:48:24.405: E/AndroidRuntime(9570): Caused by: java.lang.ClassNotFoundException: com.baruckis.SlidingMenuImplementation.GcmBroadcastReceiver
12-19 19:48:24.405: E/AndroidRuntime(9570): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
12-19 19:48:24.405: E/AndroidRuntime(9570): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-19 19:48:24.405: E/AndroidRuntime(9570): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-19 19:48:24.405: E/AndroidRuntime(9570): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2107)
12-19 19:48:24.405: E/AndroidRuntime(9570): ... 10 more
12-19 19:48:52.620: I/Process(9570): Sending signal. PID: 9570 SIG: 9
This is my Manifest (i've omitted the unnecessary parts of code):
<uses-sdk
android:minSdkVersion="8"
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.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission android:name="com.baruckis.SlidingMenuImplementation.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.baruckis.SlidingMenuImplementation.permission.C2D_MESSAGE" />
<!-- This app has permission to register and receive data message. -->
<uses-permission
android:name="com.google.android.c2dm.permission.RECEIVE" />
<application
[...]
<receiver
android:name="com.baruckis.SlidingMenuImplementation.GcmBroadcastReceiver"
android:enabled="true"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.baruckis.SlidingMenuImplementation" />
</intent-filter>
</receiver>
<service android:name="com.baruckis.SlidingMenuImplementation.GcmIntentService" />
<meta-data android:name="com.google.android.gms.version" android:value="4030500" />
</application>
And finally this is my GcmBroadcastReceiver code:
package com.baruckis.SlidingMenuImplementation;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// Explicitly specify that GcmIntentService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(),
GcmIntentService.class.getName());
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
Thanks to all! :)

Try extending the provided: com.google.android.gcm.GCMBroadcastReceiver
public class MyGCMBroadcastReceiver extends com.google.android.gcm.GCMBroadcastReceiver {
protected String getGCMIntentServiceClassName(Context context) {
return GCMIntentService.class.getName();
}
}

Related

Google Map api v2 application stop working

I am trying to run Google maps API v2 on emulator. It says "unfortunately app has stoped" Here is my manifest.xml code. There is a huge number of errors. In the first line it gives error to define android.allowBackup which I have done on application tag.Please help me solve them.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<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="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permissionandroid:name="com.myapp.providers.gsf.permission.
READ_GSERVICES"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.google.android.gms.version" android:value="4030500" />
<!-- <meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" /> -->
<activity
android:name="com.myapp.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="My key"/>
</application>
</manifest>
----------------------------------------------------------------------------------------------
MainActivity.java
package myapp;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends FragmentActivity {
private GoogleMap map;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
map = mapFrag.getMap();
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
}
------------------------------------------------------------------------------------
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"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
-----------------------------------------------------------------
Logcat
E/Trace(690): error opening trace file: No such file or directory (2)
E/AndroidRuntime(690): FATAL EXCEPTION: main
E/AndroidRuntime(690): java.lang.RuntimeException:
Unable to start activity
ComponentInfo{myapp/myapp.MainActivity}:android.view.InflateException: Binary XML file line #2:
Error inflating class fragment
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
android.app.ActivityThread.access$600(ActivityThread.java:130)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:4745)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
dalvik.system.NativeStart.main(Native Method)
09-01 15:06:56.709: E/AndroidRuntime(690): Caused by: android.view.InflateException: Binary XML
file line #2: Error inflating class fragment
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
android.view.LayoutInflater.inflate(LayoutInflater.java:466)
android.view.LayoutInflater.inflate(LayoutInflater.java:396)
android.view.LayoutInflater.inflate(LayoutInflater.java:352)
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
android.app.Activity.setContentView(Activity.java:1867)
android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.
java:110)
android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
myapp.MainActivity.onCreate(MainActivity.java:14)
android.app.Activity.performCreate(Activity.java:5008)
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
AndroidRuntime(690): ... 11 more
AndroidRuntime(690): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's
AndroidManifest.xml does not have the right value. Expected 5089000 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" />
com.google.android.gms.common.GooglePlayServicesUtil.A(Unknown Source)
com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable
(Unknown Source)
com.google.android.gms.maps.internal.u.I(Unknown Source)
com.google.android.gms.maps.internal.u.H(Unknown Source)
com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
com.google.android.gms.maps.MapFragment$b.jz(Unknown Source)
com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
com.google.android.gms.dynamic.a.a(Unknown Source)
com.google.android.gms.dynamic.a.onInflate(Unknown Source)
com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
android.app.Activity.onCreateView(Activity.java:4663)
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
09-01 15:06:56.709: E/AndroidRuntime(690): ... 23 more
09-01 15:07:53.868: E/Trace(734): error opening trace file: No such file or directory (2)
09-01 15:07:54.479: E/AndroidRuntime(734): FATAL EXCEPTION: main
09-01 15:07:54.479: E/AndroidRuntime(734): java.lang.RuntimeException:
Unable to start activity ComponentInfo{myapp/myapp.MainActivity}
android.view.InflateException: Binary XML file line #2: Error inflating class fragment
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
android.app.ActivityThread.access$600(ActivityThread.java:130)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:4745)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
dalvik.system.NativeStart.main(Native Method)
09-01 15:07:54.479: E/AndroidRuntime(734): Caused by:
android.view.InflateException: Binary XML file line #2: Error inflating class fragment
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
android.view.LayoutInflater.inflate(LayoutInflater.java:466)
android.view.LayoutInflater.inflate(LayoutInflater.java:396)
android.view.LayoutInflater.inflate(LayoutInflater.java:352)
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
android.app.Activity.setContentView(Activity.java:1867)
android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
android.support.v7.app.ActionBarActivityDelegateICS.
setContentView(ActionBarActivityDelegateICS.java:110)
android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
myapp.MainActivity.onCreate(MainActivity.java:14)
android.app.Activity.performCreate(Activity.java:5008)
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
E/AndroidRuntime(734): ... 11 more
E/AndroidRuntime(734): Caused by: java.lang.IllegalStateException: The meta-data tag in your
app's AndroidManifest.xml does not have the right value. Expected 5089000 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" />
com.google.android.gms.common.GooglePlayServicesUtil.A(Unknown Source)
com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable
(Unknown Source)
com.google.android.gms.maps.internal.u.I(Unknown Source)
com.google.android.gms.maps.internal.u.H(Unknown Source)
com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
com.google.android.gms.maps.MapFragment$b.jz(Unknown Source)
com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
com.google.android.gms.dynamic.a.a(Unknown Source)
com.google.android.gms.dynamic.a.onInflate(Unknown Source)
com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
android.app.Activity.onCreateView(Activity.java:4663)
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
09-01 15:07:54.479: E/AndroidRuntime(734): ... 23 more
error opening trace file: No such file or directory (2)
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{myapp/myapp.MainActivity}:
android.view.InflateException: Binary XML file line #2: Error inflating class fragment
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
android.app.ActivityThread.access$600(ActivityThread.java:130)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:4745)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
dalvik.system.NativeStart.main(Native Method)
09-01 15:12:22.938: E/AndroidRuntime(811): Caused by: android.view.InflateException: Binary XML
file line #2: Error inflating class fragment
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
android.view.LayoutInflater.inflate(LayoutInflater.java:466)
android.view.LayoutInflater.inflate(LayoutInflater.java:396)
android.view.LayoutInflater.inflate(LayoutInflater.java:352)
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
android.app.Activity.setContentView(Activity.java:1867)
android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
android.support.v7.app.ActionBarActivityDelegateICS.setContentView
(ActionBarActivityDelegateICS.java:110)
android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
myapp.MainActivity.onCreate(MainActivity.java:14)
android.app.Activity.performCreate(Activity.java:5008)
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
09-01 15:12:22.938: E/AndroidRuntime(811): ... 11 more
09-01 15:12:22.938: E/AndroidRuntime(811): Caused by: java.lang.IllegalStateException: The meta-
data tag in your app's AndroidManifest.xml does not have the right value. Expected 5089000
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" />
com.google.android.gms.common.GooglePlayServicesUtil.A(Unknown Source)
com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable
(Unknown Source)
com.google.android.gms.maps.internal.u.I(Unknown Source)
com.google.android.gms.maps.internal.u.H(Unknown Source)
com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
com.google.android.gms.maps.MapFragment$b.jz(Unknown Source)
com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
com.google.android.gms.dynamic.a.a(Unknown Source)
com.google.android.gms.dynamic.a.onInflate(Unknown Source)
com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
android.app.Activity.onCreateView(Activity.java:4663)
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
09-01 15:19:34.508: E/Trace(826): error opening trace file: No such file or directory (2)
09-01 15:19:35.118: E/AndroidRuntime(826): FATAL EXCEPTION: main
09-01 15:19:35.118: E/AndroidRuntime(826): java.lang.RuntimeException:
Unable to start activity ComponentInfo{myapp/myapp.MainActivity}: android.view.InflateException:
Binary XML file line #2: Error inflating class fragment
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
android.app.ActivityThread.access$600(ActivityThread.java:130)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:4745)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
dalvik.system.NativeStart.main(Native Method)
09-01 15:19:35.118: E/AndroidRuntime(826): Caused by: android.view.InflateException: Binary XML
file line #2: Error inflating class fragment
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
android.view.LayoutInflater.inflate(LayoutInflater.java:466)
android.view.LayoutInflater.inflate(LayoutInflater.java:396)
android.view.LayoutInflater.inflate(LayoutInflater.java:352)
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
android.app.Activity.setContentView(Activity.java:1867)
android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
android.support.v7.app.ActionBarActivityDelegateICS.setContentView
(ActionBarActivityDelegateICS.java:110)
android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
myapp.MainActivity.onCreate(MainActivity.java:14)
android.app.Activity.performCreate(Activity.java:5008)
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
09-01 15:19:35.118: E/AndroidRuntime(826): ... 11 more
09-01 15:19:35.118: E/AndroidRuntime(826): Caused by: java.lang.IllegalStateException:
The meta- data tag in your app's AndroidManifest.xml does not
have the right value. Expected 5089000 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" />
com.google.android.gms.common.GooglePlayServicesUtil.A(Unknown Source)
com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailabl
(Unknown Source)
com.google.android.gms.maps.internal.u.I(Unknown Source)
com.google.android.gms.maps.internal.u.H(Unknown Source)
com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
com.google.android.gms.maps.MapFragment$b.jz(Unknown Source)
com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
com.google.android.gms.dynamic.a.a(Unknown Source)
com.google.android.gms.dynamic.a.onInflate(Unknown Source)
com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
android.app.Activity.onCreateView(Activity.java:4663)
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
09-01 15:27:57.068: E/Trace(865): error opening trace file: No such file or directory (2)
09-01 15:27:57.748: E/AndroidRuntime(865): FATAL EXCEPTION: main
09-01 15:27:57.748: E/AndroidRuntime(865): java.lang.RuntimeException:
Unable to start activity ComponentInfo{myapp/myapp.MainActivity}:
android.view.InflateException: Binary XML file line #2: Error inflating class fragment
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
android.app.ActivityThread.access$600(ActivityThread.java:130)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:4745)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
dalvik.system.NativeStart.main(Native Method)
09-01 15:27:57.748: E/AndroidRuntime(865): Caused by: android.view.InflateException: Binary XML
file line #2: Error inflating class fragment
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
android.view.LayoutInflater.inflate(LayoutInflater.java:466)
android.view.LayoutInflater.inflate(LayoutInflater.java:396)
android.view.LayoutInflater.inflate(LayoutInflater.java:352)
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
android.app.Activity.setContentView(Activity.java:1867)
android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
android.support.v7.app.ActionBarActivityDelegateICS.setContentView
(ActionBarActivityDelegateICS.java:110)
android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
myapp.MainActivity.onCreate(MainActivity.java:14)
android.app.Activity.performCreate(Activity.java:5008)
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
09-01 15:27:57.748: E/AndroidRuntime(865): ... 11 more
09-01 15:27:57.748: E/AndroidRuntime(865): Caused by: java.lang.IllegalStateException:
The meta- data tag in your app's AndroidManifest.xml does not have the right value.
Expected 5089000 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" />
com.google.android.gms.common.GooglePlayServicesUtil.A(Unknown Source)
com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable
(Unknown Source)
com.google.android.gms.maps.internal.u.I(Unknown Source)
com.google.android.gms.maps.internal.u.H(Unknown Source)
com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
com.google.android.gms.maps.MapFragment$b.jz(Unknown Source)
com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
com.google.android.gms.dynamic.a.a(Unknown Source)
com.google.android.gms.dynamic.a.onInflate(Unknown Source)
com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
android.app.Activity.onCreateView(Activity.java:4663)
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
09-01 15:27:57.748: E/AndroidRuntime(865): ... 23 more
mmmh... Change
<meta-data android:name="com.google.android.gms.version" android:value="4030500" />
to
<meta-data android:name="com.google.android.gms.version" android:value="5089000" />
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<permission
android:name="com.myapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.myapp.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.myapp."Your activity name""
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="Your map key" />
</application>
</manifest>
Add the below permission to your Manifest.xml
<permission android:name="com.myapp.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
and replaca the below line:
<uses-permissionandroid:name="com.myapp.providers.gsf.permission.
READ_GSERVICES"/>
via
<uses-permission android:name="com.myapp.providers.gsf.permission.
READ_GSERVICES"/>

Why my app chash when i put Fragment for Google Maps

I tried to run a google map aplication but when i put a map Fragmet in my xml file the app stops. I think the problem is with the fragment map because when i run the app without it, for example add just a button runs perfectly, i also put the manifest to review
here is my java code:
public class Activity2 extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity2);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity2, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_activity2,
container, false);
return rootView;
}
}
}
Here is my 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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.tutorialgooglemaps.Activity2$PlaceholderFragment" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
and myLOGCAT
03-14 00:47:38.619: E/AndroidRuntime(3717): FATAL EXCEPTION: main
03-14 00:47:38.619: E/AndroidRuntime(3717): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tutorialgooglemaps/com.example.tutorialgooglemaps.Activity2}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
03-14 00:47:38.619: E/AndroidRuntime(3717): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
03-14 00:47:38.619: E/AndroidRuntime(3717): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
03-14 00:47:38.619: E/AndroidRuntime(3717): at android.app.ActivityThread.access$600(ActivityThread.java:128)
03-14 00:47:38.619: E/AndroidRuntime(3717): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
03-14 00:47:38.619: E/AndroidRuntime(3717): at android.os.Handler.dispatchMessage(Handler.java:99)
03-14 00:47:38.619: E/AndroidRuntime(3717): at android.os.Looper.loop(Looper.java:137)
03-14 00:47:38.619: E/AndroidRuntime(3717): at android.app.ActivityThread.main(ActivityThread.java:4517)
03-14 00:47:38.619: E/AndroidRuntime(3717): at java.lang.reflect.Method.invokeNative(Native Method)
03-14 00:47:38.619: E/AndroidRuntime(3717): at java.lang.reflect.Method.invoke(Method.java:511)
03-14 00:47:38.619: E/AndroidRuntime(3717): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
03-14 00:47:38.619: E/AndroidRuntime(3717): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
03-14 00:47:38.619: E/AndroidRuntime(3717): at dalvik.system.NativeStart.main(Native Method)
03-14 00:47:38.619: E/AndroidRuntime(3717): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
03-14 00:47:38.619: E/AndroidRuntime(3717): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
03-14 00:47:38.619: E/AndroidRuntime(3717): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
03-14 00:47:38.619: E/AndroidRuntime(3717): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-14 00:47:38.619: E/AndroidRuntime(3717): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-14 00:47:38.619: E/AndroidRuntime(3717): at com.example.tutorialgooglemaps.Activity2$PlaceholderFragment.onCreateView(Activity2.java:59)
03-14 00:47:38.619: E/AndroidRuntime(3717): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
03-14 00:47:38.619: E/AndroidRuntime(3717): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
03-14 00:47:38.619: E/AndroidRuntime(3717): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
03-14 00:47:38.619: E/AndroidRuntime(3717): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
03-14 00:47:38.619: E/AndroidRuntime(3717): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
03-14 00:47:38.619: E/AndroidRuntime(3717): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:570)
03-14 00:47:38.619: E/AndroidRuntime(3717): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1137)
03-14 00:47:38.619: E/AndroidRuntime(3717): at android.app.Activity.performStart(Activity.java:4480)
03-14 00:47:38.619: E/AndroidRuntime(3717): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1943)
03-14 00:47:38.619: E/AndroidRuntime(3717): ... 11 more
03-14 00:47:38.619: E/AndroidRuntime(3717): 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-14 00:47:38.619: E/AndroidRuntime(3717): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
03-14 00:47:38.619: E/AndroidRuntime(3717): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
03-14 00:47:38.619: E/AndroidRuntime(3717): at com.google.android.gms.maps.internal.q.v(Unknown Source)
03-14 00:47:38.619: E/AndroidRuntime(3717): at com.google.android.gms.maps.internal.q.u(Unknown Source)
03-14 00:47:38.619: E/AndroidRuntime(3717): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
03-14 00:47:38.619: E/AndroidRuntime(3717): at com.google.android.gms.maps.SupportMapFragment$b.ex(Unknown Source)
03-14 00:47:38.619: E/AndroidRuntime(3717): at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
03-14 00:47:38.619: E/AndroidRuntime(3717): at com.google.android.gms.dynamic.a.a(Unknown Source)
03-14 00:47:38.619: E/AndroidRuntime(3717): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
03-14 00:47:38.619: E/AndroidRuntime(3717): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
03-14 00:47:38.619: E/AndroidRuntime(3717): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
03-14 00:47:38.619: E/AndroidRuntime(3717): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
03-14 00:47:38.619: E/AndroidRuntime(3717): ... 24 more
here is the manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tutorialgooglemaps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<permission
android:name="org.example.ejemplogooglemaps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="org.example.ejemplogooglemaps.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_NETWORK_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-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.tutorialgooglemaps.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="AIzaSyDrcKDGxUgl0Ps4u2ptOsIUCI6ooXmZ0RU" />
<activity
android:name="com.example.tutorialgooglemaps.Activity2"
android:label="#string/title_activity_activity2" >
</activity>
</application>
</manifest>
Your logcat clearly said
03-14 00:47:38.619: E/AndroidRuntime(3717): 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" />
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
Update: build your manifest.xml like:
....<application>
..............
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDrcKDGxUgl0Ps4u2ptOsIUCI6ooXmZ0RU" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>

Android map loading error

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>

Android Maps V2 App Crashing

I have made an app that uses Google Android Maps API V2 and I have followed every step in the guide provided by Google but it doesn't work unfortunely and it crashes every time I try to start it up. So I'm wondering what is the problem?
MainActivity.java
package com.android.maptest;
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);
}
}
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"
android:name="com.google.android.gms.maps.MapFragment"/>
Maptest Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.maptest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="16" />
<permission
android:name="com.android.maptest.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.android.maptest.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:debuggable="true" >
<activity
android:name="com.android.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="api_key" />
</application>
</manifest>
Logcat
03-12 09:46:13.150: D/AndroidRuntime(1547): Shutting down VM
03-12 09:46:13.150: W/dalvikvm(1547): threadid=1: thread exiting with uncaught exception (group=0x410e22a0)
03-12 09:46:13.155: E/AndroidRuntime(1547): FATAL EXCEPTION: main
03-12 09:46:13.155: E/AndroidRuntime(1547): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.maptest/com.android.maptest.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
03-12 09:46:13.155: E/AndroidRuntime(1547): at
android.app.ActivityThread.access$600(ActivityThread.java:140)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.os.Handler.dispatchMessage(Handler.java:99)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.os.Looper.loop(Looper.java:137)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.ActivityThread.main(ActivityThread.java:4898)
03-12 09:46:13.155: E/AndroidRuntime(1547): at java.lang.reflect.Method.invokeNative(Native Method)
03-12 09:46:13.155: E/AndroidRuntime(1547): at java.lang.reflect.Method.invoke(Method.java:511)
03-12 09:46:13.155: E/AndroidRuntime(1547): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
03-12 09:46:13.155: E/AndroidRuntime(1547): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
03-12 09:46:13.155: E/AndroidRuntime(1547): at dalvik.system.NativeStart.main(Native Method)
03-12 09:46:13.155: E/AndroidRuntime(1547): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-12 09:46:13.155: E/AndroidRuntime(1547): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.Activity.setContentView(Activity.java:1924)
03-12 09:46:13.155: E/AndroidRuntime(1547): at com.android.maptest.MainActivity.onCreate(MainActivity.java:11)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.Activity.performCreate(Activity.java:5206)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
03-12 09:46:13.155: E/AndroidRuntime(1547): ... 11 more
03-12 09:46:13.155: E/AndroidRuntime(1547): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.Fragment.instantiate(Fragment.java:584)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.Fragment.instantiate(Fragment.java:552)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.Activity.onCreateView(Activity.java:4849)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
03-12 09:46:13.155: E/AndroidRuntime(1547): ... 20 more
03-12 09:46:13.155: E/AndroidRuntime(1547): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
03-12 09:46:13.155: E/AndroidRuntime(1547): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
03-12 09:46:13.155: E/AndroidRuntime(1547): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
03-12 09:46:13.155: E/AndroidRuntime(1547): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
03-12 09:46:13.155: E/AndroidRuntime(1547): at android.app.Fragment.instantiate(Fragment.java:574)
03-12 09:46:13.155: E/AndroidRuntime(1547): ... 23 more
03-12 09:51:21.560: I/Process(1547): Sending signal. PID: 1547 SIG: 9
Here a blog post I wrote on how to integrate Google Maps into you application:
Creating Google Map Application
From your error it look like you did not perform correctly steps 2-3 of the blog guide,
for adding Google Play services library into your application.
If you follow carefully the steps written in the guide you will end up with the end result you can see at the end of the post.
I assumed that you have already get Google Maps Android API v2 key and have Google Play services. If you not have already installed it then please follow below steps to solve this problem_
Step 1. you can found it in Android SDK Manager under Extras tick check box of -Google Play services install it and after complete installation, restart your Eclipse.
Step 2. Add library named_ google-play-services_lib found under the extras folder of your Android SDK setup folder to your Android project_
Path of google service lib_
{Your_Android_SDK_direct}\extras\google\google_play_services\libproject\google-play-services_lib
Ex. Location of this lib on My system_
C:\Program Files\Android\android-sdk\extras\google\google_play_services\libproject\google-play-services_lib
I hope this will solve your ploblem.
For me adding:
import com.google.android.gms.maps.SupportMapFragment;
And changing the xml to
<fragment
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/header" />
resolved the problem. I hope you resolve it too!
Looks like you didn't add the Google Play Services library to your project.
It's located at {Android SDK}\extras\google\google_play_services
Add it as Android Library Project to Eclipse and then add it to your project.

Not allowed to start service Intent X without permission Y

04-25 14:16:30.931: E/AndroidRuntime(6638): FATAL EXCEPTION: main
04-25 14:16:30.931: E/AndroidRuntime(6638): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { (has extras) }} to activity {com.exclusive26.igale/com.exclusive26.igale.Push_Activity}: java.lang.SecurityException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.REGISTER pkg=com.google.android.gsf (has extras) } without permission com.google.android.c2dm.permission.RECEIVE
04-25 14:16:30.931: E/AndroidRuntime(6638): at android.app.ActivityThread.deliverResults(ActivityThread.java:2553)
04-25 14:16:30.931: E/AndroidRuntime(6638): at android.app.ActivityThread.handleSendResult(ActivityThread.java:2595)
04-25 14:16:30.931: E/AndroidRuntime(6638): at android.app.ActivityThread.access$2000(ActivityThread.java:121)
04-25 14:16:30.931: E/AndroidRuntime(6638): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:973)
04-25 14:16:30.931: E/AndroidRuntime(6638): at android.os.Handler.dispatchMessage(Handler.java:99)
04-25 14:16:30.931: E/AndroidRuntime(6638): at android.os.Looper.loop(Looper.java:130)
04-25 14:16:30.931: E/AndroidRuntime(6638): at android.app.ActivityThread.main(ActivityThread.java:3701)
04-25 14:16:30.931: E/AndroidRuntime(6638): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 14:16:30.931: E/AndroidRuntime(6638): at java.lang.reflect.Method.invoke(Method.java:507)
04-25 14:16:30.931: E/AndroidRuntime(6638): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
04-25 14:16:30.931: E/AndroidRuntime(6638): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
04-25 14:16:30.931: E/AndroidRuntime(6638): at dalvik.system.NativeStart.main(Native Method)
04-25 14:16:30.931: E/AndroidRuntime(6638): Caused by: java.lang.SecurityException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.REGISTER pkg=com.google.android.gsf (has extras) } without permission com.google.android.c2dm.permission.RECEIVE
04-25 14:16:30.931: E/AndroidRuntime(6638): at android.app.ContextImpl.startService(ContextImpl.java:867)
04-25 14:16:30.931: E/AndroidRuntime(6638): at android.content.ContextWrapper.startService(ContextWrapper.java:336)
04-25 14:16:30.931: E/AndroidRuntime(6638): at com.google.android.c2dm.C2DMessaging.register(C2DMessaging.java:54)
04-25 14:16:30.931: E/AndroidRuntime(6638): at com.exclusive26.igale.Push_Activity.register(Push_Activity.java:124)
04-25 14:16:30.931: E/AndroidRuntime(6638): at com.exclusive26.igale.Push_Activity.onActivityResult(Push_Activity.java:58)
04-25 14:16:30.931: E/AndroidRuntime(6638): at android.app.Activity.dispatchActivityResult(Activity.java:3908)
04-25 14:16:30.931: E/AndroidRuntime(6638): at android.app.ActivityThread.deliverResults(ActivityThread.java:2549)
04-25 14:16:30.931: E/AndroidRuntime(6638): ... 11 more
The intent does have the proper permission in manifest:
MANIFEST:
<permission
android:name="com.exclusive26.igale.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.exclusive26.igale.permission.C2D_MESSAGE"/>
<uses-permission android:name="com.exclusive26.igale.c2dm.permission.RECEIVE"/>
...
...
<activity android:name=".Push_Activity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
...
...
<service android:name=".C2DMReceiver" />
<receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.exclusive26.igale" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<category android:name="com.exclusive26.igale" />
</intent-filter>
</receiver>
chk out the following code in Push_Activity.java :
com.google.android.c2dm.C2DMessaging.register( this, com.exclusive26.igale.Config.C2DM_SENDER );
parameters sent correctly (Push_Activity context and some email address <-- static final String)
inside C2DMessaging.register :
public static void register(Context context,
String senderId) {
Intent registrationIntent = new Intent(REQUEST_REGISTRATION_INTENT);
registrationIntent.setPackage(GSF_PACKAGE);
registrationIntent.putExtra(EXTRA_APPLICATION_PENDING_INTENT,
PendingIntent.getBroadcast(context, 0, new Intent(), 0));
registrationIntent.putExtra(EXTRA_SENDER, senderId);
context.startService(registrationIntent);
// TODO: if intent not found, notification on need to have GSF
}
in the startService() i get the exception. No idia how to solve this.
please shed some light on the subject. Many Thanx!
Just for future users with this error:
manifest file should look like this:
<permission
android:name="YOUR_PACKAGE.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="YOUR_PACKAGE.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
instead of
<permission
android:name="YOUR_PACKAGE.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="YOUR_PACKAGE.permission.C2D_MESSAGE" />
<uses-permission android:name="YOUR_PACKAGE.permission.RECEIVE" />
I spend about 5 hours to found out what was wrong in my project :)
Maybe I'm missing something but the error shows "com.google.android.c2dm.permission.RECEIVE" and the manifest contains "com.google.android.c2dm.permission.SEND" so I don't see a perfect match.
The code was correct. I created a new project, copied the code and no problem anymore
This error also can be provide, if we use some resource's names incorrectly in our Activity Java file. I also got the same error, but I did not use any services or permission yet. Problem was at onCreate() method with wrong resource id.

Categories

Resources