在 React Native 上定位 android 30 sdk 时,Linking.canOpenURL 返回 false

Bef*_*ire 5 linker android native reactjs react-native

最近将我们的构建目标切换到 android 30 以添加对 Android 11 的支持,现在方向和电话呼叫不起作用。

该文档提到了本机深度链接和/或 npm 包的使用。这会在本地完成吗?或者这个包是一种选择?

https://reactnative.dev/docs/linking

Linking.canOpenURL 现在在运行 android 30 时检查它是否受支持时返回 false。

Linking.canOpenURL(url)
.then((supported: boolean) => (supported ? Linking.openURL(url) : Alert.alert("Error", "There was an error attempting to opening the location.")))
.catch(() => Alert.alert("Error", "There was an error attempting to opening the location."));
Run Code Online (Sandbox Code Playgroud)

小智 35

就我而言,我需要将 a 添加android:host="*"data标签中,如下所示:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          package="com.acme">
...
    <queries>
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data android:scheme="https" android:host="*" />
        </intent>
    </queries>
</manifest>
Run Code Online (Sandbox Code Playgroud)

用于Linking.canOpenURL(url)返回trueURL https://...


And*_*dré 8

答案在于新的 Android 安全功能:Package Visibility。这类似于 iOS 的LSApplicationQueriesSchemes.

以 Android 11 (SDK 30) 为目标平台要求您更新AndroidManifest.xml并包含您要查询的应用程序列表。例如,这是我用来在我自己的应用程序中检查 Google 地图导航的代码。它还包括 HTTP 和 HTTPS 的权限:

<manifest package="com.example.game">
  <queries>
    <intent>
      <action android:name="android.intent.action.VIEW" />
      <data android:scheme="http"/>
    </intent>
    <intent>
      <action android:name="android.intent.action.VIEW" />
      <data android:scheme="https"/>
    </intent>
    <intent>
      <action android:name="android.intent.action.VIEW" />
      <data android:scheme="geo" />
    </intent>
    <intent>
      <action android:name="android.intent.action.VIEW" />
      <data android:scheme="google.navigation" />
    </intent>
  </queries>
  ...
</manifest>
Run Code Online (Sandbox Code Playgroud)

对于符合某些条件的应用程序(例如防病毒应用程序、文件管理器或浏览器),您可以使用该QUERY_ALL_PACKAGES 权限来允许查询类似于早期 Android 版本的任何随机包:

<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
Run Code Online (Sandbox Code Playgroud)

但是,请注意,如果您不符合下列任何应用类型的条件或以未经授权的方式使用,您的应用将被Google Play拒绝QUERY_ALL_PACKAGES

允许使用涉及必须发现设备上任何和所有已安装应用程序的应用程序,出于意识或互操作性目的,可能有资格获得许可。允许的用途包括设备搜索、防病毒应用程序、文件管理器和浏览器。被授予此权限的应用程序必须遵守用户数据政策,包括突出披露和同意要求,并且不得将其使用扩展到未披露或无效的目的。

请参阅使用广泛的包(应用程序)可见性 (QUERY_ALL_PACKAGES) 权限


小智 8

如果您决定使用,请小心

<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
Run Code Online (Sandbox Code Playgroud)

谷歌 说:

允许的使用涉及必须发现设备上所有已安装应用程序的应用程序,出于感知或互操作性目的可能有资格获得许可。允许的使用包括设备搜索、防病毒应用程序、文件管理器和浏览器。获得此权限的应用程序必须遵守用户数据政策,包括显着披露和同意要求,并且不得将其使用范围扩大到未披露或无效的目的。

关于Google Play 的政策更新