You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a question regarding the ability to call Nearby.saveFile(serviceId,endpointId,payloadId) after an initial permission failure. Currently, as long as a user has granted permissions to READ/WRITE external storage, calling Nearby.saveFile() has the promise resolve successfully. If permissions are not granted or are revoked before calling saveFile, one encounters a promise rejection. Until here things are still behaving as expected.
However, in my case I am trying to offer the user the ability to retry executing saveFile() at a later point by storing the serviceId, endpointId, and payloadId before initially calling saveFile. This way, once saveFile() is called and it fails, the user can be prompted to grant permissions within their settings or elsewhere and try calling it again. The problem is that when I allow the user to retry using the same serviceId, endpointId, and payloadId which previously failed due to permissions not being granted, the promise still rejects.
When I adb logcat I see it is failing with the message 03-24 14:31:03.806 24644 26856 V NearbyConnection: Cannot convert to file., which is line #1501 here
In other words it seems that File payloadFile = payload.asFile().asJavaFile(); is null. I decided to log every payload variable until permissionsCheck fires and this is the below output:
03-24 14:31:03.805 24644 26856 V NearbyConnection: saveFile from service com.google.myApp.v1 and endpoint hT4- and payload -6821529802993021226
03-24 14:31:03.805 24644 26856 V NearbyConnection: Payload com.google.android.gms.nearby.connection.Payload@16edba2
03-24 14:31:03.805 24644 26856 V NearbyConnection: payload.getType() 2
03-24 14:31:03.805 24644 26856 V NearbyConnection: payloadFileData awesomePhoto.WEBP:{"description":"a flower"}
03-24 14:31:03.805 24644 26856 V NearbyConnection: payloadFilename awesomePhoto.WEBP
03-24 14:31:03.805 24644 26856 V NearbyConnection: payloadMetadata {"description":"a flower"}
03-24 14:31:03.806 24644 26856 V NearbyConnection: Cannot convert to file.
Question/s: Any idea why payload.asFile().asJavaFile() returns null when retrying saveFile? Is it that the initial permissions failure causes the payload content to somehow be destroyed within the NearbyConnection cache so there is nothing to call payload.asFile().asJavaFile() on? Although I find it strange that calling payload.getType() works and other metadata still exists on the payload but asFile() fails. Any thoughts here would be amazing.
Assumption/Hypothesis: After the final payload is delivered, Nearby Connections attempts to write the file which, if the permissions are not given, fails. Therefore, regardless if permissions are then granted after, that final payload will still not have a file associated and, as such, will forever fail. If this is correct then there is no other option than to resend the file I'm guessing.
Hey @Faolain - i'm not entirely sure what's going on here either. Your use case should work.
The payload is still in the mReceivedPayloads array otherwise you'd get Cannot find payload.
I don't think it would attempt to write the file if no permissions. It may be the underlying native cleaning up files? That doesn't make much sense though either that a only a failed permission check would cause that.
I'm sorry but I don't have time to do a deeper investigation at the moment.
Thanks @butchmarshall appreciate it, turns out the google sdk is caching the failures which is leading to this issue. Xlythe submitted a bug ticket to remedy that.
Hey Butch, first need to say amazing library!
I have a question regarding the ability to call
Nearby.saveFile(serviceId,endpointId,payloadId)
after an initial permission failure. Currently, as long as a user has granted permissions to READ/WRITE external storage, callingNearby.saveFile()
has the promise resolve successfully. If permissions are not granted or are revoked before calling saveFile, one encounters a promise rejection. Until here things are still behaving as expected.However, in my case I am trying to offer the user the ability to retry executing
saveFile()
at a later point by storing theserviceId
,endpointId
, andpayloadId
before initially calling saveFile. This way, oncesaveFile()
is called and it fails, the user can be prompted to grant permissions within their settings or elsewhere and try calling it again. The problem is that when I allow the user to retry using the sameserviceId
,endpointId
, andpayloadId
which previously failed due to permissions not being granted, the promise still rejects.When I
adb logcat
I see it is failing with the message03-24 14:31:03.806 24644 26856 V NearbyConnection: Cannot convert to file.
, which is line #1501 herereact-native-google-nearby-connection/android/src/main/java/com/butchmarshall/reactnative/google/nearby/connection/NearbyConnectionModule.java
Lines 1468 to 1526 in 44f1699
In other words it seems that
File payloadFile = payload.asFile().asJavaFile();
isnull
. I decided to log every payload variable untilpermissionsCheck
fires and this is the below output:Question/s: Any idea why
payload.asFile().asJavaFile()
returns null when retryingsaveFile
? Is it that the initial permissions failure causes the payload content to somehow be destroyed within the NearbyConnection cache so there is nothing to callpayload.asFile().asJavaFile()
on? Although I find it strange that callingpayload.getType()
works and other metadata still exists on the payload butasFile()
fails. Any thoughts here would be amazing.Assumption/Hypothesis: After the final payload is delivered, Nearby Connections attempts to write the file which, if the permissions are not given, fails. Therefore, regardless if permissions are then granted after, that final payload will still not have a file associated and, as such, will forever fail. If this is correct then there is no other option than to resend the file I'm guessing.
Stackoverflow link: https://stackoverflow.com/questions/55328027/nearbyconnection-payload-asfile-asjavafile-is-null-when-retrying-to-savefil
The text was updated successfully, but these errors were encountered: