0
votes

I'm trying to add Google Maps v2 to an Mvx project by combining the Monodroid MapsAndLocationDemo_v2 with the N=26 Fraggle demo from NPlus1DaysOfMvvmCross.

I have added Google Play services to the Maps demo and am successfully displaying a map using:

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

With the Fraggle demo, the same fragment causes an Android.Views.InflateException error.

I have followed the same steps to add Google Play services to both projects, and am using the same AndroidManifest.xml file in both projects

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.demo.app" android:installLocation="auto" android:versionCode="1" android:versionName="1">
  <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />
  <application android:label="Demo"></application>
  <uses-feature android:glEsVersion="0x00020000" android:required="true" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <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="com.demo.app.permission.MAPS_RECEIVE" />
  <permission android:name="com.demo.app.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
  <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AAAAAAAAAAAAAAAAA-xxxxxxxxxxxxxxxxxxxxxx" />
</manifest>

Other than adding the fragment and updating the manifest, there are no changes to the Fraggle demo code. The working view from the Maps demo is

namespace SimpleMapDemo
{
    using Android.App;
    using Android.OS;
    using Android.Support.V4.App;

    [Activity(Label = "@string/basic_map")]
    public class BasicDemoActivity : FragmentActivity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.BasicDemo);
        }
    }
}

and the view from the Mvx version is:

using Android.App;
using Android.OS;
using Cirrious.MvvmCross.Droid.Fragging;
using Rock.Core.ViewModels;

namespace Rock.Droid.Views
{
    [Activity(Label = "View for FirstViewModel")]
    public class FirstView : MvxFragmentActivity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.FirstView);
        }
    }
}

I've also tried referencing the Google Play services dll from the working demo, and have the same results.

1
have you added the fraggle demo app's details to the maps api key in your api console?tony m
I did it the other way round, changed the fraggle app details to match the api key, but that should have the same effect.Neil

1 Answers

1
votes

Ah. It was a mistake in the AndroidManifest.xml file. The Maps API Key needs to be inside the application node. If it's not there, it causes an exception.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.demo.app" android:installLocation="auto" android:versionCode="1" android:versionName="1">
  <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />
  <application android:label="Demo">
    <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AAAAAAAAAAAAAAAAA-xxxxxxxxxxxxxxxxxxxxxx" />
  </application>
  <uses-feature android:glEsVersion="0x00020000" android:required="true" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <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="com.demo.app.permission.MAPS_RECEIVE" />
  <permission android:name="com.demo.app.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
</manifest>