由于Android 在 Android 12 中引入了不受信任的触摸事件,我的应用程序受到影响。如果我理解正确的话,问题主要是由于使用了该标志FLAG_NOT_TOUCHABLE,所以我删除了所有出现的事件
08-20 16:10:45.752 1716 2206 D InputDispatcher: Stack of obscuring windows during untrusted touch (705, 1575):
08-20 16:10:45.752 1716 2206 D InputDispatcher: * type=2038, package=xxxxxxx, id=204, mode=USE_OPACITY, alpha=1.00, frame=[0,145][1080,2296], touchableRegion=[0,145][1080,2296], window={36c5ada , flags={NOT_FOCUSABLE | NOT_TOUCHABLE | NOT_TOUCH_MODAL | LAYOUT_IN_SCREEN | FORCE_NOT_FULLSCREEN | HARDWARE_ACCELERATED}, inputFeatures={0x0}, hasToken=true, applicationInfo.name=, applicationInfo.token=<null>
Run Code Online (Sandbox Code Playgroud)
NOT_TOUCHABLE 标志仍然没有消失!目前关于这个主题只有一篇文章可用,我的案例属于本博客中的“不必要的大窗口”。即我的窗口已经存在wrap_content,并且我已经删除了任何出现的FLAG_NOT_TOUCHABLE. 我的触碰仍然被阻挡。否则我怎么知道我的触摸工作正常?正如developer.android网站所推荐的,当我运行以下命令时adb shell settings put global block_untrusted_touches 2,一切似乎都工作正常。任何帮助将不胜感激!
我发现多个消息来源称,从 2021 年底开始,当用户选择退出广告个性化时,Android 广告 ID 将在 Android 12 设备上不可用(它将是一串零)。好的来源之一是: https: //www.xda-developers.com/google-play-services-delete-ad-id-opt-out-personalization/
为了确保在 Android 12 设备上主动处理我的应用获利,我刚刚在 Pixel 4 设备(运行 Android 12 操作系统)上进行了验证,并且在选择退出广告个性化后我能够获取 Android 广告 ID。即使没有针对 API 31 (Android 12) 执行任何额外步骤,例如不添加 AD_ID 的任何额外权限。是否有明确的时间表,至少何时会对 Android 12 设备产生影响?这将有助于我们提前规划部署。
android android-permissions google-advertising-id android-12
在早于 Android 12 的 Android 版本上,我可以轻松构建带有未裁剪图像的启动屏幕。例如 Android 11 上是这样的:
然而,Android 12 引入了新的启动屏幕 API,我不知道如何在 Android 12 中重现上面的启动屏幕。它似乎总是被裁剪,在 Android 12 上结果如下:
这是我android/src/main/res/values/styles.xml的旧 Android 版本(例如 Android 11):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">@drawable/launch_background</item>
<item name="android:windowFullscreen">false</item>
</style>
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
这是我android/src/main/res/values-v31/styles.xml的 Android 12:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowSplashScreenAnimatedIcon">@drawable/launch_background</item>
<item name="android:windowFullscreen">false</item>
</style>
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
两者之间的唯一区别styles.xml是我用于android:windowSplashScreenAnimatedIconAndroid 12 和android:windowBackground旧版 Android 版本,如新启动屏幕 …
我正在开发一个使用 Android 画中画模式的应用程序。
MainActivity 有一个按钮,可以启动其他一些活动(只是向另一个活动触发意图)。当我进入 PIP 模式并展开 MainActivity 时会出现问题,现在当我单击按钮时,新 Activity 大约需要 7-8 秒才能可见。此外,如果重复该模式,则活动的意图将被完全忽略,并且 SampleActivity 永远不会启动。
Android-12 以下一切正常。发生在 Pixel 设备上(因为 12 目前仅在 Pixel 上可用。)
以下是示例代码片段(具有相同问题的示例项目代码)。
清单文件:
<activity
android:name=".MainActivity"
android:exported="true"
android:taskAffinity=".MainActivity"
android:configChanges=
"screenSize|smallestScreenSize|screenLayout|orientation"
android:resizeableActivity="true"
android:screenOrientation="portrait"
android:supportsPictureInPicture="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SampleActivity" />
Run Code Online (Sandbox Code Playgroud)
画中画模式:
enterPictureInPictureMode(
PictureInPictureParams.Builder().setActions()
.setAspectRatio(
Rational(
140,
190
)
)
.build()
)
Run Code Online (Sandbox Code Playgroud)
按钮点击意图
findViewById<Button>(R.id.btnClickMe).setOnClickListener {
(it as? Button)?.text = "Clicked"
val intent = Intent(this@MainActivity, SampleActivity::class.java)
startActivity(intent)
}
Run Code Online (Sandbox Code Playgroud)
尝试使用清单标志/配置,但没有运气。请提供必要的建议。
android start-activity android-picture-in-picture android-12
需要帮忙。我收到三星手机用户的标题中描述的崩溃。我已经添加了FLAG_IMMUTABLE我myFlags or FLAG_IMMUTABLE所有的 PendingIntents。应用程序在我的 Pixel 3 上没有崩溃。我尝试添加workmanager版本 2.7.0,这是在类似问题的其他答案中推荐的,但它仍然崩溃。
有人对此有任何提示吗?
我已将 SDK 版本更新为 31,之后出现此错误。这是我的摇篮:
android {
compileSdkVersion 31
defaultConfig {
applicationId "com.persiandesigners.alldentshops"
minSdkVersion 16
targetSdkVersion 31
vectorDrawables.useSupportLibrary = true
versionCode 1
versionName "1"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha01'
implementation 'androidx.cardview:cardview:1.0.0-alpha01'
implementation 'com.google.android.material:material:1.2.0-alpha01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
Run Code Online (Sandbox Code Playgroud)
我收到此错误:清单合并失败:需要显式指定 android:exported for 。android:exported当相应组件定义了意图过滤器时,面向 Android 12 及更高版本的应用需要指定显式值。有关详细信息,请参阅 https://developer.android.com/guide/topics/manifest/activity-element#exported。
我按照它说的做了,这是我的清单代码:
<activity
android:name="mypackage.MainActivity"
android:exported="true"
tools:node="merge"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/SplashScreenTheme"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" …Run Code Online (Sandbox Code Playgroud) 在 Android 12 中,需要指定 PendingIntent 的可变性。在签名屏幕中,使用 HintRequest 类,并 通过getHintPickerIntent方法返回PendingIntent。代码如下,
HintRequest hintRequest = new HintRequest.Builder().setPhoneNumberIdentifierSupported(true).build();
PendingIntent intent = Credentials.getClient(activity).getHintPickerIntent(hintRequest);//crashes here on android 12
Run Code Online (Sandbox Code Playgroud)
logcat中的错误是这样的,
java.lang.IllegalArgumentException: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
Run Code Online (Sandbox Code Playgroud)
我的问题是如何在创建待处理意图后设置可变性标志。
如果用户在我的应用程序中关闭了警报和提醒,我想向用户显示小吃栏(自 Android 12 起,必须启用此设置才能注册警报,例如触发通知)。但在某些手机上,它显示完全不同的屏幕,没有任何可用的设置。
代码:
val snackbar = Snackbar.make(tabBar, getString(R.string.snackbar_alarm_schedule_settings), 7000)
snackbar.setAction(R.string.snackbar_settings) {
Intent().apply {
action = ACTION_REQUEST_SCHEDULE_EXACT_ALARM
}.also { startActivity(it) }
}
snackbar.view.findText(com.google.android.material.R.id.snackbar_text).run {
maxLines = 5
}
snackbar.show()
Run Code Online (Sandbox Code Playgroud)
以下是我的设置与实际设置的比较:
该文档称,在针对Android 12 或更高版本的应用程序上,Toast 被截断为两行。我观察到的行为是,在运行 Android 12 或更高版本的设备上安装的应用程序上,Toast 被截断为两行。
具体来说,我的手机更新到 Android 12之前安装的一个应用程序的toast 不会被截断,但如果我将其安装在运行 Android 12 的模拟器上,它的 toast 就会被截断。我的手机更新到 Android 12后重建并安装的另一个应用程序的toast 被截断。
更新:
情况实际上似乎更复杂:行为还取决于设备,并且显然还取决于它是调试版本还是发布版本。被截断其 toast 的同一个应用程序可以在我的手机上使用发布版本正确显示它们,但在模拟器上使用相同的版本版本截断它们。
请注意,这与70307699不同,OP 将其更新targetSdk为 31。我的两个应用程序都targetSdk设置为小于 31。
我怎样才能获得记录的行为并恢复我的祝酒词?