标签: android-12

Android 12 蓝牙权限

我正在尝试使用 BLE 连接到设备,但在 Android 12 上遇到错误。我尝试了很多不同的方法,但找不到任何解决方案。如何请求蓝牙权限?

AndroidManifest.xml

 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 <uses-permission android:name="android.permission.BLUETOOTH"
        android:maxSdkVersion="30" />
 <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
        android:maxSdkVersion="30" />
 <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
 <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
 <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

 <uses-feature android:name="android.hardware.bluetooth_le"
        android:required="true" />

 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Run Code Online (Sandbox Code Playgroud)

和权限请求代码

private static final String[] BLE_PERMISSIONS = new String[]{
            Manifest.permission.ACCESS_COARSE_LOCATION,
            Manifest.permission.ACCESS_FINE_LOCATION,
    };
    
private static final String[] ANDROID_12_BLE_PERMISSIONS = new String[]{
            Manifest.permission.BLUETOOTH_SCAN,
            Manifest.permission.BLUETOOTH_CONNECT,
            Manifest.permission.ACCESS_FINE_LOCATION,
    };

public static void requestBlePermissions(Activity activity, int requestCode) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
        ActivityCompat.requestPermissions(activity, ANDROID_12_BLE_PERMISSIONS, requestCode);
    else
        ActivityCompat.requestPermissions(activity, BLE_PERMISSIONS, requestCode); …
Run Code Online (Sandbox Code Playgroud)

permissions android bluetooth bluetooth-lowenergy android-12

7
推荐指数
2
解决办法
3万
查看次数

Flutter 应用在​​ Android 12 上启动时崩溃

我在 Google Play 上发布了一个应用程序,并且经常使用。在上次更新中,我将compileSdkVersion和targetSdkVersion都发布到了31。

我发现 Android 版本低于 12 的用户在使用应用程序时不会遇到任何问题,而 Android 版本 12 的用户在尝试打开应用程序时会遇到应用程序崩溃的情况。

这是我从 Google Play 商店收到的消息:

在此输入图像描述

有人遇到过类似的问题吗?如有任何建议,将不胜感激!

crash android flutter android-12

7
推荐指数
1
解决办法
1万
查看次数

在 Android 12 上未收到 Firebase 推送通知

