2

I have created a minimal example that demos the problem in this question

https://github.com/dbachelder/MNCMapTest

I ran into this issue in a real app, but created this project to demo the minimal example.

The project was created with Android Studio 1.3.1

It was a "Google Maps Activity" project targeting MNC.

The only change I made was changing

compile 'com.android.support:appcompat-v7:23.+'

to

compile 'com.android.support:appcompat-v7:22.+'

as 23.+ doesn't seem to exist yet... (not sure why it's used by the project creation wizard)

On start up this exception is seen.

 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.WRITE_EXTERNAL_STORAGE"/>
        at com.google.maps.api.android.lib6.d.t.a(Unknown Source)
        at com.google.maps.api.android.lib6.d.ft.a(Unknown Source)
        at com.google.maps.api.android.lib6.d.aj.a(Unknown Source)
        at com.google.maps.api.android.lib6.d.ai.a(Unknown Source)
        at com.google.android.gms.maps.internal.x.onTransact(SourceFile:107)
        at android.os.Binder.transact(Binder.java:387)
        at com.google.android.gms.maps.internal.IMapFragmentDelegate$zza$zza.onCreateView(Unknown Source)
        at com.google.android.gms.maps.SupportMapFragment$zza.onCreateView(Unknown Source)
        at com.google.android.gms.dynamic.zza$4.zzb(Unknown Source)
        at com.google.android.gms.dynamic.zza.zza(Unknown Source)
        at com.google.android.gms.dynamic.zza.onCreateView(Unknown Source)
        at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
        at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:924)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1116)
        at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1218)
        at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2170)
        at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:300)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
        ... 19 more

as you can see in the manifest:

https://github.com/dbachelder/MNCMapTest/blob/master/app/src/main/AndroidManifest.xml

The permission in question is there.

The emulator is running the latest version of M.

Is there something I am missing to get maps to play nice in M? Like ask for the permission before I inflate the layout containing the map? Or am I just jumping the gun and I need to wait a bit longer for all of this to be ready for testing?

That seems like an annoying limitation to have to ask for the storage permission at startup for apps built around the map.

UPDATE: there is now a branch of the project that works.. here is the diff: https://github.com/dbachelder/MNCMapTest/pull/1/files

danb
  • 10,239
  • 14
  • 60
  • 76

3 Answers3

3

Is there something I am missing to get maps to play nice in M?

WRITE_EXTERNAL_STORAGE is now a dangerous permission, as of v2 of MNC. Not only do you have to have it in the manifest, but you need to request it from the user at runtime. The process for this is (somewhat) covered in the developer preview documentation.

As a stopgap measure, you should be able to go into your app's page in Settings and manually toggle this permission on, though I haven't tried that.

Like ask for the permission before I inflate the layout containing the map?

Yes, you will need to request (and get) the permission from the user before you attempt to invoke any code that requires that permission. That probably means before you attempt to do anything with Maps V2.

Or am I just jumping the gun and I need to wait a bit longer for all of this to be ready for testing?

Oh, well, there could be bugs too, but your sample app is not requesting the permission at runtime, so I'd start there.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • This is what I was worried about... I will add the permission check. I was just hoping that was not correct as having an app that opens immediately asking for a permission that seems completely unrelated to the task at hand (from the user's perspective) is going to be a bad experience. – danb Aug 13 '15 at 18:43
  • 1
    @danb: "that seems completely unrelated to the task at hand" -- you are certainly welcome to show some UI before asking for the permission, such as some rationale for why you need it. You will want such a UI anyway to handle that case where the user says "no". However, Google's attitude seems to be, for permissions that are essential for app operation, you just ask for them up front, with no explanation, and figure that the user will get used to it. – CommonsWare Aug 13 '15 at 18:48
  • According to some comments from Ian Lake and elsewhere, the Google Maps API should work without WRITE_EXTERNAL_STORAGE (though its caching is obviously restricted) - has anyone managed to get it working with Play Services 7.+ ? – Estel Aug 19 '15 at 09:31
  • For future reference, according to Ian Lake here https://plus.google.com/u/0/+KirillRakhman/posts/g6NASCPxefm app developers need to check/request map api's permissions for now. – dvd Aug 28 '15 at 21:09
1

Update for weary travelers in the near future, I encountered the same problem, ended up moving from MapView to SupportMapFragment (due to the need to delay initializing MapView until external storage permission is granted, with SupportMapFragment you don't have to dispatch the lifecycle callbacks).

It was fairly straightforward (bit complicated for us due to our use of child fragment managers, but nothing insurmountable), except you have to handle fragment restore state case carefully: say user granted permission, map is showing, background app go to settings to revoke permission. Come back to app, framework is going to restore the old fragments + UI states, since map fragment was in the UI stack before, map fragment now created and crash when it gets to SupportMapFragment#onCreateView due to no permission.

dvd
  • 1,470
  • 1
  • 16
  • 24
0

I have it on good authority that this will not be an issue by the time M is live. GPS will be updated to not require this permission for maps in the near future so the only time you will have to bother with this issue is in this interim phase.

danb
  • 10,239
  • 14
  • 60
  • 76
  • Thanks, but 'good authority' from an internet forum isn't exactly something you want to base development decisions on :( – dvd Sep 04 '15 at 17:32
  • I know the difference between good authority and an internet forum. Trust me, this is good information. – danb Sep 07 '15 at 22:21