bertoldofonseca / better_open_file

A plug-in that can call native APP to open files with string result in flutter, support iOS(UTI) / android(intent) / PC(ffi) / web(dart:html)
BSD 3-Clause "New" or "Revised" License
8 stars 8 forks source link

Permission MANAGE_EXTERNAL_STORAGE Error #4

Open AndreLuizNogueira opened 2 years ago

AndreLuizNogueira commented 2 years ago

I just Changed from Open_file and can't open files on ondroid 11, permission denied error.

The File is a pdf in my Documents folder, and I was able to open in Open_File.

file: /storage/emulated/0/documents/My App/test.pdf

Permission denied: android.Manifest.permission.MANAGE_EXTERNAL_STORAGE

bertoldofonseca commented 2 years ago

Hi @jerckov40. I still trying to figure out how to make this work on Android 11.

Did you try to declare this permission on your App?

AndreLuizNogueira commented 2 years ago

I cant add, It is restricted. why is the lib using manage instead of read ? With open_file It uses read_external...

bertoldofonseca commented 2 years ago

AFAIK, there is no permissions declared anymore on the LIB.

When I asked about adding the permission on your side, I meant for testing only, not indefinitely.

bertoldofonseca commented 2 years ago

On the example app, there is only a READ permission declerade. There is no MANAGE permission there.

https://github.com/bertoldofonseca/better_open_file/blob/ef754acfd04874f59f3c3541c358e676c87b5063/example/android/app/src/main/AndroidManifest.xml#L10

AndreLuizNogueira commented 2 years ago

Sorry, misunderstood. i am currently on half of a new feature in my app, I will test later today and report back

AndreLuizNogueira commented 2 years ago

Just tested, same error.

9d954a94-0979-43c3-aea6-6dba00210c6b

bertoldofonseca commented 2 years ago

I will have to spend more time understanting this MANAGE permission and file access on Android >= 11.

AndreLuizNogueira commented 2 years ago

if it helps, my phone is a POCO X3 NFC 64GB, I just updated to android 12.

my environment:

[√] Flutter (Channel stable, 3.3.2, on Microsoft Windows [versÆo 10.0.22000.978], locale pt-BR) [√] Android toolchain - develop for Android devices (Android SDK version 33.0.0) [√] Chrome - develop for the web [√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.0.5) [√] Android Studio (version 2021.3) [√] Connected device (4 available) [√] HTTP Host Availability

Tools • Dart 2.18.1 • DevTools 2.15.0

AndreLuizNogueira commented 2 years ago

today google declined my app for using the old Open_file lib, so I came up with this workaround for using this lib on Android >= 11, just copy your file to temp folder when oppenning; like this :

var result = await OpenFile.open(filepath); if (result.message.toUpperCase().contains('MANAGE_EXTERNAL_STORAGE')) { final filename = filepath.split('/').last; final String newpath = '${(await getTemporaryDirectory()).path}/$filename'; await File(filepath).copy(newpath); result = await OpenFile.open(newpath); }