简体   繁体   English

如何在颤振中使用android_intent_plus打开pdf?

[英]How to open a pdf using android_intent_plus in flutter?

I have a .pdf on download android folder, and I want to open it with flutter.我在下载 android 文件夹上有一个 .pdf,我想用颤振打开它。

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谢谢 <3

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM