问题标签 [android-10.0]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
511 浏览

java - 更新 MediaStore 上的条目不适用于 Android Q / API29

我正在尝试(没有运气)为音轨和图像更新 MediaStore 的条目。我正在使用这样的东西:

上面的代码片段适用于 API16->API28 没有问题。

虽然,在 API29 上它不起作用。日志或消息中不会显示任何错误。我正在 API29 模拟器上尝试上面的代码。我不确定这个问题是否与使用模拟器有关。

我真的很感激任何指出我正确方向的信息。

0 投票
2 回答
5047 浏览

java - 无法使用 mkdir 在 Android Q 中创建文件夹

我的应用程序在所有 android 版本中创建文件夹都没有问题,除了android Q,我不知道为什么我的代码在 android q 中不起作用

这是我的代码:

0 投票
4 回答
8566 浏览

android - Is it possible to add a network configuration on Android Q?

Background

I've noticed that in WifiManager class there is a function called addNetwork, that might be useful if I want to restore or save networks information (network name AKA SSID, together with the password and the type), so that I could also connect to it.

The problem

I can't find much information about how to do such a thing. I've seen various examples on StackOverflow, and if I target Android API 28 (or below), I indeed succeed to make it add a network and even connect to it.

When targeting Android 29 (Android Q), however, it fails to add the network.

What I've found

Since I'm trying on Pixel 2 with Android Q beta 4, I think that maybe it's because addNetwork is deprecated, so the docs even say so, and that if I target Android Q, it won't work, and indeed it doesn't work:

Compatibility Note: For applications targeting Build.VERSION_CODES.Q or above, this API will always return -1.

The way it seems it should work up till Android Q (excluding), is by preparing WifiConfiguration and adding it. Later I can also connect to it if I wish. On Android Q, it seems it was replaced by WifiNetworkSuggestion, but it doesn't seem like it's about adding a network at all:

The Network Suggestion object is used to provide a Wi-Fi network for consideration when auto-connecting to networks. Apps cannot directly create this object, they must use WifiNetworkSuggestion.Builder#build() to obtain an instance of this object.

Apps can provide a list of such networks to the platform using WifiManager#addNetworkSuggestions(List).

Here's my current code, for pre-Android-Q

Seems it requires only these permissions:

But in any case, this works as long as you don't target Android Q (API 29) and above. When you target it, I indeed always get "-1" as a result, meaning it fails.

I've also found an issue on the issue tracker (here and I wrote about it here), telling about someone that needs the API back, but I'm not sure it's about adding a network.

Looking at WifiNetworkSuggestion, I don't see that it has as many things to set as WifiConfiguration via its builder, so this is another reason for why I suspect it's not about adding a network.

But I tried anyway. Here's the code I've tried, for example, to add a normal WPA network:

When running (I gave it my Wifi network details, after making the OS forget about it), it says it succeeded, but nothing occurred on the OS's Wifi settings. The network doesn't exist there with the password I've added. So I really don't get what it did...

After a few long seconds, I've noticed a notification asking me if it's ok to connect to the suggested networks made by the app:

enter image description here

But still when I chose that I accept, it didn't do anything, as before.

I tried to make another POC, thinking I might have done it incorrectly, but then it didn't even show the notification. Since I think this whole behavior is a bug, I've reported about it here.

Not only that, but I've found out that if indeed it is supposed to add a network one way or another, it still has some serious restrictions, such as max added networks (here) and being removed upon uninstall of the app (here)

The questions

  1. How should Android Q be handled exactly? Is there really no API anymore to add a network?

  2. If WifiNetworkSuggestion is not about adding a network, what is it really used for exactly?

  3. Since I'm not familiar enough with the tidbits of adding a network, is my code correct about all possible ways to add a network? I ask this because someone wrote here that people should enable Wifi and make sure pingSupplicant returns true. Is it true? Or would it be enough to just call addNetwork ?

  4. If it's now impossible to add a network using the normal API, is there maybe a solution by using a rooted device instead? Maybe some adb command?


EDIT: Not sure how to do it officially, but using adb, you might be able to add Wifi-networks on Android 11 . Need to check adb shell cmd wifi help .

0 投票
4 回答
75393 浏览

android - Android Q 模拟器上 Logcat 中的“runtime_flags 中设置的未知位:0x8000”警告

我在 logcat 中的应用程序的第一行收到了这个警告,我不知道它指的是什么以及我应该如何修复它。谷歌没有提供太多这方面的信息(事实上,根本没有)。请指教。这可能是关于什么样的旗帜?有没有办法找出指定的位可能指的是什么(或者,也许,在较旧的 Android 版本上已经指代,但在 Android 10 中已失效)?Android 9 或更早版本的日志中没有此行。

0 投票
1 回答
4074 浏览

android - Android 9+ 上的媒体投影问题

我制作了一个 OCR 应用程序,它使用 Android mediaprojection 制作屏幕截图并处理此图像中的文本。这工作正常,除了在 Android 9+ 上。当 mediaprojeciton 启动时,总​​是会弹出一个窗口警告可能记录的敏感数据,以及一个取消或开始记录的按钮。我怎样才能实现这个窗口只会显示一次?

