标签: android-11

使用 ionic 和 cordova 生成针对 API Level 30 (Android 11) 的 Android 包

我是一名 ionic 开发人员,在提交更新(或新应用程序)时,我一直在处理 Google Play 的这些新要求:

从 2021 年 8 月开始,新应用将需要以 Android App Bundle 格式发布。

从 2021 年 11 月开始,应用程序更新将需要以 API 级别 30 或更高级别为目标,并针对 Android 11 中的行为变化进行调整。未收到更新的现有应用程序不受影响,可以继续从 Play 商店下载。Wear OS 应用程序必须继续以 API 级别 28 或更高级别为目标。

我正在使用 ionic/cli v6.16.3 和 cordova v10.0.0,但无法使用以下命令创建 aab 捆绑包:

ionic cordova 构建 android --prod --release -- -- --packageType=bundle

它曾经在我以前的 cordova 版本(v9)上运行良好,但自从我升级到 cordova v10 后它就停止工作了。

除此之外,我不确定是否必须使用 APKSIGNER 方案 v2 来签署捆绑包。

android google-play cordova ionic-framework android-11

5
推荐指数
1
解决办法
5512
查看次数

Android 11:卸载后重新获得应用文件夹所有权

我有一个关于 Android 11 中存储更改的问题。如果我理解正确,应用程序可以读取/写入/删除它创建的文件。然后我还可以访问这些文件,例如如下所示:

File path = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString() + "/ExampleApp/" + fileName);
Run Code Online (Sandbox Code Playgroud)

ExampleApp is the app folder I created in the public Downloads folder. But once the app gets uninstalled, it losses the ownership over all the files it created. Is there a way to regain the ownership of the ExampleApp folder by the app once it gets reinstalled? One could use scoped storage & ACTION_OPEN_DOCUMENT_TREE, but that would then have to be done on every fresh start …

android scoped-storage android-11

5
推荐指数
1
解决办法
950
查看次数

如何更改 Toast 中的默认/占位符蓝色 Android 图标,Android 11

我正在 Android 11 模拟器 (Pixel 5 API 31) 上测试我的应用程序,当我打开 Toast 通知时,我会看到以下内容: 在此输入图像描述

Toast 旁边有一个蓝色的默认/占位符 Android 图标。如何用我自己的图标替换这个占位符图标?

旧版本的 Android 不会显示任何带有 toast 消息的图标。

我的应用程序已经有一个自定义启动器图标、通知图标以及操作栏和选项卡图标。所以看起来它并没有继承于此,但我无法弄清楚我需要添加或更改什么来用我自己的图标替换它或删除它。

这是我的 java 代码,用于在需要时启动 toast:

   Toast.makeText(getContext(),getString(R.string.crashTurnedOn),Toast.LENGTH_SHORT).show();
Run Code Online (Sandbox Code Playgroud)

感谢您的任何帮助。

java android toast android-toast android-11

5
推荐指数
0
解决办法
2472
查看次数

在运行 Android 11 的摩托罗拉设备上打开键盘时应用程序崩溃

我们在运行 Android 11 的摩托罗拉设备上遇到了问题。在其他设备上,即使在 Android 11 上,我们也无法重现此问题。我们已经查看了UnsupportedOperationException:尝试从与某个不相关的上下文获取显示,但该线程是目前不活跃,因为我们没有收到任何回复。

该问题似乎与在 TextInput 字段中打开键盘有关。完整的错误语句如下。

Fatal Exception: java.lang.UnsupportedOperationException

