如何使用android_intent_plus打开PDF?

发布于 2025-02-11 03:39:41 字数 2116 浏览 3 评论 0原文

我在下载Android文件夹上有一个.pdf,我想用扑响打开它。

我尝试过:

final AndroidIntent intent = AndroidIntent(
  action: 'android.os.Intent.ACTION_VIEW',
  // android.os.Intent.ACTION_VIEW  action_view
  data: Uri.encodeFull("/storage/emulated/0/Download/myfile.pdf"),
  // content:
  // file: 
  // type: "application/*",
  flags: [
    Flag.FLAG_GRANT_READ_URI_PERMISSION,
    Flag.FLAG_GRANT_PERSISTABLE_URI_PERMISSION,
    Flag.FLAG_ACTIVITY_NEW_TASK
  ],
);
intent.launch();

但是我会收到以下错误:

V/IntentSender( 8997): Sending intent Intent { act=android.os.Intent.ACTION_VIEW dat=/storage/emulated/0/Download/myfile.pdf flg=0x10000041 (has extras) }
E/MethodChannel#dev.fluttercommunity.plus/android_intent( 8997): Failed to handle method call
E/MethodChannel#dev.fluttercommunity.plus/android_intent( 8997): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.os.Intent.ACTION_VIEW dat=/storage/emulated/0/Download/myfile.pdf flg=0x10000041 (has extras) }
dev.fluttercommunity.plus.androidintent.MethodCallHandlerImpl.onMethodCall(MethodCallHandlerImpl.java:95)
E/flutter ( 8997): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: PlatformException(error, No Activity found to handle Intent { act=android.os.Intent.ACTION_VIEW dat=/storage/emulated/0/Download/myfile.pdf flg=0x10000041 (has extras) }, null, android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.os.Intent.ACTION_VIEW dat=/storage/emulated/0/Download/myfile.pdf flg=0x10000041 (has extras) }
E/flutter ( 8997): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter ( 8997): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:167:18)
E/flutter ( 8997): <asynchronous suspension>
E/flutter ( 8997): #2      AndroidIntent.launch (package:android_intent_plus/android_intent.dart:150:5)
E/flutter ( 8997): <asynchronous suspension>

我需要额外的许可吗?提供者?还要别的吗? 有什么建议吗? 谢谢&lt; 3

I have a .pdf on the download android folder, and I want to open it with flutter.

I tried:

final AndroidIntent intent = AndroidIntent(
  action: 'android.os.Intent.ACTION_VIEW',
  // android.os.Intent.ACTION_VIEW  action_view
  data: Uri.encodeFull("/storage/emulated/0/Download/myfile.pdf"),
  // content:
  // file: 
  // type: "application/*",
  flags: [
    Flag.FLAG_GRANT_READ_URI_PERMISSION,
    Flag.FLAG_GRANT_PERSISTABLE_URI_PERMISSION,
    Flag.FLAG_ACTIVITY_NEW_TASK
  ],
);
intent.launch();

But I get the following error:

V/IntentSender( 8997): Sending intent Intent { act=android.os.Intent.ACTION_VIEW dat=/storage/emulated/0/Download/myfile.pdf flg=0x10000041 (has extras) }
E/MethodChannel#dev.fluttercommunity.plus/android_intent( 8997): Failed to handle method call
E/MethodChannel#dev.fluttercommunity.plus/android_intent( 8997): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.os.Intent.ACTION_VIEW dat=/storage/emulated/0/Download/myfile.pdf flg=0x10000041 (has extras) }
dev.fluttercommunity.plus.androidintent.MethodCallHandlerImpl.onMethodCall(MethodCallHandlerImpl.java:95)
E/flutter ( 8997): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: PlatformException(error, No Activity found to handle Intent { act=android.os.Intent.ACTION_VIEW dat=/storage/emulated/0/Download/myfile.pdf flg=0x10000041 (has extras) }, null, android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.os.Intent.ACTION_VIEW dat=/storage/emulated/0/Download/myfile.pdf flg=0x10000041 (has extras) }
E/flutter ( 8997): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter ( 8997): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:167:18)
E/flutter ( 8997): <asynchronous suspension>
E/flutter ( 8997): #2      AndroidIntent.launch (package:android_intent_plus/android_intent.dart:150:5)
E/flutter ( 8997): <asynchronous suspension>

Do I need an extra permission? provider? anything else?
Any suggestions?
Thankss <3

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

祁梦 2025-02-18 03:39:41

尝试一下
导入'软件包:open_file/open_file.dart';

OpenFile.open("/sdcard/example.pdf");

try this
import 'package:open_file/open_file.dart';

OpenFile.open("/sdcard/example.pdf");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文