0

I'm implementing file transfer through Android Beam in my app.

I have 2 phone I can use for testing: a Samsung Galaxy A6 and my Nexus 5x.

On the Galaxy there is no problem on the receiving side. The file is download in the "Download" folder and I get the path for the file from the intent, just like it's explained in the android dev page.

On my Nexus 5x the file get downloaded in the "beam" folder, but from the intent I get "beam/beam/file.txt" and I have to manually remove one of the "beam" in the path.

Why the hell is this happening?

And even if I managed to remove the "beam" part from it, I still miss the complete path to the file.

While on the galaxy the path from the intent is

/storage/emulated/0/Download/...

On my nexus 5x is just:

beam/beam/...

Just.... what?

Is there anyway I can fix this or do I manually have to check if the beam folder is in the external or internal memory and then add the correct prefix?

Currently this is the code I use to retrieve the path when handling the "view intent" that should contain the file I received:

mIntent.data?.also { beamUri ->
        val pathSegments = beamUri.pathSegments
        var path : String? = beamUri.path

        // Edge Case for Nexus 5X
        if(pathSegments.size == 3){
            if((pathSegments[0] == pathSegments[1]) && pathSegments[0] == "beam"){
                path = "${pathSegments.first()}${File.separator}${pathSegments.last()}"
            }
        }
        ...
}

EDIT 1: Logging beamUri as suggested in the comments below, on the nexus 5x, the file is received as a content and on the Galaxy as a file.

I'll now implement the method to deal with content as well, but why the difference between the two?

Syrinxos
  • 137
  • 1
  • 2
  • 8
  • 1
    what is `beamUri` like? try to log it with `Log.d` – pskink Aug 17 '18 at 12:23
  • beamURI is (depending on the device as written before) `/storage/emulated/0/Download/...` or `beam\beam\...` – Syrinxos Aug 17 '18 at 12:55
  • 1
    no, Uri starts with scheme like file:// or content:// etc – pskink Aug 17 '18 at 12:59
  • Oh, apparently is received as a file on the Galaxy and as a content on my nexus 5x. – Syrinxos Aug 17 '18 at 13:32
  • 2
    so you have the answer for your question – pskink Aug 17 '18 at 13:34
  • Thank you. But why are those two thing received in two different ways? The file being sent is the same for both of the devices – Syrinxos Aug 17 '18 at 13:35
  • 1
    this is the same way: you have Uri, now read ContentProvider API docs on how to read data from your Uri – pskink Aug 17 '18 at 13:37
  • Yes, it's been solved. I'd like to know why on some devices I can access it as a file while in other devices I need to use a content provider. – Syrinxos Aug 18 '18 at 08:34
  • you have to always use `ContentResolver` when dealing with `Uri`s - i just realized that i told you to read `"ContentProvider API docs"` - of course its `ContentResolver` - sorry for that ;-( – pskink Aug 18 '18 at 08:34

0 Answers0