メインコンテンツまでスキップ
バージョン: v9

@capacitor/app-launcher

AppLauncher APIを使うと、アプリが開けるかどうかをチェックして、アプリを開くことができます。

iOSでは、アプリのURLスキームを知っている場合のみ、アプリを開くことができます。

Androidでは、アプリのURLスキームがわかっているか、公開されているパッケージ名を使用すれば、アプリを開くことができます。

注意: Android 11 以降では、照会したいアプリのパッケージ名または URL スキームを、AndroidManifest.xml の queries タグ内に追加してください。

例:

<queries>
<!-- Query by package name -->
<package android:name="com.twitter.android" />
<!-- Query by url scheme -->
<intent>
<action android:name="android.intent.action.VIEW"/>
<data android:scheme="twitter"/>
</intent>
</queries>

Install​

npm install @capacitor/app-launcher
npx cap sync

Example​

import { AppLauncher } from '@capacitor/app-launcher';

const checkCanOpenTwitterUrl = async () => {
const { value } = await AppLauncher.canOpenUrl({ url: 'twitter://timeline' });
console.log('Can open url: ', value);
};

const openTwitterUrl = async () => {
const { completed } = await AppLauncher.openUrl({ url: 'twitter://timeline' });
console.log('openUrl completed: ', completed);
};

// Android only
const checkCanOpenTwitterPackage = async () => {
const { value } = await AppLauncher.canOpenUrl({ url: 'com.twitter.android' });
console.log('Can open package: ', value);
};

// Android only
const openTwitterPackage = async () => {
const { completed } = await AppLauncher.openUrl({ url: 'com.twitter.android' });
console.log('openUrl package completed: ', completed);
};

API​

canOpenUrl(...)​

canOpenUrl(options: CanOpenURLOptions) => Promise<CanOpenURLResult>

Check if an app can be opened with the given URL.

On iOS you must declare the URL schemes you pass to this method by adding the LSApplicationQueriesSchemes key to your app's Info.plist file. Learn more about configuring Info.plist.

This method always returns false for undeclared schemes, whether or not an appropriate app is installed. To learn more about the key, see LSApplicationQueriesSchemes.

On Android the URL can be a known URLScheme or an app package name.

On Android 11 and newer you have to add the app package names or url schemes you want to query in the AndroidManifest.xml inside the queries tag.

ParamType
options
CanOpenURLOptions

Returns:

Promise<CanOpenURLResult>

Since: 1.0.0


openUrl(...)​

openUrl(options: OpenURLOptions) => Promise<OpenURLResult>

Open an app with the given URL. On iOS the URL should be a known URLScheme. On Android the URL can be a known URLScheme or an app package name.

ParamType
options
OpenURLOptions

Returns:

Promise<OpenURLResult>

Since: 1.0.0


Interfaces​

CanOpenURLResult​

PropType
valueboolean

CanOpenURLOptions​

PropType
urlstring

OpenURLResult​

PropType
completedboolean

OpenURLOptions​

PropType
urlstring