简体   繁体   English

Android - map map 在一台设备上是空白的,在其他设备上不是

[英]Android - map map is blank on one device, not others

Hoping someone can help with this.希望有人可以帮助解决这个问题。 I have a map fragment in my Android app, but on one physical device (Android 11 with the Feb 2022 security update) it always comes up blank.我的 Android 应用程序中有一个 map 片段,但在一台物理设备(具有 2022 年 2 月安全更新的 Android 11)上,它总是空白。 On another device (Android 8), and on Android 11 and Android 12 AVDs, the maps display just fine.在另一台设备 (Android 8) 以及 Android 11 和 Android 12 AVD 上,地图显示得很好。 I'm not seeing anything in logcat (such as an authentication issue from an invalid key or lack of permission) it just...never renders.我在 logcat 中没有看到任何内容(例如来自无效密钥或缺乏权限的身份验证问题)它只是......从不呈现。

Interestingly, it does respond to long-clicks (presses) with appropriate latitude/longitudes.有趣的是,它确实以适当的纬度/经度响应长按(按下)。 I'm just long-pressing blindly to get them.我只是盲目地长按以获取它们。

For reference - my layout is:供参考 - 我的布局是:

    ...
    <androidx.fragment.app.FragmentContainerView
        xmlns:tools="http:`//schemas.android.com/tools"
        android:id="@+id/mfbMap"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".ActFlightMap" />
    ....

The relevant manifest sections:相关清单部分:

    <application ...>
        ...
        <uses-library
            android:name="com.google.android.maps"
            android:required="false" />
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="@string/GoogleMapsKey" />
    </application>
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

And my main code:我的主要代码:

class ActFlightMap : AppCompatActivity(), OnMapReadyCallback,
    OnMarkerClickListener, OnGlobalLayoutListener,  OnMapLongClickListener, CoroutineScope by MainScope() {
   ...
   public override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.flightmap)

        val mf = supportFragmentManager.findFragmentById(R.id.mfbMap) as SupportMapFragment?
        try {
            mf?.getMapAsync(this)
        } catch (ex: Exception) {
            Log.e("MyAppTag", Objects.requireNonNull(ex.localizedMessage))
        }
        ...
    }

    override fun onMapReady(googleMap: GoogleMap) {
        val map = googleMap

        map.mapType = GoogleMap.MAP_TYPE_HYBRID
        val settings = map.uiSettings
        settings.isCompassEnabled = false
        settings.isRotateGesturesEnabled = false
        settings.isScrollGesturesEnabled = true
        settings.isZoomControlsEnabled = false
        settings.isZoomGesturesEnabled = true

        map.setOnMapLongClickListener(this)
        ...
    }

In the above code, I can verify that onMapReady is in fact called and googleMap is non-null.在上面的代码中,我可以验证实际上调用了 onMapReady 并且 googleMap 是非空的。 I can add elements to the map. Long click (as mentioned above) works.我可以向 map 添加元素。长按(如上所述)有效。 Nothing mentioning maps in the logcat. logcat 中没有提及地图。 I even get the little "press to center on your current location" icon.我什至还看到了“按当前位置居中”这个小图标。 The tiles just never draw on my Android 11 phone, but it all works flawlessly in both the emulators and on my older (Android 8) phone.这些图块从不在我的 Android 11 手机上绘制,但它在模拟器和我的旧款 (Android 8) 手机上都能完美运行。

Thoughts?想法?

Turns out it was a theming issue.原来这是一个主题问题。

When this theme is applied to the hosting activity (ActFlightMap, above), it doesn't work:当此主题应用于托管活动(ActFlightMap,上面)时,它不起作用:

   <style name="MFBTheme" parent="Theme.AppCompat.DayNight">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:textColorPrimary">@color/textColorPrimary</item>
        <item name="android:background">@color/colorBackground</item>
        <item name="android:windowBackground">@color/colorBackground</item>
        <item name="android:colorBackground">@color/colorBackground</item>
    </style>

But if I simply change the theme in the manifest to use @style/Theme.AppCompat.DayNight, it works great on the devices that hadn't been working.但是,如果我只是将清单中的主题更改为使用@style/Theme.AppCompat.DayNight,那么它在无法正常工作的设备上效果很好。

No idea what the problem is with the theme above, or why it only impacts some devices.不知道上面的主题有什么问题,或者为什么它只影响某些设备。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM