我正在学习 Android 12 中引入的 Android 新 SplashScreen API。到目前为止,我已经让它可以在我的模拟器和 Google Pixel 4A 上运行,但我想增加其持续时间。在我的启动屏幕中,我不需要花哨的动画,我只想要一个静态的可绘制对象。
我知道,我知道(叹气)你们中的一些人可能会想,我不应该增加持续时间,而且我知道有几个很好的论据支持不这样做。然而,对我来说,带有非动画可绘制对象的启动屏幕的持续时间非常短暂(不到一秒),我认为这引起了可访问性问题,特别是因为它无法被禁用(具有讽刺意味的是)。简而言之,产品背后的组织或其品牌/产品标识无法被当时规模的新用户正确吸收或识别,从而使新的启动屏幕变得多余。
我在启动画面的主题中看到属性 windowSplashScreenAnimationDuration (如下所示),但这对持续时间没有影响,大概是因为我没有制作动画。
<style name="Theme.App.starting" parent="Theme.SplashScreen">
<!--Set the splash screen background, animated icon, and animation duration.-->
<item name="windowSplashScreenBackground">@color/gold</item>
<!-- Use windowSplashScreenAnimatedIcon to add either a drawable or an
animated drawable. One of these is required-->
<item name="windowSplashScreenAnimatedIcon">@drawable/accessibility_today</item>
<item name="windowSplashScreenAnimationDuration">300</item> <!--# Required for-->
<!--# animated icons-->
<!--Set the theme of the activity that directly follows your splash screen-->
<item name="postSplashScreenTheme">@style/Theme.MyActivity</item>
<item name="android:windowSplashScreenBrandingImage">@drawable/wculogo</item>
</style>
Run Code Online (Sandbox Code Playgroud)
有没有直接的方法来延长非动画启动画面的持续时间?
描述
我无法使用 Android-12 中的类获取 WIFI onCapabilitiesChangedSSID ConnectivityManager.NetworkCallback。在 Android-12 中,getConnectionInfo 已弃用。因此,正如 android 文档所建议的那样,我正在尝试WifiInfo使用onCapabilitiesChanged.
像这样,
@Override
public void onCapabilitiesChanged(@NonNull Network network, @NonNull NetworkCapabilities networkCapabilities) {
super.onCapabilitiesChanged(network, networkCapabilities);
WifiInfo wifiInfo = (WifiInfo) networkCapabilities.getTransportInfo();
}
Run Code Online (Sandbox Code Playgroud)
但是,当我打印该WifiInfo对象时。它将打印SSID:<unknown ssid>并getHiddenSSID返回 true。
意想不到的行为是,
Android-12设备连接1个WIFI(例如ABC)
getConnectionInfo。它返回 SSID: ABC 和 getHiddenSSID: falseonCapabilitiesChanged,它返回 SSID: <unknown ssid> 和 getHiddenSSID : true注意:提供位置许可。
尝试在 Android 12 设备中安装应用程序时出现以下错误。
Installation did not succeed.
The application could not be installed: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
Run Code Online (Sandbox Code Playgroud)
错误
Installation failed due to: 'INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: Failed parse during installPackageLI: /data/app/vmdl1707272647.tmp/base.apk (at Binary XML file line #98): aero.sita.airsideapp.activities.MainActivity: Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present'
Run Code Online (Sandbox Code Playgroud)
有以下目标并编译sdk版本
compileSdkVersion: 31,
buildToolsVersion: "28.0.2",
minSdkVersion : 16,
targetSdkVersion : 31,
Run Code Online (Sandbox Code Playgroud)
将版本减少到 30 效果很好,但是我无法使用android:windowSplashScreenBackgroundandroid 12 设备的启动屏幕背景更改参数
编辑:添加android:exported="true"到所有 <activity>、<service> …
我想播放一些音频,音量级别调整为耳朵的大小。“通话模式”。为此,我使用众所周知且普遍建议的
audioManager.setMode(audioNormalState ?
AudioManager.MODE_NORMAL : AudioManager.MODE_IN_COMMUNICATION);
Run Code Online (Sandbox Code Playgroud)
问题是我并不总是在模式切换后播放音频,我必须等待并且不确定多久,甚至可能是几分钟。我做了一些循环记录,MODE_IN_COMMUNICATION只要用户在某些搭载 Android 9 的摩托罗拉上的应用程序中处于“电话通话模式”,模式就会保留,但在配备Android 12 的 Pixel 3 上,6 秒后模式会自动切换回MODE_NORMAL当没有播放任何内容时。没有执行额外的代码(如某些侦听器),没有额外的(系统)日志。当我在切换到MODE_IN_COMMUNICATION模式后 1 秒开始播放音频时,只要播放音频(甚至超过 6 秒),它就不会自动切换,但在完成模式后也会自动切换到MODE_NORMAL.
我的应用程序可以发出某种实时语音呼叫(命令),但也可以“发出蜂鸣声”一些信号模式,并且还有一个历史记录功能,可以按时间顺序再次播放所有发声动作。如果这只是语音,那么MODE_IN_COMMUNICATION仅在通话期间切换到和返回可能就足够了,但是如何处理非常重要的SoundPool广告歌曲,我是否也必须为它们切换模式?(或者对于历史播放,这是一个混合)据我所知模式切换并不快(在某些设备上甚至是几秒),所以我可能会对数百毫秒的短信号应用一些显着的延迟(没办法,每个毫秒都是至关重要!)或者即使在“电话呼叫模式”下,当模式没有“足够快”改变时(用户不会高兴),我也冒着大声播放信号/语音的风险。我依赖于固定设置(但根据应用程序状态和设置进行配置)MODE_IN_COMMUNICATION,该设置一直有效到 Android 12...(可以确认 Pixel 和 Samsung 上的新/错误行为)
目前使用的切换音频模式+配置的方法如下,值得注意的是,该setSpeakerphoneOn方法在 Android 12 上也并不总是有效。至少在打开时不起作用MODE_NORMAL,这是现在默认的自动切换回模式,也是isSpeakerphoneOn第false一个开始,但我所有的音频源实际上都大声播放......
// forceAudioNormalState = true only when app exit!
public static void resolveLoudState(AudioManager audioManager, boolean forceAudioNormalState) {
boolean silentPhoneCallMode = isPhoneCallModeEnabled(); // phone call GUI, only …Run Code Online (Sandbox Code Playgroud) 蓝牙是我们应用程序的主要依赖项。因此,我们已经尝试实施新的 Android 12 蓝牙权限。我们唯一的资源是Android 开发人员 Android 12 中的新蓝牙权限。只是说添加权限
“android.permission.BLUETOOTH_CONNECT”
“android.permission.BLUETOOTH_SCAN”
我添加并获得了两个和当然位置的运行时权限(通常为前 12))。
我的代码库中没有其他变化。应该?我不知道。所以,问题是我的应用程序找不到 BLE 设备。我找不到原因。
你有什么建议或资源吗?
android bluetooth android-permissions android-bluetooth android-12
与这个问题类似,但不一样
更新到 Android 12 (SDK 31) 后,我们更改PendingIntent.getActivity(context, 0, intent, 0)为PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE)建议的。
但PendingIntent.FLAG_IMMUTABLE不适用于 23 以下的 SDK。如果我添加if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)以保留两个版本,我会保留有关未使用正确标志的 lint 警告else。
这里的预期行为是什么?谢谢!
我\xc2\xb4已经开始测试我的应用程序在Android 12上的问题,并且收到了一些关于为主屏幕小部件设置的待处理意图的可变性标志的警告。这些可变性标志现在从 SDK 31 开始是强制性的。在 31 之前,此代码可以工作,但会出现 lint 警告:
\nval myIntent = Intent(context, MainActivity::class.java)\nval myPendingIntent = PendingIntent.getActivity(context, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT )\nmyRemoteViews.setOnClickPendingIntent(R.id.widget_button, myPendingIntent)\nRun Code Online (Sandbox Code Playgroud)\n在 Android 12 上,需要添加第二个标志,如下所示:
\nval myIntent = Intent(context, MainActivity::class.java)\nval myPendingIntent = PendingIntent.getActivity(context, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)\nmyRemoteViews.setOnClickPendingIntent(R.id.widget_button, myPendingIntent)\nRun Code Online (Sandbox Code Playgroud)\n到目前为止,一切都很好。但是,对于某些小部件操作,不仅需要导航到应用程序,还需要导航到特定片段并添加片段参数。对于这些情况,我\xc2\xb4一直在使用 NavDeepLinkBuilder 创建pendingIntent\n https://developer.android.google.cn/reference/kotlin/androidx/navigation/NavDeepLinkBuilder
\nval myPendingIntent = NavDeepLinkBuilder(context)\n .setGraph(R.navigation.nav_main)\n .setDestination(R.id.myFragment)\n .setArguments(\n myFragment.bundle(myArgs)\n )\n .createPendingIntent()\nmyRemoteViews.setOnClickPendingIntent(R.id.widget_button, myPendingIntent)\nRun Code Online (Sandbox Code Playgroud)\n在您将构建目标设置为 sdk 31 并在 Android 12(模拟器)上构建之前,此方法非常有效。在这种情况下,它会在使用以下堆栈跟踪创建小部件时崩溃:
\n 2021-11-03 17:41:27.792 20309-20309/com.package.debug E/AndroidRuntime: FATAL EXCEPTION: main\n Process: com.package.debug, PID: 20309\n java.lang.RuntimeException: …Run Code Online (Sandbox Code Playgroud) android android-pendingintent android-architecture-navigation android-deep-link android-12
我正在尝试检查 Android 12 是否正在优化我的应用程序电池使用情况,因此我使用了 isIgnoringBatteryOptimizations方法( https://developer.android.com/reference/android/os/PowerManager#isIgnoringBatteryOptimizations(java.lang.String))。但是isIgnoringBatteryOptimizations返回一个布尔值yes,它已经过优化,而 Android 12 有 3 个级别的优化(查看屏幕截图):
我的应用程序在 1 和 2 的情况下工作正常,我想在受限模式下显示警告。
optimization android battery android-powermanager android-12
我已经安装了 Android 12 Preview 模拟器。我遇到了很多问题,因为模拟器在启动时崩溃,但是在卸载并再次安装并重新启动机器等之后,我设法启动了它。我现在遇到的问题是互联网连接不起作用。所有其他模拟器都可以正常工作。我试图从命令行启动模拟器来设置 dns
~/Library/Android/sdk/emulator/emulator -avd Pixel_5_API_S -dns-server 8.8.8.8
Run Code Online (Sandbox Code Playgroud)
我得到的是网络仍然不工作,我可以看到很多日志:
vqParseGuestToHostRequestLocked:734 {src_port=2489684015 dst_port=4294967295} 意外的 dst_port
vqParseGuestToHostRequestLocked:734 {src_port=2489684016 dst_port=4294967295} 意外的 dst_port
vqParseGuestToHostRequestLocked:734 {src_port=2489684017 dst_port=4294967295} 意外的 dst_port
vqParseGuestToHostRequestLocked:734 {src_port=2489684018 dst_port=4294967295} 意外的 dst_port
这是我正在使用的模拟器:
Name: Pixel_5_API_S
CPU/ABI: Google APIs Intel Atom (x86_64)
Path: /Users/username/.android/avd/Pixel_5_API_S.avd
Target: google_apis [Google APIs] (API level S)
Skin: pixel_4
SD Card: 512M
fastboot.chosenSnapshotFile:
runtime.network.speed: full
hw.accelerometer: yes
hw.device.name: pixel_5
hw.lcd.width: 1080
image.androidVersion.codename: S
hw.initialOrientation: Portrait
image.androidVersion.api: 30
tag.id: google_apis
hw.mainKeys: no
hw.camera.front: emulated
avd.ini.displayname: Pixel 5 API …Run Code Online (Sandbox Code Playgroud) 我正在使用Android 12 启动屏幕 API,虽然从启动器打开应用程序时启动屏幕图标显示没有问题,但从通知打开应用程序仅显示启动屏幕背景,没有图标或动画图标。
v31/styles.xml这是我的活动使用的主题AndroidManifest.xml:
<style name="MainActivityTheme" parent="AppTheme">
<item name="android:windowSplashScreenBackground">@color/splash_screen_background</item>
<item name="android:windowSplashScreenAnimatedIcon">@drawable/splash_screen_icon</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用其他主题,但无济于事:
<style name="SplashScreenTheme" parent="Theme.SplashScreen">
<item name="android:windowSplashScreenBackground">@color/splash_screen_background</item>
<item name="android:windowSplashScreenAnimatedIcon">@drawable/splash_screen_icon</item>
<item name="postSplashScreenTheme">@style/MainActivityTheme</item>
</style>
Run Code Online (Sandbox Code Playgroud)
欢迎任何使图标在通知中可见的想法。提前致谢!
android ×10
android-12 ×10
android-architecture-navigation ×1
android-wifi ×1
battery ×1
bluetooth ×1
java ×1
optimization ×1
ssid ×1
wifi ×1