Why my map app crashes if I set maxSdkVersion in the WRITE_EXTERNAL_STORAGE permission?

后端 未结 3 1939
终归单人心
终归单人心 2021-02-06 16:34

I\'ve set my map following the instructions in this link. And set the WRITE_EXTERNAL_STORAGE permission in accordance with the recomended by the Official Android Do

相关标签:
3条回答
  • 2021-02-06 16:56

    The XML code provided in the link is for Android API 12 or later. Since your minSDKVersion is 8. Use this:

    <fragment
            android:id="@+id/map"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            class="com.google.android.gms.maps.SupportMapFragment" />
    

    Check here for more.

    0 讨论(0)
  • 2021-02-06 17:02

    I did some research around the maxSdkVersion. And I found the following

    From google http://developer.android.com/guide/topics/manifest/uses-sdk-element.html

    Warning: Declaring this attribute is not recommended. First, there is no need to set the attribute as means of blocking deployment of your application onto new versions of the Android platform as they are released. By design, new versions of the platform are fully backward-compatible. Your application should work properly on new versions, provided it uses only standard APIs and follows development best practices. Second, note that in some cases, declaring the attribute can result in your application being removed from users' devices after a system update to a higher API Level. Most devices on which your application is likely to be installed will receive periodic system updates over the air, so you should consider their effect on your application before setting this attribute.

    I have something like this in my current working google app

     <uses-sdk
        android:minSdkVersion="11"
        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.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" />
    
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    

    So if you really want, you can try put that maxSdkVersion in the note, unless its what google is documented in the above link.

    Hope this help

    0 讨论(0)
  • 2021-02-06 17:05

    If you check the link you've provided to the <uses-permission> documentation, you'll see that it states that:

    it's no longer necessary for your app to request the WRITE_EXTERNAL_STORAGE permission when your app wants to write to its own application-specific directories on external storage (the directories provided by getExternalFilesDir()).

    It would appear that the Maps API needs write access to other directories. And if you check the Specify permissions section of the other link you gave, it still lists the WRITE_EXTERNAL_STORAGE permission as required, with no mention of exception for API Level 19.


    After having checked many, many online resources with regard to the Maps API, Android API Level 19, and the restriction of the WRITE_EXTERNAL_STORAGE permission, I found no source or example that listed or referenced a working example using the Maps API with that permission restricted to API Level 18 and below. Again, I quote the link you've provided that says the permission is not needed in API Level 19 "when your app wants to write to its own application-specific directories on external storage". (I would point out that it merely says it is not necessary in that case, and in no way "recommends" that you set this restriction absolutely.) The Maps API needs write-permission to external storage directories that are not owned by your app. The fact that "without specifying the maxSdkVersion value, the app works properly" indicates that even in KitKat, Maps needs that permission. The error is telling you exactly that.

    0 讨论(0)
提交回复
热议问题