【问题标题】:Flutter - PlatformException when using an ACTION_EDIT intentFlutter - 使用 ACTION_EDIT 意图时出现 PlatformException
【发布时间】:2019-07-29 17:18:41
【问题描述】:

我正在使用android_intent 包发送ACTION_EDIT 意图以使图像可编辑,但我不断收到错误消息。

我在网上查了这个问题,发现如果我的SDK版本高于或等于24,我需要创建一个扩展FileProvider的类才能解决问题,但我不能弄清楚如何在颤振中做到这一点。

我正在使用的功能来选择图像并将其发送到手机编辑器:

Future getImage() async {
    var image = await ImagePicker.pickImage(source: ImageSource.camera);

    if (Platform.isAndroid) {
      var intent =
          AndroidIntent(action: 'action_edit', data: image.uri.toString());
      await intent.launch();
    }

    setState(() {
      _image = image;
    });
}

我得到的错误:

PlatformException (PlatformException(error, file:///storage/emulated/0/Android/data/com.example.app/files/Pictures/eebbf5f6-0a08-462b-9564-63c1a226e6a24636306815702344465.jpg exposed beyond app through Intent.getData(), null))

I/io.flutter.plugins.androidintent.AndroidIntentPlugin(30575): Sending intent Intent { act=action_edit dat=file:///storage/emulated/0/Android/data/com.example.app/files/Pictures/eebbf5f6-0a08-462b-9564-63c1a226e6a24636306815702344465.jpg }
E/MethodChannel#plugins.flutter.io/android_intent(30575): Failed to handle method call
E/MethodChannel#plugins.flutter.io/android_intent(30575): android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com.example.app/files/Pictures/eebbf5f6-0a08-462b-9564-63c1a226e6a24636306815702344465.jpg exposed beyond app through Intent.getData()
E/MethodChannel#plugins.flutter.io/android_intent(30575):   at android.os.StrictMode.onFileUriExposed(StrictMode.java:1978)
E/MethodChannel#plugins.flutter.io/android_intent(30575):   at android.net.Uri.checkFileUriExposed(Uri.java:2371)
E/MethodChannel#plugins.flutter.io/android_intent(30575):   at android.content.Intent.prepareToLeaveProcess(Intent.java:10936)
E/MethodChannel#plugins.flutter.io/android_intent(30575):   at android.content.Intent.prepareToLeaveProcess(Intent.java:10887)
E/MethodChannel#plugins.flutter.io/android_intent(30575):   at android.app.Instrumentation.execStartActivity(Instrumentation.java:1667)
E/MethodChannel#plugins.flutter.io/android_intent(30575):   at android.app.Activity.startActivityForResult(Activity.java:4688)
E/MethodChannel#plugins.flutter.io/android_intent(30575):   at android.app.Activity.startActivityForResult(Activity.java:4646)
E/MethodChannel#plugins.flutter.io/android_intent(30575):   at android.app.Activity.startActivity(Activity.java:5007)

你知道如何解决这个问题吗?

【问题讨论】:

    标签: android android-intent flutter dart flutter-dependencies


    【解决方案1】:

    我解决了这个问题,我将意图包从android_intent 更改为intent,然后我不知何故看到了ACTION_EDIT 的可用应用程序,而我的模拟器/手机上没有这些应用程序。

    【讨论】:

      【解决方案2】:

      这个问题可以通过android_intent包解决。

      不知怎的,我遇到了这个问题,经过搜索和尝试,我这样解决了:

      我使用“android.intent.action.EDIT”代替“action_edit”作为“动作”。

      var intent = AndroidIntent(
                       action: 'android.intent.action.EDIT', 
                       data: image.uri.toString(),
                   );
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-01-06
        • 2020-01-05
        • 2019-09-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-01-31
        • 1970-01-01
        相关资源
        最近更新 更多