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

@capacitor/share

Share APIは、ユーザーがインストールしている共有可能なアプリでコンテンツを共有するためのメソッドを提供します。

Share APIは、iOS、Android、およびWeb(新しいWeb Share APIを使用)で動作しますが、 ウェブでのサポートは現時点では不十分です。

Install

npm install @capacitor/share
npx cap sync

Android

デフォルトでは、Capacitorアプリはキャッシュフォルダからのファイルのみ共有できます。他のAndroidフォルダを共有可能にするには、android/app/src/main/res/xml/file_paths.xmlファイルに追加する必要があります。利用可能な場所については、FileProviderドキュメントのSpecifying Available Filesセクションを確認してください。

Example

import { Share } from '@capacitor/share';

await Share.share({
title: 'See cool stuff',
text: 'Really awesome thing you need to see right meow',
url: 'http://ionicframework.com/',
dialogTitle: 'Share with buddies',
});

// Share text only
await Share.share({
text: 'Really awesome thing you need to see right meow',
});

// Share url only
await Share.share({
url: 'http://ionicframework.com/',
});

// Share local file using url parameter
const photo = await Camera.getPhoto(options);
await Share.share({
url: photo.path,
});

// Share multiple files using files parameter
const { photos } = await Camera.pickImages(options);
await Share.share({
files: photos.map(photo => photo.path!),
});

各プラットフォームは異なるフィールドセットを使用しますが、すべてを指定することをお勧めします。

API

canShare()

canShare() => Promise<CanShareResult>

Check if sharing is supported.

Returns:

Promise<CanShareResult>

Since: 1.1.0


share(...)

share(options: ShareOptions) => Promise<ShareResult>

Show a Share modal for sharing content with other apps

ParamType
options
ShareOptions

Returns:

Promise<ShareResult>

Since: 1.0.0


Interfaces

CanShareResult

PropTypeDescriptionSince
valuebooleanWhether sharing is supported or not.1.1.0

ShareResult

PropTypeDescriptionSince
activityTypestringIdentifier of the app that received the share action. Can be an empty string in some cases. On web it will be undefined.1.0.0

ShareOptions

PropTypeDescriptionSince
titlestringSet a title for any message. This will be the subject if sharing to email1.0.0
textstringSet some text to share1.0.0
urlstringSet a URL to share, can be http, https or file:// URL1.0.0
filesstring[]Array of file:// URLs of the files to be shared. Only supported on iOS and Android.4.1.0
dialogTitlestringSet a title for the share modal. This option is only supported on Android.1.0.0