我尝试通过创建两个额外的私有静态变量来存储 mediaprojection 的意图和结果数据来防止它弹出,如果它不为空,则重用它。但它不起作用(在另一篇文章中了解此方法)。

弹出窗口

我的代码在 Android 9 以下的 Android 版本上运行良好。在较旧的 Android 版本上,我可以选择保留授予录制权限的决定,并且它永远不会再次出现。那么我可以在 Android 9 中做什么?

在此先感谢,我很高兴你的每一个想法:)

0 投票
1 回答
366 浏览

android - 时间到了,我的应用程序无法响铃 android q

我正在构建一个闹钟应用程序,时间到了,应用程序会响起并显示活动(显示日期/时间和歌曲标题)。在 Google Pixel 3a (Q beta 4) 上运行应用程序时,警报不会响起并且无法显示活动并且在设备背景上显示消息:

后台活动从被阻止的包名开始。

我在有关此问题的一些页面上搜索并找到了一种解决方案:-通过使用通知触发的活动来缓解

但是闹钟响铃和活动只显示点击通知,那么如何在时间到时闹钟响铃并显示活动而不点击android Q上的通知?

https://developer.android.com/preview/privacy/background-activity-starts

0 投票
0 回答
313 浏览

android - 权限请求导致 Android Q 模拟器上的活动重新创建

我一直在 Android Q 上测试我的应用程序,并发现了导致应用程序无法运行的奇怪行为。然后我能够用最少的代码在一个新项目中重现它。

问题是活动处于重新创建的无限循环中(一遍又一遍地调用 onCreate)。这是通过在运行时请求权限来触发的。即使已经授予权限并且没有显示请求 UI,也会发生这种情况。

这只会发生在 Q 上,不会发生在 Pie、Oreo 或 Marshmallow 上。我不知道我的代码是否在做奇怪的事情,或者它是否是当前 Q 模拟器映像中的操作系统错误。你怎么看?在不触发此错误的情况下,我还能如何在应用启动时请求权限?

AndroidManifest.xml:

构建.gradle:

MainActivity.java:

这就是我在启动此应用程序时在 logcat 中看到的内容:

这些是我的确切模拟器设置:

在此处输入图像描述

0 投票
2 回答
10170 浏览

android - android Q中无法识别MediaProjection服务类型

随着 Android Q 的新隐私更改生效,现在任何使用MediaProjectionapi 的应用程序都必须在 manifest 下的服务标签中指定android:foregroundServiceType属性。

但是最近,我注意到虽然我设置了,android:foregroundServiceType="mediaprojection"但还是抛出了一个安全异常。有人知道我做错了什么吗?

显现:

抛出异常:

PS:这是在具有目标 SDK 29 的 Android Q DP5 GSI 上体验的。该应用程序在目标 sdk 28 上运行良好,无需任何更改。

0 投票
4 回答
9203 浏览

image - 如何将图像保存在 android Q 的子目录中,同时保持向后兼容

我正在创建一个简单的图像编辑器应用程序,因此需要加载和保存图像文件。我希望保存的文件出现在画廊中的单独相册中。从 Android API 28 到 29,应用程序能够访问存储的程度发生了巨大变化。我可以在 Android Q (API 29) 中做我想做的事,但这种方式不向后兼容。

当我想在较低的 API 版本中获得相同的结果时,到目前为止,我只找到了需要使用不推荐使用的代码(从 API 29 开始)的方法。

这些包括:

  • MediaStore.Images.Media.DATA柱子的使用
  • 通过获取外部存储的文件路径Environment.getExternalStoragePublicDirectory(...)
  • 直接通过插入图像MediaStore.Images.Media.insertImage(...)

我的问题是:是否有可能以这种方式实现它,所以它是向后兼容的,但不需要弃用的代码?如果不是,在这种情况下可以使用已弃用的代码,还是这些方法很快会从 sdk 中删除?无论如何,使用不推荐使用的方法感觉非常糟糕,所以我宁愿不要:)

这是我发现的适用于 API 29 的方式:

然后我使用 insert 方法返回的 URI 来保存位图。问题是在 API 29 中引入了 RELATIVE_PATH 字段,因此当我在较低版本上运行代码时,图像被放入“图片”文件夹而不是“PATH/TO/ALBUM”文件夹。

0 投票
1 回答
4033 浏览

android - 获取 android 设备的永久唯一 ID

我有一个应用程序,我想在其中识别具有唯一 ID 的设备,

我尝试了多种解决方案,但在手机重置唯一 ID 更改后(如 ANDROID_ID)

我在下面使用了 StackOverflow 链接,这些链接现在不可用。

是否有唯一的 Android 设备 ID?,

如何在 Android 中获取唯一的设备编号?,

获取 Android 设备的唯一 ID?,

如何在 Android 中获取唯一的设备硬件 ID?,

在android中获取唯一的设备ID

Android Q 对 IMEI 和序列号的访问受到限制。它仅适用于具有特殊运营商许可的平台和应用程序。此外,权限 READ_PRIVILEGED_PHONE_STATE 不适用于非平台应用程序。

许多人可能会将其标记为重复,但请注意, 我正在寻找一个可以持续用于设备的唯一 ID。(即使在重置/格式化设备后也不会改变)