@finanzritter/nativescript-share-file
使用原生操作系统API在NativeScript中发送和共享文件到其他应用。
npm i --save @finanzritter/nativescript-share-file

Nativescript Share File

npm npm Publish

:construction: 开发中

此包是从未维护的包 braune-digital/nativescript-share-file 分叉而来。我们目前正在清理和更新代码。


将文件发送/共享到其他应用。

Android Intent,IOS InteractionController

.

安装

在您的应用中安装插件。

npm install @finanzritter/nativescript-share-file

Android FileProvider 设置

在Android上,您必须添加FileProvider定义并指定可用的文件,具体请参阅此处,或查看示例应用(AndroidManifest.xml和file_paths.xml)。

使用方法

信息:共享的文件应位于documents路径中。

import { ShareFile } from '@finanzritter/nativescript-share-file';
import { Observable, knownFolders, path, File } from "@nativescript/core";

export class TestClass extends Observable {
shareFile;
fileName;
documents;
path;
file;

constructor() {
super();

this.fileName = 'test.txt';
this.documents = knownFolders.documents();
this.path = path.join(this.documents.path, this.fileName);
this.file = File.fromPath(this.path);

this.shareFile = new ShareFile();

this.shareFile.open({
path: this.path,
intentTitle: 'Open text file with:', // optional Android
rect: { // optional iPad
x: 110,
y: 110,
width: 0,
height: 0
},
options: true, // optional iOS
animated: true // optional iOS
});
}
}

参数

path

要共享的文件的路径。

String:必需

intentTitle

Android上的intent标题。

String:(可选) 默认:打开文件:

rect

定位iPad上的视图。在iPhone上,它始终显示在底部。

Object:(可选) 默认:{x: 0, y: 0, width: 0, height: 0 }

options

显示iOS设备的附加打开选项。

Boolean:(可选) 默认:false

animated

iOS设备的打开动画。

Boolean:(可选) 默认:false

鸣谢