Android 未显示免安装应用权限请求对话框

Android instant app permission request dialog not shown

我目前正在为 Android 开发即时应用程序,我想使用相机。 我在 Fragment 中请求相机权限,但没有出现权限请求对话框。

这是我在片段中请求权限的方式:

requestPermissions(new String[]{
                    Manifest.permission.CAMERA}, 1);

现在我希望显示权限请求对话框,因为它是针对应用程序本身的 (com.android.application)。不幸的是,它没有出现在免安装应用 (com.android.instantapp) 中。

另外我发现

@Override
public void onRequestPermissionsResult(final int requestCode, @NonNull final String permissions[], @NonNull int[] grantResults)
{...}

被调用但带有 grantResults[0] = -1,这意味着 PackageManager.PERMISSION_DENIED

根据 Instant Apps FAQ 它应该与应用程序相同:

How do permissions work in Google Play Instant?

Google Play Instant uses the runtime permissions model that was introduced in Android 6.0 (API level 23).

如果我从 Google (android-topeka) 添加 Instant App Demo 项目的权限请求,也会出现同样的问题。

我认为这是因为您缺少将相机权限添加到清单中。 将相机权限添加到您的清单。

<uses-permission android:name="android.permission.CAMERA" />

希望这能解决您的问题。

这似乎只发生在我的 HUAWEI Mate 10 Pro 上。我已经在多个设备上进行了测试,一切正常,正如预期的那样。

目前我不知道为什么权限请求在华为设备上不起作用,但我认为这与EMUI系统有关。