我的 Xamarin.Android 应用程序的推送通知仅适用于 Android 11 (Pixel 3 XL)。目前,我的应用程序针对的是 Android 11,但它也可以在 Android 12 (Pixel 6 Pro) 上运行。唯一不起作用的是 Firebase 推送通知。下面是我正在使用的代码。在过去的一周里,我一直在研究这个问题,并看到了有关 Android 12 (Pixel 6) 未收到推送通知的特定问题的帖子。我按照其他人的建议对手机配置进行了更改,另一个应用程序通知开始工作,但我的仍然没有。任何想法都会有所帮助。谢谢。

 if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                // Notification channels are new in API 26 (and not a part of the
                // support library). There is no need to create a notification
                // channel on older versions of Android.


                var name = "NameOfChannel";
                var description = "Notification Channel";
                var channel = new NotificationChannel(CHANNEL_ID, name, NotificationImportance.Max)
                {
                    Description = description …
Run Code Online (Sandbox Code Playgroud)

android pixel xamarin google-cloud-firestore android-12

7
推荐指数
2
解决办法
6193
查看次数

Android 12 启动画面 API 无法与 Material 组件配合使用

我一直在关注文档,但不幸的是它不包括使用材质组件作为应用程序整体主题时的适应。

<style name="Theme.App" parent="Theme.MaterialComponents.DayNight">
    <!-- Primary brand color. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryVariant">@color/colorPrimaryDark</item>
    <item name="colorOnPrimary">@android:color/white</item>
    <!-- Secondary brand color. -->
    <item name="colorSecondary">@color/colorPrimary</item> <!--Fab color-->
    <item name="colorOnSecondary">@color/colorAccent</item> <!--Fab icon color-->
    <item name="colorSecondaryVariant">@color/colorAccentDark</item>
    <!-- Status bar color. -->
    <item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
    <!-- Customize your theme here. -->
    <!--<item name="tabStyle">@style/AppTabLayout</item>-->
    <!-- The color for all other text including the menu -->
    <item name="android:textColor">@color/colorPrimary</item>
    <item name="android:textColorHighlight">@color/colorAccentDark</item>
    <item name="android:windowAnimationStyle">@style/WindowAnimationTransition</item>

    <item name="checkboxStyle">@style/AppCheckBoxStyle</item>
    <item name="popupMenuBackground">@drawable/popup_bg_rounded</item>
    <item name="materialAlertDialogTheme">@style/AppDialogTheme</item>

    <item name="autoCompleteTextViewStyle">@style/AppCursor</item>

    <item name="overlapAnchor">false</item>
    <item name="android:dropDownVerticalOffset">?attr/actionBarSize</item>

    <item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
</style>

<style …
Run Code Online (Sandbox Code Playgroud)

android material-components-android android-12 android-splashscreen

7
推荐指数
1
解决办法
2719
查看次数

在 Android 12 中运行深度链接需要进行哪些更改

我的应用程序的深度链接功能在 Android 11 上运行良好。但在 Android 12 中却不起作用。我检查并关注了几篇 StackOverflow 帖子和其他一些博客。但我在应用程序详细信息中未选中链接

在此输入图像描述

如果我手动检查它,深层链接就会起作用。

我尝试使用文档进行手动验证并收到legacy_failure错误。 https://developer.android.com/training/app-links/verify-site-associations#manual-verification

我也关注了这个网址https://doordash.engineering/2022/01/25/your-deep-links-might-be-broken-web-intents-and-android-12/comment-page-1/?unapproved= 40015&适度哈希=dc9e7df0845c5072330edc78f75ca497#comments

android deep-linking android-manifest android-deep-link android-12

7
推荐指数
1
解决办法
7252
查看次数

当应用程序在后台运行时,Android 12 firebase 推送通知不起作用

我正在从firebase>compose notification page发送测试推送通知。我在 Android 8、9、10、11 上收到推送通知,但在 12 上则没有。

我有两台运行 Android 12 的设备:实体手机 Samsung S22 和 Pixel 模拟器。在这两种情况下,推送通知都不会出现在通知托盘中。

笔记:

  • 我说的是当应用程序在后台运行时系统在通知托盘中显示的通知。当应用程序位于前台时,onMessageReceived 在 Android 12 上按预期工作。
  • 令牌是正确的
  • 在所有情况下,我都会关闭应用程序以便在通知托盘中推送
  • 如果我使用android:exported="false"- 仍然不起作用

我在 android 清单中的服务:

        <service
            android:name=".old.push.FCMHandlerService"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
Run Code Online (Sandbox Code Playgroud)

push-notification firebase firebase-cloud-messaging android-12

7
推荐指数
1
解决办法
9216
查看次数

尽管使用 NoActionBar 主题,Android 上的操作栏仍然显示

我正在为我的 Android 应用程序使用主题Theme.MaterialComponents.DayNight.NoActionBar( docs )。

我也在getActionBar().hide()MainActivity 中调用。

在我的几乎所有设备上,操作栏都没有显示。然而,在一台设备(运行 Android 12 的 Pixel 6)上,我仍然看到操作栏。我确信我已经安装了最新版本的应用程序。

你知道为什么操作栏仍然挂在这一台设备上吗?

android android-actionbar google-pixel android-12

7
推荐指数
1
解决办法
360
查看次数

找不到 windowSplashScreenAnimatableIcon

我想在 Android 12 上自定义启动屏幕,但收到 AAPT 错误:

AAPT: error: style attribute 'android:attr/windowSplashScreenAnimatableIcon' not found.
Run Code Online (Sandbox Code Playgroud)

这是样式的相关部分:

AAPT: error: style attribute 'android:attr/windowSplashScreenAnimatableIcon' not found.
Run Code Online (Sandbox Code Playgroud)

这就是文档中提到的属性。

以下是我正在使用的构建工具库的概述:

compileSdk="android-S"
minSdk=21
targetSdk="S"
buildTools='31.0.0-rc4'
Run Code Online (Sandbox Code Playgroud)

我使用 Android Studio 北极狐 | 2020.3.1 Beta 1 仅供记录。

有人可以指出我做错了什么吗?

android splash-screen styling android-12

6
推荐指数
1
解决办法
1万
查看次数

如何在 Android 12 SplashScreen 中使用或选择退出

Android 12 中的新 API SplashScreen看起来不错,但就像之前文档中的示例代码一样,并没有真正帮助解释整个正确的实现。在某些情况下,您可能会在启动画面期间执行某些任务,在我们的情况下,这是启动 Firebase Auth,因此最好的方法可能只是选择不使用这个新的特色 API,但根据 lint 警告,它似乎是强制性的并且没有办法选择退出。

应用程序不应提供自己的启动屏幕

应用程序定义的启动画面从 Android 12 (API 31+) 开始,应用程序的启动画面由系统提供,应用程序不应创建自己的启动画面,否则用户将看到两个启动画面。请检查 SplashScreen 类以检查如何控制和自定义启动画面。

旧设备的向后兼容性如何,如何处理?是否有任何代码实验室项目可以玩和测试?

android splash-screen android-12

6
推荐指数
2
解决办法
1561
查看次数

Android 12 - 存储访问框架/范围存储不再工作

Android 12最近在一些手机上发布,一些用户开始抱怨存储访问:他们无法再向应用程序授予对特定文件夹的访问权限(例如“下载”文件夹)。

该消息表示:“无法使用此文件夹。为了保护您的隐私,请选择其他文件夹”。

这个问题很容易重现,我花了一些时间寻找解决方案,但找不到一个简单的解决方案。

问题图片

似乎唯一的解决方法是要求完全存储访问(但这不是我想要做的,这很糟糕)或要求用户创建一个新文件夹,这将是用户体验的绝对痛苦。

我不明白的是:Google 是否在没有任何文档的情况下就在 Android 12 上弃用了 SAF?这是一个错误还是一个功能?我真的很困惑那里。Android 11 的迁移已经很痛苦了,现在恐怕 12 会变得更加痛苦。

这是代码,但没什么特别的:

    /*
    * Requests Scoped Storage access authorization
    */
    @RequiresApi(Build.VERSION_CODES.Q)
    @JvmStatic
    fun requestScopedStorageAccess(activity: Activity, requestCode: Int) {
        val storageManager = activity.getSystemService(Context.STORAGE_SERVICE) as StorageManager
        val intent = storageManager.primaryStorageVolume.createOpenDocumentTreeIntent()
        activity.startActivityForResult(intent, requestCode)
    }
Run Code Online (Sandbox Code Playgroud)

我认为值得注意的是,一切都在 Android 10 和 11 上完美运行,因此问题确实与 Android 12 有关。

storage android storage-access-framework scoped-storage android-12

6
推荐指数
1
解决办法
5120
查看次数