url_launcher_ohos:基于 Flutter 的 OpenHarmony URL 启动插件项目

用户可借助该项目在 OpenHarmony 应用中实现 URL 跳转功能,支持检查 URL 可用性、配置跳转参数、控制 WebView 行为等,兼容多种启动模式,简化跨平台 URL 处理流程。【此简介由AI生成】

Branch1Tags0
FilesLast commitLast update
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago

url_launcher

This project is based on url_launcher@6.1.12.

1. Installation and Usage

1.1 Installation

Go to the project directory and add the following dependencies in pubspec.yaml

pubspec.yaml

...

dependencies:
  url_launcher:
   git:
     url: "https://gitcode.com/openharmony-tpc/flutter_packages.git"
     path: "packages/url_launcher/url_launcher"

...

Execute Command

flutter pub get

2. Constraints

For use cases packages/url_launcher/url_launcher_ohos/example

2. Constraints

2.1 Compatibility

This document is verified based on the following versions:

  1. Flutter: 3.7.12-ohos-1.0.6; SDK: 5.0.0(12); IDE: DevEco Studio: 5.0.13.200; ROM: 5.1.0.120 SP3.

2.2 Permission Requirements

The following permissions include the system_basic permission, but the default application permission is normal. Only the normal permission can be used. Therefore, the error 9568289 may be reported during the installation of the HAP package. For details, see Document Change the application level to system_basic.

2.2.1 Add permissions to the module.json5 file in the entry directory.

Open entry/src/main/module.json5 and add the following information:

"requestPermissions": [
  {
    "name": "ohos.permission.INTERNET",
    "reason": "$string:network_reason",
    "usedScene": {
      "abilities": [
          "EntryAbility"
      ],
      "when": "inuse"
    }
  },
]

2.2.2 Add the reason for applying for the preceding permission to the entry directory.

Open entry/src/main/resources/base/element/string.json and add the following information:

{
  "string": [
    {
      "name": "network_reason",
      "value": "use network"
    }
  ]
}

3. API

If the value of **ohos Support** is **yes**, it means that the ohos platform supports this property; **no** means the opposite; **partially** means some capabilities of this property are supported. The usage method is the same on different platforms and the effect is the same as that of iOS or Android.

Name return value Description Type ohos Support
canLaunch(String url) Future Returns true if this platform is able to launch [url]. function yes
launch(String url, {required bool useSafariVC,required bool useWebView,required bool enableJavaScript,required bool enableDomStorage,required bool universalLinksOnly,required Map<String, String> headers,String? webOnlyWindowName,}) Future Passes [url] to the underlying platform for handling. function yes
launchUrl(String url, LaunchOptions options) Future Passes [url] to the underlying platform for handling. function yes
closeWebView() Future Closes the WebView, if one was opened earlier by [launch]. function yes

Parameters

Name Description Type ohos Support
url Jump address String yes
useSafariVC Whether or not to open the URL in the Safari view controller bool yes
useWebView If set to null or false, open the URL in the device's default browser; otherwise, launch the URL in the WebView. bool yes
enableJavaScript If set to true, JavaScript is enabled in the WebView bool yes
enableDomStorage When this value is set to true, the WebView enables DOM storage bool yes
universalLinksOnly Used to control whether web pages are opened only through Universal Links bool yes
headers The request header parameter when opening a URL on a web page Map<String, String> headers yes
webOnlyWindowName Default behaviour when unset should be to open the url in a new tab. String? yes

LaunchOptions

Name Description Type ohos Support
mode The requested launch mode. PreferredLaunchMode yes
webViewConfiguration Configuration for the web view in [PreferredLaunchMode.inAppWebView] mode. InAppWebViewConfiguration yes
webOnlyWindowName Default behaviour when unset should be to open the url in a new tab. String? yes

PreferredLaunchMode

Name Description Type ohos Support
PreferredLaunchMode.platformDefault Leaves the decision of how to launch the URL to the platform enum yes
PreferredLaunchMode.inAppWebView Loads the URL in an in-app web view enum yes
PreferredLaunchMode.externalApplication Passes the URL to the OS to be handled by another application. enum yes
PreferredLaunchMode.externalNonBrowserApplication Passes the URL to the OS to be handled by another non-browser application. enum yes

InAppWebViewConfiguration

Name Description Type ohos Support
enableJavaScript If set to true, JavaScript is enabled in the WebView bool yes
enableDomStorage When this value is set to true, the WebView enables DOM storage bool yes
headers The request header parameter when opening a URL on a web page Map<String, String> yes

4. Known Issues

5. Others

6. License

This project is licensed under BSD-3-Clause

模板版本: v0.0.1

Introduction

用户可借助该项目在 OpenHarmony 应用中实现 URL 跳转功能,支持检查 URL 可用性、配置跳转参数、控制 WebView 行为等,兼容多种启动模式,简化跨平台 URL 处理流程。【此简介由AI生成】

Customize your domain