Tha.Poox
Tha.Poox

Reputation: 119

google map android API V2 failure

Trying to add a Map into an Android application, I already created the API key and enabled Google Map Android V2; I added the permission, the google play services version and the API key in the manifest file. I also added the Google Plays Services lib in the project.

But when I launch the application it stops, I don't know why, I think it's something that has to do with the permissions, but just to make sure, I copy/Past the permissions as suggested by the Google Developpers website showing us how to add the map. But like I said, I'm not sure if this si the real deal. Here's my codes:

Manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="usthb.appusthb"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="19" />


<!-- ============  PERMISSIONS: ============ -->
<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"/>

 <!-- ============ END PERMISSIONS =============== -->
            <!-- this will notify the user that the device needs OpenGL ES version 2 to display the map (as recomanded from the google developpers website)-->
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Black.NoTitleBar" >
<!-- ====   google play services version:  ====  -->
    <meta-data
         android:name="com.google.android.gms.version"
         android:value="@integer/google_play_services_version" />

        <activity
            android:name="usthb.appusthb.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>

<!-- Google Map Android API V2 === ==== ===  API key:  -->
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyCfqonheoI9OG_REcsnl7-xgmpiFwu692I"/>

    </application>

</manifest>

MainLayout:

<?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"/>

MainActivity:

public class MainActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toast.makeText(this, "sup", 2000).show();
    }
}

Log:

02-17 10:50:11.928: E/AndroidRuntime(1356): FATAL EXCEPTION: main
02-17 10:50:11.928: E/AndroidRuntime(1356): Process: usthb.appusthb, PID: 1356
02-17 10:50:11.928: E/AndroidRuntime(1356): java.lang.RuntimeException: Unable to start activity ComponentInfo{usthb.appusthb/usthb.appusthb.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.os.Handler.dispatchMessage(Handler.java:102)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.os.Looper.loop(Looper.java:136)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.ActivityThread.main(ActivityThread.java:5017)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at java.lang.reflect.Method.invokeNative(Native Method)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at java.lang.reflect.Method.invoke(Method.java:515)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at dalvik.system.NativeStart.main(Native Method)
02-17 10:50:11.928: E/AndroidRuntime(1356): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.Activity.setContentView(Activity.java:1929)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at usthb.appusthb.MainActivity.onCreate(MainActivity.java:12)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.Activity.performCreate(Activity.java:5231)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
02-17 10:50:11.928: E/AndroidRuntime(1356):     ... 11 more
02-17 10:50:11.928: E/AndroidRuntime(1356): 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:
02-17 10:50:11.928: E/AndroidRuntime(1356): <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
02-17 10:50:11.928: E/AndroidRuntime(1356):     at maps.af.ch.a(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at maps.af.ay.a(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at maps.af.ay.a(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at maps.af.al.a(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at maps.af.bg.a(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at maps.af.bf.a(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at ebt.onTransact(SourceFile:107)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.os.Binder.transact(Binder.java:361)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at com.google.android.gms.maps.MapFragment$a.onCreateView(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at com.google.android.gms.dynamic.a$4.b(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at com.google.android.gms.dynamic.a.a(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at com.google.android.gms.dynamic.a.onCreateView(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at com.google.android.gms.maps.MapFragment.onCreateView(Unknown Source)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.Fragment.performCreateView(Fragment.java:1700)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:866)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1040)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1142)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.app.Activity.onCreateView(Activity.java:4786)
02-17 10:50:11.928: E/AndroidRuntime(1356):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
02-17 10:50:11.928: E/AndroidRuntime(1356):     ... 20 more

Upvotes: 1

Views: 89

Answers (1)

Raghunandan
Raghunandan

Reputation: 133560

Change this

 android:name="com.google.android.gms.maps.MapFragment"/>

to

 android:name="com.google.android.gms.maps.SupportMapFragment"/>

since your min sdk is 11. So you need to use SupportMapFragment. For 12 and above use MapFragment.

Upvotes: 1

Related Questions