HBiSoft / PickiT

An Android library that returns real paths from Uri's

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error if getPath parameter already is an absolute path

selankon opened this issue · comments

Describe the bug

Actually, if I try to pass an absolute path to getPath, the program throw an exception.

The correct behavior should be to return the same path you put in if already is an absolute path? This could happen when receiving a sharing intent and android copy the file into application cache files.

From the existing absolute I do de following before ask getPath:

val uri: Uri = Uri.parse(absoluteUriPath!!)
val clip = ClipData.newUri(
    activity.getContentResolver(), "AbsolutePath",
    uriPath
)
pickiT?.getPath(clipData.getItemAt(0).getUri(), Build.VERSION.SDK_INT)

Log

Here the stack trace of the error:

Expand log
E/MethodChannel#flutter_file_dialog(20683): java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter path
E/MethodChannel#flutter_file_dialog(20683): 	at com.kineapps.flutter_file_dialog.FileDialog.PickiTonCompleteListener(Unknown Source:2)
E/MethodChannel#flutter_file_dialog(20683): 	at com.hbisoft.pickit.PickiT.getPath(PickiT.java:162)
E/MethodChannel#flutter_file_dialog(20683): 	at com.kineapps.flutter_file_dialog.FileDialog.getAbsolutePath(FileDialog.kt:228)
E/MethodChannel#flutter_file_dialog(20683): 	at com.kineapps.flutter_file_dialog.FileDialog.getAbsolutePath(FileDialog.kt:242)
E/MethodChannel#flutter_file_dialog(20683): 	at com.kineapps.flutter_file_dialog.FileDialog.getAbsolutePathFromUri(FileDialog.kt:156)
E/MethodChannel#flutter_file_dialog(20683): 	at com.kineapps.flutter_file_dialog.FlutterFileDialogPlugin.onMethodCall(FlutterFileDialogPlugin.kt:138)
E/MethodChannel#flutter_file_dialog(20683): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:259)
E/MethodChannel#flutter_file_dialog(20683): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:296)
E/MethodChannel#flutter_file_dialog(20683): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:320)
E/MethodChannel#flutter_file_dialog(20683): 	at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12)
E/MethodChannel#flutter_file_dialog(20683): 	at android.os.Handler.handleCallback(Handler.java:938)
E/MethodChannel#flutter_file_dialog(20683): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#flutter_file_dialog(20683): 	at android.os.Looper.loop(Looper.java:223)
E/MethodChannel#flutter_file_dialog(20683): 	at android.app.ActivityThread.main(ActivityThread.java:7664)
E/MethodChannel#flutter_file_dialog(20683): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#flutter_file_dialog(20683): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/MethodChannel#flutter_file_dialog(20683): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/flutter (20683): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: PlatformException(error, Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter path, null, java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter path
E/flutter (20683): 	at com.kineapps.flutter_file_dialog.FileDialog.PickiTonCompleteListener(Unknown Source:2)
E/flutter (20683): 	at com.hbisoft.pickit.PickiT.getPath(PickiT.java:162)
E/flutter (20683): 	at com.kineapps.flutter_file_dialog.FileDialog.getAbsolutePath(FileDialog.kt:228)
E/flutter (20683): 	at com.kineapps.flutter_file_dialog.FileDialog.getAbsolutePath(FileDialog.kt:242)
E/flutter (20683): 	at com.kineapps.flutter_file_dialog.FileDialog.getAbsolutePathFromUri(FileDialog.kt:156)
E/flutter (20683): 	at com.kineapps.flutter_file_dialog.FlutterFileDialogPlugin.onMethodCall(FlutterFileDialogPlugin.kt:138)
E/flutter (20683): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:259)
E/flutter (20683): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:296)
E/flutter (20683): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:320)
E/flutter (20683): 	at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12)
E/flutter (20683): 	at android.os.Handler.handleCallback(Handler.java:938)
E/flutter (20683): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter (20683): 	at android.os.Looper.loop(Looper.java:223)
E/flutter (20683): 	at android.app.ActivityThread.main(ActivityThread.java:7664)
E/flutter (20683): 	at java.lang.reflect.Method.invoke(Native Method)
E/flutter (20683): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/flutter (20683): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/flutter (20683): )
E/flutter (20683): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter (20683): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:167:18)
E/flutter (20683): <asynchronous suspension>
E/flutter (20683): #2      _MyAppState._absoluteFromAbsolute (package:flutter_file_dialog_example/main.dart:185:14)
E/flutter (20683): <asynchronous suspension>
E/flutter (20683): 

Can it be reproduced in demo app

No.

PickiT version

'com.github.HBiSoft:PickiT:2.0.5'

Device information

  • Miui Android 10
  • LineageOs Android 11

The problem with this is that PickiT is intended for native Android MediaStore.
When selecting media from from MediaStore an Uri gets returned.

Where as what you are doing - val uri: Uri = Uri.parse(absoluteUriPath!!) parses a String to a Uri. I can't get the absoluteUriPath from your Uri to check if the file exists.

What I can suggest is to check if the file exists before passing it to PickiT. I'm not that familiar with Flutter, but you can do something like this:

if (await File(absoluteUriPath).exists()) {
    // File path exists (You can use absoluteUriPath)  
} else {
    // File path doesn't exist (Pass absoluteUriPath to PickiT)
}

Like I said above, I will not be able to implement this and will, unfortunately, have to close this issue since there is nothing I can do from my side.

FTR the problem was that the flutter plugin to handle sharing intents was returning the absolute file for a copy-cache of the sent file.

I created a POC implementing receive sharing intent using PickiT library for Flutter.

https://gitlab.com/elRepo.io/receive_sharing_intent_pickit/-/merge_requests/1