Issue
I have been stuck over a day to use the Google Play Service. This is a very bad procedure created by Google. Why it is that difficult??
I want to use Google Play Service in order to develop some apps which depends on the Map. I have been tried everything step by step, discussed on many sites but still unable to get it. I thought only the StackOverflow can help in this situation. I can't give the link of all the reference websites but i am giving some of them-
http://developer.android.com/google/play-services/setup.html#Setup
http://www.vogella.com/tutorials/AndroidGoogleMaps/article.html#installmaps
Setup Google Play Games Services
I am using Eclipse ADT Bundle. Google Play Service has a mark with a tick in Android SDK which indicates that it is installed. It is also foud in the proper directory. I am providing the snapshot of my project-
The above snoapshot shows the activity_main.xml, Errors while Launching the application and Project Tree Structure. It also shows that google_play_service_lib has been imported.
public class MainActivity extends ActionBarActivity {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
The Project is not contain any error. I've also added the code into the proguard-project.txt and the android-manifest.xml is
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.latlongfrommap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="19" />
<uses-permission android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.latlongfrommap.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="AIzaSyAQXXXXXXXXXXXXXXpADfMsO4fF0eEXdRE" />
</application>
Also I've been generated the API Key from the console.Graphical layout of activity-main is also has an warning.
Please Help me out by your valuable advise. Thanking you.
EDIT:
In the official set up guide, they didn't mention that jar file should be added to the library.. I did that because I found it in many websites.. is It correct??.. The fragment tag is not detected by the activity_main.xml.. is there any problem with that??
Yes, I was right about the jar file. It should not be added. It was creating some kind of conflict. But I still have errors
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.latlongfrommap/com.example.latlongfrommap.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2314)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2388)
at android.app.ActivityThread.access$800(ActivityThread.java:148)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5312)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
at android.app.Activity.setContentView(Activity.java:2154)
at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
at com.example.latlongfrommap.MainActivity.onCreate(MainActivity.java:25)
at android.app.Activity.performCreate(Activity.java:5953)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1128)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2267)
... 10 more
Caused by: java.lang.SecurityException: The Maps API requires the additional following permissions to be set in the AndroidManifest.xml to ensure a correct behavior:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
at com.google.maps.api.android.lib6.c.ck.a(Unknown Source)
at com.google.maps.api.android.lib6.c.i.a(Unknown Source)
at com.google.maps.api.android.lib6.c.el.a(Unknown Source)
at com.google.maps.api.android.lib6.c.ab.a(Unknown Source)
at com.google.maps.api.android.lib6.c.aa.a(Unknown Source)
at com.google.android.gms.maps.internal.x.onTransact(SourceFile:107)
at android.os.Binder.transact(Binder.java:380)
at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
at com.google.android.gms.maps.MapFragment$a.onCreateView(Unknown Source)
at com.google.android.gms.dynamic.a$4.b(Unknown Source)
at com.google.android.gms.dynamic.a.a(Unknown Source)
at com.google.android.gms.dynamic.a.onCreateView(Unknown Source)
at com.google.android.gms.maps.MapFragment.onCreateView(Unknown Source)
at android.app.Fragment.performCreateView(Fragment.java:2053)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:870)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1045)
at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1147)
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2118)
at android.app.Activity.onCreateView(Activity.java:5302)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
... 23 more
Solution
Thank God. Finally it's done. Many websites said that, after doing all the stuff describing at the official tutorial site you need to do some extra things. Some of them are really helpful and some are not. Before you waste your complete day like me, remember the below things-
- "you have to add the google-play-services.jar externally to the library". That's entirely NOT TRUE. If you have already imported the
google-play-services_lib
project which is the first step of the official guide and again adding the jar, it will create a conflict to your program. So either you add the jar or import thegoogle-play-services_lib
project. Generate
API Key
usingGoogle Developers Console
. This step is really important and make sure the key has been attached to your manifest using meta tag.<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyAQ8XXXXXXXXXXXXXXXXXxxxxxxeEXdRE" />
To generate the key you'll need to know the package name of the project and SHA1 fringerprint which can be found by clicking the window -> Preferences -> Android -> Build.
3. You have to add some permissions
<uses-permission android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Before you do the step 4 of the official guide, you need to add the value into the
string.xml
which can be found atres/values
directory of your project tree.<integer name="google_play_services_version">5089000</integer>
where the version number can be found insdk\extras\google\google_play_services\libproject\google-play-services_lib\res\values\version.xml
the
<fragment>
tag ofactivity-main.xml
may show you some awkward warning. Don't worry about it.Make sure that the Android Private Libraries option in Order & Export is checked. It actually link the
google-play-services_lib
project which consists all the libraries. To do that:Properties -> Build Path -> Order and Export -> check Android Private Libraries
Last but not least you have to clean your project before doing anything. To do so, goto project->clean and make sure that the
Build Automatically
is checked.
Answered By - Somnath Kayal
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.