【发布时间】:2019-07-19 16:15:58
【问题描述】:
我已经迁移到 NativeScript 6.0,需要一些帮助,了解如何在 Downloads 文件夹中下载和打开带有 Android 支持库 (AndroidX) 的文件。 p>
实际上,在 NS 5.x 中,我使用了 Android 支持库 (android.support.v4.content.FileProvider) 中的 FileProvider 并且效果很好。迁移后,使用 (androidx.core.content.FileProvider),我打开应用程序时出错。
但在 Android 文档中,我找不到任何方法或信息来迁移本机下载和打开(下载文件夹)的代码。
上一个方法:
private openFile(fileName: string, mimeType: string, extension: string) {
try {
if (isAndroid) {
const intent = new android.content.Intent(android.content.Intent.ACTION_VIEW);
const context = applicationModule.android.context;
console.log("android.ctx=", context);
const nativeFile = new java.io.File(fileName);
console.log("nativeFile=", nativeFile);
const uri = android.support.v4.content.FileProvider.getUriForFile(context, "com.otisw.gescon.app.provider", nativeFile);
intent.setDataAndType(uri, mimeType);
intent.addFlags(android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION);
const choosedIntent = android.content.Intent.createChooser(intent, "Open file...");
console.log("choosedIntent=>", choosedIntent);
context.startActivity(choosedIntent);
} else {
// const documents = fs.knownFolders.currentApp();
// const file = this.documents.getFile(fileName);
const open = utils.ios.openFile(fileName);
}
} catch (e) {
console.log(e);
}
}
试过了:
private openFile(fileName: string, mimeType: string, extension: string) {
try {
if (isAndroid) {
const intent = androidx.core.content.IntentCompat.makeMainSelectorActivity(
"android.content.Intent.ACTION_VIEW",
"??"
);
文件参考.d.ts:
/// <reference path="./node_modules/tns-core-modules/tns-core-modules.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android/androidx-26.d.ts" />
是否有人尝试将用于下载和打开的代码从 NativeScript 升级到新的 AndroidX 或知道解决方法?
谢谢!
【问题讨论】:
标签: nativescript androidx