Resolved How do I detect usb storage in unity android?

Duvyanshu

~matchmaker~
Joined
Feb 20, 2020
Messages
26
Programming Experience
1-3
I am trying to read a text file from usb storage through my unity android game in unity 2018.4.9.
I am using java class GetExternalFilesDir but it doesn't reads Usb storage in 90% android devices. It reads only internal storage and sd card(if inserted).

I am struggling with it for weeks now and I will be very grateful if you can provide a fix for this.

Thanks in advance.
 
I
Why can't I do that? To create data persistence between android and windows version of the app I am saving some data to textfiles in usb storage so that it can be passed from windows to android and vice versa. How do iI make you believe its nothing unethical?
I am using VS2017 but using unity because of its IDE.
 
To me, a less "hacky" way is to require a desktop app for the user to install/run. Both the desktop app and and your Android app can talk to each other using the network -- either peer-to-peer TCP or UDP, or through a web service hosted online somewhere. This provides full awareness to the PC user that they are actively doing something that allows access to the PC.

I believe that AirDroid has gone down this path. AirDroid used to be web based on the PC but now they are app based. and as I recall at one point they supported tethering via USB (and then using the same ADB channels/protocols). I don't think the tethering feature is available anymore.
 
Last edited:
Anyway, from the documentation for getExternalFilesDir():
Shared storage devices returned here are considered a stable part of the device, including physical media slots under a protective cover. The returned paths do not include transient devices, such as USB flash drives connected to handheld devices.
 
To me, a less "hacky" way is to require a desktop app for the user to install/run. Both the desktop app and and your Android app can talk to each other using the network -- either peer-to-peer TCP or UDP, or through a web service hosted online somewhere. This provides full awareness to the PC user that they are actively doing something that allows access to the PC.

I believe that AirDroid has gone down this path. AirDroid used to be web based on the PC but now they are app based. and as I recall at one point they supported tethering via USB (and then using the same ADB channels/protocols).
I appreciate it. Finally someone talking some sense. Sir I wanted to make the whole process online so we can allow online updates as well(obviously when requested by user) but client asked to keep it USB locked for first 20 Build distribution. The App data persistence between android and PC is obviously well documented. That is what makes this software unique in its own way. It save name and Date of birth profiles to be read in different machines wherever USB key is connected.

I think I forgot to mention that I can't afford U2F keys in my current budget so I am making one in a normal storage.
The way it works is: Software detects the specific textfile in the USB Storage location and if the text in it matches with the string inside the software, the software will be registered and allowed to use further. I think that should clear everyone's doubts.
 
Last edited:
IMPORTANT!!

I think I forgot to mention that I can't afford U2F keys in my current budget so I am making one in a normal storage.
The way it works is: Software detects the specific textfile in the USB Storage location and if the text in it matches with the string inside the software, the software will be registered and allowed to use further. I think that should clear everyone's doubts.
 
Last edited:
So basically you are trying to build a poor man's security dongle.
 
@Skydiver I have been so patient since I posted this thread. Now that all has been cleared out please help me do it the right way. I will send you all a post-production release as well, as a Token of Gratitude.
 
Even if Skydiver does decide to help you. Both of you are not taking into account that the storage media between android and the PC is not the same and there is a rather complicated process to successfully transfer files between the two completely different volumes. Not to mention, that your app will eventually be scanned and pulled from the play store (if you put it up there) if you are accessing USB storage without acquiring the permissions from the user first which is procedural.
Now that all has been cleared
All has not been cleared, you haven't explained why you started out telling us that it was a game, and then shifted to saying it was an app when I questioned you about why a game would need USB access. The two are completely different entirely. From what you started out explaining to now is a completely new set of information which describes your game as something that it is not and something which is completely different and I still don't believe you.
 
Even if Skydiver does decide to help you. Both of you are not taking into account that the storage media between android and the PC is not the same and there is a rather complicated process to successfully transfer files between the two completely different volumes. Not to mention, that your app will eventually be scanned and pulled from the play store (if you put it up there) if you are accessing USB storage without acquiring the permissions from the user first which is procedural.

All has not been cleared, you haven't explained why you started out telling us that it was a game, and then shifted to saying it was an app when I questioned you about why a game would need USB access. The two are completely different entirely. From what you started out explaining to now is a completely new set of information which describes your game as something that it is not and something which is completely different and I still don't believe you.

Yes @Sheepings I said it earlier that it is a game. Sorry for that my misunderstanding, I didn't knew calling it a game or an app would make that big a difference. It is an app made in GameDevelopment Studio with VS2017 community edition. I mentioned earlier it is not being uploaded on play store. It will be distributed externally. USB will act a security dongle and medium to share user entries in the software(Name and Date of Birth) between Android and OS.
 
I agree that trying access USB is very suspicious. It feels like a perfect vector to get into a lot of machines. As I was telling @Sheepings offline, when walking through an airport or most public libraries, it is so common to see people with their phone plugged in to their laptop presumably to keep the phone charged. All it will take is the wrong set of permissions and/or the user finally getting tired of the "allow access" prompts and just accepts.

Instead of depending on finding a file on USB, why not make a real 2FA where the user enters a password, and receives a text message?
 
I agree that trying access USB is very suspicious. It feels like a perfect vector to get into a lot of machines. As I was telling @Sheepings offline, when walking through an airport or most public libraries, it is so common to see people with their phone plugged in to their laptop presumably to keep the phone charged. All it will take is the wrong set of permissions and/or the user finally getting tired of the "allow access" prompts and just accepts.

Instead of depending on finding a file on USB, why not make a real 2FA where the user enters a password, and receives a text message?
Maybe in upcoming versions. For now, client demands the Security through USB. I can't deny, He can't Afford U2F keys so I promised to make one in regular storages.
 
I agree that trying access USB is very suspicious. It feels like a perfect vector to get into a lot of machines. As I was telling @Sheepings offline, when walking through an airport or most public libraries, it is so common to see people with their phone plugged in to their laptop presumably to keep the phone charged. All it will take is the wrong set of permissions and/or the user finally getting tired of the "allow access" prompts and just accepts.

Instead of depending on finding a file on USB, why not make a real 2FA where the user enters a password, and receives a text message?
Only permissions I have addes is to access external storage. I dont think anymore will be required.
 
It is an app made in GameDevelopment Studio with VS2017 community edition.
I thought you said it was created in Unity?

Surely you remember which software you created it with...
client demands the Security through USB. I can't deny
Tell your client they are asking you to do something extremely difficult which I've only seen big companies such as Nikon, Panasonic, Sony, and other big brand companies do with their camera software apps, and your client should consider other alternatives. Three years ago, Canon adapted to use a PC app to transfer files from the camera instead of from Android app to PC, because of the difficulties involved with media volumes being completely different, they abandoned the process. If you think you are a better dev than what Canon can hire, then knock yourself out and give it a go. But I still won't be participating in helping you with it.
 
Back
Top Bottom