我发现我正在启动的新应用程序出现奇怪的问题。我正在利用新的 Android 12 启动画面 API 来创建启动画面,并按照Google 提供的指南进行操作。我在项目中包含了 core-splashscreen,以提供与旧版本 Android 操作系统的兼容性。当我运行该应用程序时,我会在 API 30 等旧操作系统版本上看到预期的启动屏幕,但当我在 API 31 上运行它时,我提供的启动屏幕图标不会显示。显示了我指定的背景颜色,但根本不存在图标。我已经尝试使用可绘制资源和 mipmap 进行此操作,但没有任何效果。我很困惑,因为我找到的每个教程都显示了我所遵循的相同步骤以及他们工作启动屏幕的屏幕截图,但我没有任何运气。
对于上下文,这里是我对 v31 的启动屏幕样式定义:
<style name="Theme.Splash" parent="Theme.SplashScreen">
<item name="android:windowSplashScreenBackground">@color/orange_7A</item>
<item name="android:windowSplashScreenAnimatedIcon">@drawable/splash_foreground</item>
<item name="postSplashScreenTheme">@style/Theme.App</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我对所有其他操作系统版本都有相同的样式,除了我使用“windowSplashScreenAnimatedIcon”而不是“android:windowSplashScreenAnimatedIcon”。我尝试过 v31 在项目名称前面有或没有“android:”,但都不起作用。这是我的 MainActivity.kt:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
installSplashScreen()
setContent {
MyVeevaTheme {
Login()
}
}
}
Run Code Online (Sandbox Code Playgroud)
我还在 AndroidManifest.xml 中将“android:theme”属性设置为我的启动样式。我知道正在应用启动样式,因为它尊重背景颜色,但由于某种原因它没有显示图标,即使图标在旧操作系统版本中显示良好。预先感谢您可以提供的任何帮助。
从 Android 12 开始,Google 会显示带有应用图标的 Toast 消息。
我的应用程序有启动器图标。Android 12 初始屏幕正确显示应用程序图标。
通过代码显示 toast
Toast.makeText(this, "Show simple toast", Toast.LENGTH_LONG).show()
Run Code Online (Sandbox Code Playgroud)
编译SdkVersion/targetSdkVersion 31
android 模拟器 Google play Intel x86 Atom_64 系统映像 API 级别 31,修订版 8。
如何更改此默认 toast 图标?
正如标题所说,我升级到了 API 31。我有一个执行振动的函数,但是在行中
val vib = this.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
Run Code Online (Sandbox Code Playgroud)
VIBRATOR_SERVICE现在显示为已弃用。我怎样才能更换它?或者至少,API 31 及以上版本的现代解决方案是什么?
编辑:正如 Joachim Sauer 所写,替代方案是 VibrationManager。我现在需要的是使用 VibrationManager 的等效代码行。
当我想通过 WifiManager.connectionInfo 获取有关当前 wifi 连接的信息时,我得到以下信息:
'connectionInfo 的吸气剂:WifiInfo!' 已弃用。在 Java 中已弃用
我该如何在 Android 12 中做到这一点?(只想获取RSSI)
我正在使用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 12 (SPB5.210812.002) 的 Pixel 4a 上,当用户授予近似位置权限时,不会从FusedLocationProviderClient. 当我将权限更改为精确位置权限时,我就可以获取位置。
我在清单中拥有粗略和精细的位置权限,并在运行时请求这两种权限。
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Run Code Online (Sandbox Code Playgroud)
一旦获得任一许可,我就会请求lastKnownLocation以及位置更新。有了精确的位置许可,我很快就能获得位置,但当用户提供大致位置许可时就无法获得位置。
对于位置请求优先级,我已经尝试过LocationRequest.PRIORITY_HIGH_ACCURACY和LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY。
在 Android 9 上,一切都按预期工作,所以我猜这与Android 12 中引入的精确/近似位置权限有关。
这是我的代码的一部分:
private val fusedLocationClient by lazy {
LocationServices.getFusedLocationProviderClient(requireContext())
}
private val cts: CancellationTokenSource = CancellationTokenSource()
private val locationRequest = LocationRequest()
.setPriority(LOCATION_REQUEST_PRIORITY)
.setFastestInterval(MIN_TIME_BETWEEN_STAMPS_IN_MILLIS) // 1000
.setInterval(TIME_BETWEEN_STAMPS_IN_MILLIS) // 10000
private val locationCallback = object : LocationCallback() {
override fun onLocationResult(locationResult: LocationResult?) {
locationResult?.locations?.firstOrNull()?.let {
userLocation = it
onUserLocationUpdated() …Run Code Online (Sandbox Code Playgroud) location fusedlocationproviderclient android-12 android-api-31
大家好,我的全屏有问题,我尝试了各种设置,但无法在 android 12 api31 上获得全屏。
目前我已经这样设置了。
我像这样运行应用程序
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []).then(
(_) => runApp(MyApp()),
);
Run Code Online (Sandbox Code Playgroud)
在 styles.xml 中
<style name="NormalTheme" parent="@android:style/Theme.Translucent.NoTitleBar">
// Important to draw behind cutouts
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>
Run Code Online (Sandbox Code Playgroud)
在AndroidManifest.xml中
android:windowSoftInputMode="adjustResize"
Run Code Online (Sandbox Code Playgroud)
我也尝试过其他的事情,但目前我得到的最好的结果是这个
return Scaffold(
body: Container(
color: Colors.deepPurple,
child: const Center(
child: Text(
"Container full",
style: TextStyle(fontSize: 40),
),
),
),
);
Run Code Online (Sandbox Code Playgroud)
我想覆盖整个屏幕,但我什至无法覆盖缺口
最终结果应该是这样的。我希望能够操纵我的应用程序的整个屏幕空间。我不想要系统栏。
我试图使 android 12 启动屏幕的背景使用 @android:color/system_neutral1_900 作为背景,但正如我所看到的,颜色仅在启动屏幕之后加载。有什么办法可以在启动屏幕上使用它吗?
<style name="Theme.App.SplashScreen" parent="Theme.SplashScreen">
<!-- Set the splash screen background, animated icon, and animation duration. -->
<item name="windowSplashScreenBackground">@android:color/system_neutral1_900</item>
</style>
Run Code Online (Sandbox Code Playgroud)
颜色不会出现,它使用默认的灰色。我还尝试了其他 system_ 颜色,出现了相同的结果。使用 @android:color/black 或十六进制颜色可以。
android ×7
android-12 ×7
dart ×1
deprecated ×1
flutter ×1
fusedlocationproviderclient ×1
location ×1
toast ×1
vibration ×1
wifimanager ×1