mannprerak2 / nearby_connections

Flutter plugin (android) for sharing bytes and files Offline, (Based on the android Nearby Connections API)
https://pub.dev/packages/nearby_connections
BSD 2-Clause "Simplified" License
94 stars 30 forks source link

files not receiving on android 11 #33

Closed devalanrs closed 3 years ago

devalanrs commented 3 years ago
Error Logs D/nearby_connections(17721): ad.onConnectionResult D/nearby_connections(17721): onPayloadReceived D/nearby_connections(17721): onPayloadTransferUpdate I/flutter (17721): Tt3c: -4780165049267211412:IMG_20210409_181224.jpg I/flutter (17721): NoSuchMethodError: The method 'exists' was called on null. I/flutter (17721): Receiver: null I/flutter (17721): Tried calling: exists() I/flutter (17721): InProgress D/nearby_connections(17721): onPayloadTransferUpdate I/flutter (17721): Success W/NearbyConnections(17721): Failed to create Payload from ParcelablePayload: Java file not found at /storage/emulated/0/Download/.nearby/-4780165049267211412 W/NearbyConnections(17721): java.io.FileNotFoundException: open failed: EACCES (Permission denied) W/NearbyConnections(17721): at android.os.ParcelFileDescriptor.openInternal(ParcelFileDescriptor.java:344) W/NearbyConnections(17721): at android.os.ParcelFileDescriptor.open(ParcelFileDescriptor.java:231) W/NearbyConnections(17721): at com.google.android.gms.nearby.connection.Payload$File.zza(Unknown Source:12) W/NearbyConnections(17721): at com.google.android.gms.internal.nearby.zzfl.zza(Unknown Source:81) W/NearbyConnections(17721): at com.google.android.gms.internal.nearby.zzav.zza(Unknown Source:5) W/NearbyConnections(17721): at com.google.android.gms.internal.nearby.zzdx.dispatchTransaction(Unknown Source:28) W/NearbyConnections(17721): at com.google.android.gms.internal.nearby.zzb.onTransact(Unknown Source:22) W/NearbyConnections(17721): at android.os.Binder.execTransactInternal(Binder.java:1159) W/NearbyConnections(17721): at android.os.Binder.execTransact(Binder.java:1123) D/nearby_connections(17721): onPayloadReceived D/AndroidRuntime(17721): Shutting down VM E/AndroidRuntime(17721): FATAL EXCEPTION: main
mannprerak2 commented 3 years ago

Did you request the Read files permission on runtime?

mannprerak2 commented 3 years ago

I am able to replicate this on Android 11.

Crash Logs ``` W/NearbyConnections(19143): Failed to create Payload from ParcelablePayload: Java file not found at /storage/emulated/0/Download/.nearby/-5722419836622414852 W/NearbyConnections(19143): java.io.FileNotFoundException: open failed: EACCES (Permission denied) W/NearbyConnections(19143): at android.os.ParcelFileDescriptor.openInternal(ParcelFileDescriptor.java:344) W/NearbyConnections(19143): at android.os.ParcelFileDescriptor.open(ParcelFileDescriptor.java:231) W/NearbyConnections(19143): at com.google.android.gms.nearby.connection.Payload$File.zza(Unknown Source:12) W/NearbyConnections(19143): at com.google.android.gms.internal.nearby.zzfl.zza(Unknown Source:81) W/NearbyConnections(19143): at com.google.android.gms.internal.nearby.zzav.zza(Unknown Source:5) W/NearbyConnections(19143): at com.google.android.gms.internal.nearby.zzdx.dispatchTransaction(Unknown Source:28) W/NearbyConnections(19143): at com.google.android.gms.internal.nearby.zzb.onTransact(Unknown Source:22) W/NearbyConnections(19143): at android.os.Binder.execTransactInternal(Binder.java:1170) W/NearbyConnections(19143): at android.os.Binder.execTransact(Binder.java:1134) D/nearby_connections(19143): onPayloadReceived D/AndroidRuntime(19143): Shutting down VM E/AndroidRuntime(19143): FATAL EXCEPTION: main E/AndroidRuntime(19143): Process: com.pkmnapps.nearby_connections_example, PID: 19143 E/AndroidRuntime(19143): java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.io.File.getAbsolutePath()' on a null object reference E/AndroidRuntime(19143): at com.pkmnapps.nearby_connections.NearbyConnectionsPlugin$13.onPayloadReceived(NearbyConnectionsPlugin.java:421) E/AndroidRuntime(19143): at com.google.android.gms.internal.nearby.zzaw.notifyListener(Unknown Source:10) E/AndroidRuntime(19143): at com.google.android.gms.common.api.internal.ListenerHolder.notifyListenerInternal(com.google.android.gms:play-services-base@@17.3.0:18) E/AndroidRuntime(19143): at com.google.android.gms.common.api.internal.ListenerHolder$zaa.handleMessage(com.google.android.gms:play-services-base@@17.3.0:6) E/AndroidRuntime(19143): at android.os.Handler.dispatchMessage(Handler.java:106) E/AndroidRuntime(19143): at com.google.android.gms.internal.base.zap.dispatchMessage(com.google.android.gms:play-services-base@@17.3.0:8) E/AndroidRuntime(19143): at android.os.Looper.loop(Looper.java:245) E/AndroidRuntime(19143): at android.app.ActivityThread.main(ActivityThread.java:8004) E/AndroidRuntime(19143): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(19143): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631) E/AndroidRuntime(19143): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978) I/Process (19143): Sending signal. PID: 19143 SIG: 9 ```
mannprerak2 commented 3 years ago

Glad to see there are so many users 😄

Since Android 10, they have changed the storage access rules and we can't get the file path using my current implementation.

For android 10: you can add this attribute to your application element in your AndroidManifest.xml (just a quick fix until I fix the plugin)

<application ...
android:requestLegacyExternalStorage="true" 
...>

For android 11 and beyond: Seems like I'll have update the plugin code. I'll try to make a fix soon

mannprerak2 commented 3 years ago

This is blocked by the underlying android nearby connections SDK. See this issue: https://github.com/android/connectivity-samples/issues/176

GauravGunjal43 commented 3 years ago

Glad to see there are so many users 😄

Since Android 10, they have changed the storage access rules and we can't get the file path using my current implementation.

For android 10: you can add this attribute to your application element in your AndroidManifest.xml (just a quick fix until I fix the plugin)

<application ...
android:requestLegacyExternalStorage="true" 
...>

For android 11 and beyond: Seems like I'll have update the plugin code. I'll try to make a fix soon

this works but the file is received in a hidden folder named '.nearby' in the downloads directory. How do i change the directory of received files because it is not accessible.

mannprerak2 commented 3 years ago

@GauravGunjal43

this works but the file is received in a hidden folder named '.nearby' in the downloads directory. How do I change the directory of received files because it is not accessible?

Ah, yes they have been rolling this out for a few weeks(The files are now being saved to the .nearby folder). Are you sure you not able to rename the file to another directory on Android 10? Can you provide any error logs for this?

Note that it may not be possible for us to be able to do anything until they resolve the issue with the underlying SDK as it does not expose the file URI of the payload.

GauravGunjal43 commented 3 years ago

any updates on this?

mannprerak2 commented 3 years ago

We can't do anything until they fix this in the underlying android nearby connections library.

mannprerak2 commented 3 years ago

Hi everyone, I have released a new version with a fix for this - https://pub.dev/packages/nearby_connections/versions/3.1.0