gpt4 book ai didi

javascript - 为什么 'share PDF' 和 'open PDF' 无法在使用 Nativescript 版本 6.2 的 Android 上运行

转载 作者:行者123 更新时间:2023-12-01 00:22:12 24 4
gpt4 key购买 nike

我最近将 NativeScript 5.2 版本更新到 6.2,我发现无法在 Android 设备上共享或打开 PDF,并且每当我尝试共享或保存 PDF 时,它都会发出错误消息。

作为迁移的一部分,我已将 android.support.v4.content.FileProvider 更改为 androidx.core.content.FileProvider

日志仅显示:

storage/emulated/0/Download/DocPDFs/risk_assessment_Lite_Version_201912122019.pdf JS: Android Share Error TypeError: Cannot read property 'startActivity' of undefined

    var parent = args.object.parent;

    if ( app.android ) {
        try {
            var shareFileList = new java.util.ArrayList();
            var file = new java.io.File( parent.path );
           // var fileUri = android.support.v4.content.FileProvider.getUriForFile(app.android.currentContext, appProvider, file);
           var fileUri = androidx.core.content.FileProvider.getUriForFile(app.android.currentContext, appProvider, file);

            shareFileList.add( fileUri );
            
            var shareIntent = new android.content.Intent();
            shareIntent.setAction(android.content.Intent.ACTION_SEND_MULTIPLE);
            shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody1 + userName + shareBody2 + parent.name + shareBody3);
            shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, shareSubject + parent.name);
            var emailList = new java.lang.reflect.Array.newInstance(java.lang.String.class, 1);
            emailList[0] = userEmail;
            shareIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailList);
            shareIntent.putParcelableArrayListExtra(android.content.Intent.EXTRA_STREAM, shareFileList);
            shareIntent.setType("*/*");
            shareIntent.addFlags(android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION);
            app.android.currentContext.startActivity(android.content.Intent.createChooser(shareIntent, _L("sharechecklisttoint")));
        } catch (error) {
            console.log("Android Share Error -> " + error);
            //new toastyModule.Toasty("Ein Fehler ist beim Teilen aufgetreten.").show();
            feedback.error({
                title: _L("error1"),
                backgroundColor: new color.Color("#434142"),
                message: "An error occurred while sharing."
            });
        }```

Does Anybody has an Idea?
Thanks

最佳答案

currentContext 不再有效,请参阅 API spec获取正确的属性列表。

使用app.android.foregroundActivity.startActivity(...)app.android.context.startActivity(...)

关于javascript - 为什么 'share PDF' 和 'open PDF' 无法在使用 Nativescript 版本 6.2 的 Android 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59316381/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com