Tried to obtain display from a Context not associated with one. Only visual Contexts (such as Activity or one created with Context#createWindowContext) or ones created with Context#createDisplayContext are associated with displays. Other types of Contexts are typically related to background entities and may return an arbitrary display.
Run Code Online (Sandbox Code Playgroud)

android motorola keyboard-events android-context android-11

5
推荐指数
1
解决办法
659
查看次数

如何使用 Android.bp 解决依赖项缺失的变体 arch:common 问题?

最初,该依赖项包含在 Android 9 的 Android.mk 文件中。该模块可以编译并运行,不会出现任何构建错误。

迁移到 Android 11 时,必须将依赖项“libvlc”添加到 Android.bp static_libs 中。

 android_app {

   compile_multilib: "both",

   static_libs: [
    " libvlc",
    ...
   ],
 }

cc_prebuilt_library_shared {
    name: "libvlc",
    srcs: ["libs/libvlc.so"],
    vendor: true,
}
Run Code Online (Sandbox Code Playgroud)

这会引发错误:

  dependency "libvlc" of "MyModule" missing variant:

  os:android, arch:common

available variants:
  os:android, image:vendor.30, arch:arm64_armv8-a_cortex-a53, sdk:, link:shared, version:

  os:android, image:vendor.30, arch:arm64_armv8-a_cortex-a53, sdk:, link:static, version:

  os:android, image:vendor.30, arch:arm_armv7-a-neon_cortex-a9, sdk:, link:shared, version:

  os:android, image:vendor.30, arch:arm_armv7-a-neon_cortex-a9, sdk:, link:static, version:

14:54:21 soong bootstrap failed with: exit status 1

#### failed to build …
Run Code Online (Sandbox Code Playgroud)

android-source libvlc android-soong android-11

5
推荐指数
0
解决办法
2051
查看次数

Android 11无线调试配对和长连接

我的问题实际上包括两个:

  1. adb pair最近在 30 个版本的 Android 平台工具中添加了该命令,但官方 Linux 存储库(特别是 Ubuntu 18.04 和 Debian 10)最新只有 27 个版本。有没有办法不用手动从网站下载最新的存档并将其放入系统中即可保持最新状态?

  2. 我正在使用无线调试来实现某些设备监控和家庭自动化目的,因此我需要保持连接持续(至少在设备连接到我的家庭网络时)。有什么方法可以在没有 root 的情况下保持连接setprop persist.adb.tcp.port 5555吗?或者至少在重新启动后不要禁用“无线调试”选项并保留端口号。

debugging remote-debugging adb android-sdk-tools android-11

5
推荐指数
0
解决办法
609
查看次数

对子目录 DocumentFile 对象的 Uri 调用 DocumentFile.fromTreeUri() 时出现意外行为

如果我调用 DocumentFile.fromTreeUri()主目录并列出其内容,它会DocumentFile按预期返回与目录中包含的文件夹和文件相关的所有对象,但是当我尝试调用DocumentFile.fromTreeUri()其中Uri的文件夹之一时DocumentFile,而不是返回所有DocumentFile相关对象按预期返回到子目录中包含的文件夹和文件,它实际上返回与其根目录上的调用完全相同的内容Uri

例如,我有一个包含 3 个文件的下载文件夹和一个包含 2 个文件的子文件夹,其结构如下

Download
-->file1
-->file2
-->file3
-->Subfolder
----->subfile1
----->subfile2
Run Code Online (Sandbox Code Playgroud)

如果我调用 通过意图回调选择的DocumentFile.fromTreeUri().listFiles()下载文件夹 它会返回我Uricontent://com.android.externalstorage.documents/tree/primary%3ADownload

-->file1
-->file2
-->file3
-->Subfolder
Run Code Online (Sandbox Code Playgroud)

到目前为止一切都很好,现在如果我尝试获取Uri与调用DocumentFile相关的对象,我得到的显然看起来是正确的,但是如果我调用它,当我列出它的内容时我会再次得到Subfoldermysub.getUri()content://com.android.externalstorage.documents/tree/primary%3ADownload/document/primary%3ADownload%2FSubfolderDocumentFile.fromTreeUri().listFiles()

-->file1
-->file2
-->file3
-->Subfolder
Run Code Online (Sandbox Code Playgroud)

与主下载文件夹 Uri 上的调用完全相同。如果我直接打电话,也会发生同样的情况mysub.listFiles()。这看起来是一个完全不合逻辑的设计。

我怎样才能真正从与其父DocumentFile文件夹相关的对象中正确获取与子文件夹相关的对象DocumentFile,以便子文件夹DocumentFile可以列出其内容而不是其父文件夹的内容?

android storage-access-framework android-10.0 android-11

4
推荐指数
1
解决办法
1408
查看次数

java.io.FileNotFoundException 打开失败:EEXIST(文件存在)Android 11

我试图从服务器下载图像并将其保存在外部存储器中,但在 Android 11 中,当我尝试创建文件时出现错误。我已授予访问外部存储的权限。

我在互联网上搜索了一下,他们建议我将此代码放在清单中,但它不适用于 android 11

android:requestLegacyExternalStorage="true"
Run Code Online (Sandbox Code Playgroud)

显现

<uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:requestLegacyExternalStorage="true"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.TestDwonloadImgApp"
        android:usesCleartextTraffic="true">
        <activity android:name=".MainActivity2">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity">
        </activity>
    </application>
Run Code Online (Sandbox Code Playgroud)

主要活动

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ImageView img = findViewById(R.id.img);

        ImmagineInterface ii = RetrofitManager.retrofit.create(ImmagineInterface.class);
        Call<ResponseBody> call = ii.downloadFile("/immaginimusei/arte-scienza.jpg");
        call.enqueue(new Callback<ResponseBody>() …
Run Code Online (Sandbox Code Playgroud)

java android android-11

4
推荐指数
1
解决办法
2842
查看次数

Android 11 / API 30 - 打开 YouTube 链接

我目前很难在浏览器或 YouTube 应用程序中打开 YouTube 链接。我知道Android 11 中新的包可见性并以这种方式实现。

MyClass.java$myMethod

String ytLink = "https://www.youtube.com/watch?v=Hp_Eg8NMfT0"
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(ytLink)); 
if (intent.resolveActivity(context.getPackageManager()) != null) {  
  context.startActivity(intent); 
}
Run Code Online (Sandbox Code Playgroud)

AndroidManifest.xml

<manifest>
  <queries>
    <intent>
      <action android:name="android.intent.action.VIEW" />
      <data android:scheme="https" />
    </intent>
  </queries> 
</manifest>
Run Code Online (Sandbox Code Playgroud)

然而,intent.resolveActivity返回null...我尝试过的每个其他链接都返回一个ComponentName,以便Intent可以启动...您有任何线索吗?

提前致谢 ;)

youtube android android-intent android-11

4
推荐指数
1
解决办法
4594
查看次数

Android 11 使用字符串资源在 Android Manifest 中声明包可见性

我的应用程序检测是否通过安装了某个应用程序queryIntentActivities。由于我的应用程序的目标是 api 级别 30,因此它停止工作,因为我缺少一些清单声明。

此示例中,他们直接定义包名称。但我想要查询的应用程序对于每个构建变体都不同。所以最好使用字符串资源。然而这似乎不可能。

例子

<manifest package="com.example.game">
    <queries>
        <package android:name="com.example.store" />
        <package android:name="com.example.services" />
    </queries>
    ...
</manifest>
Run Code Online (Sandbox Code Playgroud)

我想要什么

<manifest package="com.example.game">
    <queries>
        <package android:name="@string/store_app" />
        <package android:name="@string/services_app" />
    </queries>
    ...
</manifest>
Run Code Online (Sandbox Code Playgroud)

其他一些文件

<string name="store_app">com.example.store</string>
<string name="services_app">com.example.services</string>
Run Code Online (Sandbox Code Playgroud)

如何使用字符串资源

android android-manifest android-intent android-11

4
推荐指数
1
解决办法
5904
查看次数