Resolving issue: failed to attach an image in android

Hi, I am exploring the mobile-App of Joplin
and seen some similar issues in android

and this one also

I think there is no problem with @react-native-file-picker , problem is the Storage Permission.
File -picker behaves bit different in every android version , in some versions it asks for permission before going to pick file but in other(like android 10) it is not ask for storage permission for only file picker.

in my case- I use OnePlus6 (android 10) , as the guideline of Android, we don't have to ask permission for android default system file picker, but if we want to pick file from other built in apps (like Gallery etc...) then we need granted permission to access storage
People generally use gallery for pick photos.
I recreate this issue in android 9,10 and 11.

let see what happens when I recreate this issue in android 10

first I clicked on attach


it pops up two options ,
then I click on attach file - it opens File picker without asking permission
and then I choose gallery for pic file

then i choose photo from gallery and it showed me an error
-Permission denied

and after clicked on ok it did't ask me for storage permission.

then i went in app info and manually allowed storage permission and then it successfully attached photo in note.
in any case Joplin did not crash.
but it can crash in older version of androids.

so , we can resolve this issue by adding runtime storage permission in Note.js file it generalizes for all device, when user click on attach file it first verify the storage permission before going forward!!! this way we don't have to depend on file picker to ask permission.

Did a quick test but could not reproduce the error, though I may have granted the permissions earlier.
In any case, I think the correct way to do this is to use URI permissions, this way Joplin does not need to request anything to read the file. To do this however it must read the data via the ContentResolver rather than trying to read it as a file on storage.

So in summary: yes, requesting storage permissions will work (until Android 11, I think) but it's not the best way.

1 Like

if u want to recreate issue go to app setting and deny media and files permission.(this issue is not in all androids)

you are right , in latest android 12 and 11, we must use ContentResolver API to Retrieve data it makes Joplin more data secure app, no additional permission needed. and for older android Sdks we can Add Permission check.
currently I don't know how to retrieve data by URI with Native APIs . but I worked on a project in past in which I use Media Store and Content Resolver APIs in android to Retrieve music files and there thumbnail(using bitmap decode).

Please also tell me about Search in Joplin android app, it is working too bad in my android 10.

I think it's ContentResolver.openInputStream

I do not know anything about it.

@Amarpsp10 if you're interested in fixing this looks like the best way forward is to use the copyTo option that you can pass to react-native-document-picker to copy the file to Joplin's cache or files dir.
And then just rename it to whatever is needed for Joplin - since the file will be in Joplin's own dir, renaming it should not require any special access permissions.

@roman_r_m yes , trying to fixing it, I will use this Method :+1: :+1: :+1:

@roman_r_m sorry to say, but App is already doing same thing, It copy the chosen file in user data(Joplin's own dir) and then proceed next, means there is another problem, but yeah I learnt working of Document Picker,

It does copy the file, sure, just not how, I think, it should do it. I'll take a look later.

@roman_r_m I saw this statement after picking file copy(localFilePath, targetPath);
and here localFilePath is Uri of picked file. and
const targetPath = Resource_1.default.fullPath(resource);
where
const Resource_1 = require("@joplin/lib/models/Resource");
if you get something please tell

So I have tried to reproduce the issue from your original post and could not (I am using the emulator bundled with Android studio). Even without storage permissions I can share pictures both from the stock gallery app and from a random 3rd party gallery I've installed from apkmirror.

UPD
Also tried Android 11 - same result.

I think I know how to fix it but without being able to test my changes I am not sure what I can do here.

really complex situation,

On GITHUB, Joplin mobile app have many Issues, in most of them I'm not able to reproduce.

If you, instead of attaching, open that gallery app and share an image to Joplin, does it work for you?

And can you also confirm the exact name of yout gallery app? Maybe I can try installing it and see if it changes anything.

yes , working

OnePlus Gallery in built in my phone

have you reproduce issue in your real device with android 10?
because different mobiles have different "Security Patches".
one thing more I saw, if we turn on our Developer options then device reduce its security. and also give some diff results

I do not have a device with Android 10.

This is quite strange - the logic in both is very similar, in fact, sharing uses the same JS code as attaching, it's only the native side that is different.

Can you try the latest version of react-native-document-picker?

sorry make a correction , when i share the image to Joplin from gallery it asks for permission , I forgot to reset permissions

Right. This makes sense, with permissions it can just read the file off the storage rather than use the URI provided.

I am not sure if there's an issue at all here - the user just need to provide read permissions and everything works. It's not ideal, and it might break in Android 11 but seems fine for now.

1 Like

yes off topic, but I am going to work on a Backlog Feature Search in Note, this feature is still pending in mobile app.
I am not getting a good issue for contribution

Yes, looks like most issues are with desktop app, probably because it has more functions. And most issues on mobile seem to be related to sync.
If you prefer working on mobile, there are a few choices still:

1 Like

thanks for sharing