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.
 
Please explain that one more time? ?

You have a roid game created in Unity 3D which is likely running on a phone, and you want this game to read files on a USB port?

Sounds like a very strange request. Why would a game need to access files on a another device if its only a game? If I have this wrong, then please do explain precisely and clearly how this is expected to work and why you need it?

I will just point out that off the bat, Android doesn't just throw around those types of permissions, and any attempts to access such devices will be met with permission restrictions. And the correct way to do it would be to acquire the permission from the user of your "game" first, otherwise you risk your "game" being pulled from the play store for violating security policies. Try going the route of [REDACTED SUPPORT LINK], and try implementing the standard procedures first.

I am still struggling to understand why a game of all things would need to read or write to an external USB device.

EDIT : Removed link. Pending mod inspection of your question.
 
Last edited:
I have to agree that the idea of mobile game reading from a USB device is very unusual and, in fact, I've never heard of it being done before. I'd say that the two most likely possibilities are that you are very misguided in trying to do this in the first place and should look at loading the data from some other source or you're actually trying to do something dodgy. If you cannot provide a reasonable explanation for this then I think that we will have to close this thread.
 
should look at loading the data from some other source or you're actually trying to do something dodgy.
John, I know as a moderator, you need to be very rational and reasonable, calm and collective; collective in the sense that you need to acquire necessary information before making a brisk action such as closing ones topic and to allow the OP the opportunity to be specific about what they are doing.

However, it appears, that storing the data of whatever this "game" is, is not adequate for our OP to store said data in the inbuilt local storage of the phone or external SD card of that phone.
It reads only internal storage and sd card(if inserted).

If alarm bells are not going off yet. They really should be. I've thought about this for a while now and can only conclude the later of your assumption is true and that our OP is doing something dodgy. What our OP appears to be asking for is a way to bypass the permissions put in place by Android to circumvent just any app from accessing external storage of the devices its connected too and android imposes stricter permission policies for allowing any app to access the USB port for file transfer or file/directory lookup access.

I can only conclude this "game" consists of ransomware to collect specific personal data from any devices it is connected to. If this was a legitimate question, and our OP was creating a legitimate "game", they should be complying with Android/Google Play policy of asking the user to first grant such permissions to the game to allow such access, but that isn't the question here. And even if it was, why would a "game" need access to the USB port at all?

I can't help but believe with the spate and rise of game adverts on facebook which are infecting users phones and compromising security which has been reported numerously on the news, and that this is just another one of those cases. No matter what reply our OP gives. There is just no justification for not using internal storage, or at least SD storage should large amounts of space be required for whatever this "game" is doing, and under no circumstances should any "game" be allowed access a users USB port which is typically only used for two-way file transfer between PC and phone.

Ultimately the choice to close this topic is yours to make, but I fail to see how any good intentions or a logical answer can come of a question of this nature.

Lastly, If you invoke file transfer from a connected USB => Phone, you have free will to transfer files to and from : these storage volumes and the volumes of that on the PC its connected too :

Screenshot_78.jpg


Do you still think it should remain and open thread?
 
Its not a game. Its a software that I coded on unity and software will be distributed by apk. Apk will read a text file in usb to run on android devices.
I have asked for external permissions as well and software asks for it when it runs on android.
 
John, I know as a moderator, you need to be very rational and reasonable, calm and collective; collective in the sense that you need to acquire necessary information before making a brisk action such as closing ones topic and to allow the OP the opportunity to be specific about what they are doing.

However, it appears, that storing the data of whatever this "game" is, is not adequate for our OP to store said data in the inbuilt local storage of the phone or external SD card of that phone.


If alarm bells are not going off yet. They really should be. I've thought about this for a while now and can only conclude the later of your assumption is true and that our OP is doing something dodgy. What our OP appears to be asking for is a way to bypass the permissions put in place by Android to circumvent just any app from accessing external storage of the devices its connected too and android imposes stricter permission policies for allowing any app to access the USB port for file transfer or file/directory lookup access.

I can only conclude this "game" consists of ransomware to collect specific personal data from any devices it is connected to. If this was a legitimate question, and our OP was creating a legitimate "game", they should be complying with Android/Google Play policy of asking the user to first grant such permissions to the game to allow such access, but that isn't the question here. And even if it was, why would a "game" need access to the USB port at all?

I can't help but believe with the spate and rise of game adverts on facebook which are infecting users phones and compromising security which has been reported numerously on the news, and that this is just another one of those cases. No matter what reply our OP gives. There is just no justification for not using internal storage, or at least SD storage should large amounts of space be required for whatever this "game" is doing, and under no circumstances should any "game" be allowed access a users USB port which is typically only used for two-way file transfer between PC and phone.

Ultimately the choice to close this topic is yours to make, but I fail to see how any good intentions or a logical answer can come of a question of this nature.

Lastly, If you invoke file transfer from a connected USB => Phone, you have free will to transfer files to and from : these storage volumes and the volumes of that on the PC its connected too :

View attachment 835

Do you still think it should remain and open thread?
Sir this is not a game and surely i am not putting it on play store. The app will read a text file in usb in order to work. That is all. It is being coded in unity.
 
I am trying to read a text file from usb storage through my unity android game in unity
Its not a game. Its a software that I coded on unity
You're contradicting yourself or You're telling lies. You don't create software in unity, that's what visual studio 2019 is for; creating software. You use unity for game development.

Please don't try to bullshit me. Telling lies is patronising.

I've been a software programmer for 20 years or so, I make android apps, desktop games, and write software for a career in over 20 different languages. I've also been participating member of community forums just like this one long enough to spot when someone is blowing smoke up my ass.
 
You're contradicting yourself or You're telling lies. You don't create software in unity, that's what visual studio 2019 is for; creating software. You use unity for game development.

Please don't try to bullshit me. Telling lies is patronizing.

I've been a software programmer for 20 years or so, I make android apps, desktop games, and write software for a career in over 20 different languages. I've also been participating member of community forums just like this one long enough to spot when someone is blowing smoke up my ass.

Respected sir, I am not lying and I don't know what makes you think I am lying?
I know unity is for game development but with a little smartness, we can create apps as well on it. No one is looking at the code of my software.

I can share videos, images, and gif as well forthis solution. I have posted various threads across the web to find the answer to this issue while I was completing other modules (I can share links to that too).

Visual studio unity 2017 supports all c# libraries, system files, LINQ, so I used it to build this one software, I've made test games as well, but I took a risk to see if anything out of the box can be done so I made a software in it which is also complete. The software also generates PDF using itext7 of at least 20 pages. All of you will now say that why use pdf creation in games? I am saying it again, it is not a game and yes it is on unity and yes itis just another app.
 
Please explain that one more time? ?

You have a roid game created in Unity 3D which is likely running on a phone, and you want this game to read files on a USB port?

Sounds like a very strange request. Why would a game need to access files on a another device if its only a game? If I have this wrong, then please do explain precisely and clearly how this is expected to work and why you need it?

I will just point out that off the bat, Android doesn't just throw around those types of permissions, and any attempts to access such devices will be met with permission restrictions. And the correct way to do it would be to acquire the permission from the user of your "game" first, otherwise you risk your "game" being pulled from the play store for violating security policies. Try going the route of [REDACTED SUPPORT LINK], and try implementing the standard procedures first.

I am still struggling to understand why a game of all things would need to read or write to an external USB device.

EDIT : Removed link. Pending mod inspection of your question.

software asks permissions for external storage, but I am not sure if there is special permission to read usb storage.
 
I have to agree that the idea of mobile game reading from a USB device is very unusual and, in fact, I've never heard of it being done before. I'd say that the two most likely possibilities are that you are very misguided in trying to do this in the first place and should look at loading the data from some other source or you're actually trying to do something dodgy. If you cannot provide a reasonable explanation for this then I think that we will have to close this thread.
You said it right, it is tricky but not misguided I think. Why is it unusual to build something that does something that it has never done before?
 
John, I know as a moderator, you need to be very rational and reasonable, calm and collective; collective in the sense that you need to acquire necessary information before making a brisk action such as closing ones topic and to allow the OP the opportunity to be specific about what they are doing.

However, it appears, that storing the data of whatever this "game" is, is not adequate for our OP to store said data in the inbuilt local storage of the phone or external SD card of that phone.


If alarm bells are not going off yet. They really should be. I've thought about this for a while now and can only conclude the later of your assumption is true and that our OP is doing something dodgy. What our OP appears to be asking for is a way to bypass the permissions put in place by Android to circumvent just any app from accessing external storage of the devices its connected too and android imposes stricter permission policies for allowing any app to access the USB port for file transfer or file/directory lookup access.

I can only conclude this "game" consists of ransomware to collect specific personal data from any devices it is connected to. If this was a legitimate question, and our OP was creating a legitimate "game", they should be complying with Android/Google Play policy of asking the user to first grant such permissions to the game to allow such access, but that isn't the question here. And even if it was, why would a "game" need access to the USB port at all?

I can't help but believe with the spate and rise of game adverts on facebook which are infecting users phones and compromising security which has been reported numerously on the news, and that this is just another one of those cases. No matter what reply our OP gives. There is just no justification for not using internal storage, or at least SD storage should large amounts of space be required for whatever this "game" is doing, and under no circumstances should any "game" be allowed access a users USB port which is typically only used for two-way file transfer between PC and phone.

Ultimately the choice to close this topic is yours to make, but I fail to see how any good intentions or a logical answer can come of a question of this nature.

Lastly, If you invoke file transfer from a connected USB => Phone, you have free will to transfer files to and from : these storage volumes and the volumes of that on the PC its connected too :

View attachment 835

Do you still think it should remain and open thread?
Oh My god dear sir please, there are no virus or spams in this app made on unity(yes, I coded it on unity, (It was a risk but I took it anyways to see where it leads.)

Software is complete and it is setup to ask for external storage permissions in my manifest as well. I didn't knew dong something out of the box will be so suspicious. This software won't even run on adverts. I am ready to share screenshots and gif workings of this software from unity editor as well. I request you to look past sterotypes. I coded the software on unity, yes it is an utility app and not a game. No it won't be uploaded on play store.
 
John, I know as a moderator, you need to be very rational and reasonable, calm and collective; collective in the sense that you need to acquire necessary information before making a brisk action such as closing ones topic and to allow the OP the opportunity to be specific about what they are doing.

However, it appears, that storing the data of whatever this "game" is, is not adequate for our OP to store said data in the inbuilt local storage of the phone or external SD card of that phone.


If alarm bells are not going off yet. They really should be. I've thought about this for a while now and can only conclude the later of your assumption is true and that our OP is doing something dodgy. What our OP appears to be asking for is a way to bypass the permissions put in place by Android to circumvent just any app from accessing external storage of the devices its connected too and android imposes stricter permission policies for allowing any app to access the USB port for file transfer or file/directory lookup access.

I can only conclude this "game" consists of ransomware to collect specific personal data from any devices it is connected to. If this was a legitimate question, and our OP was creating a legitimate "game", they should be complying with Android/Google Play policy of asking the user to first grant such permissions to the game to allow such access, but that isn't the question here. And even if it was, why would a "game" need access to the USB port at all?

I can't help but believe with the spate and rise of game adverts on facebook which are infecting users phones and compromising security which has been reported numerously on the news, and that this is just another one of those cases. No matter what reply our OP gives. There is just no justification for not using internal storage, or at least SD storage should large amounts of space be required for whatever this "game" is doing, and under no circumstances should any "game" be allowed access a users USB port which is typically only used for two-way file transfer between PC and phone.

Ultimately the choice to close this topic is yours to make, but I fail to see how any good intentions or a logical answer can come of a question of this nature.

Lastly, If you invoke file transfer from a connected USB => Phone, you have free will to transfer files to and from : these storage volumes and the volumes of that on the PC its connected too :

View attachment 835

Do you still think it should remain an open thread?
Sir, I respect your authority and by all means, if everyone has made up their mind that it is not ethical, go ahead close it and block me off this forum but I have really coded a simple utility software on unity(I know it's for games). It uses visual studio so I thought to make a simple calculation software that generated a pdf report based on calculation as well. Now you should think why would a game generate pdf reports, but again it is not a game. I did an experiment on unity to see If I can make a working utility as well. It worked, I completed the software but this one thing I am struggling with. I got it to work on standalone using DriveInfo class but surely we all know it doesn't work for android which brings me back to my question "How do I read USB on android?"
I am not experienced in Java at all.
 
Has anybody made up their mind to help me out with this? If yes, I will share my code or close the question if no one can help me so I can finally give up. Hopes can be dangerous.
 
I am not convinced that you're being as forthcoming as you should have been from the beginning, I've already expressed why above...

I also don't believe what you are doing is for good intentions, and I'm entitled to my gut feeling and opinions.

I also don't believe that your "game" is an app. And how one distinguishes confusion between the two I will never know.

I've also never seen anyone using Unity to create an "app" while Visual Studio is much more efficient for such task.

I am sorry, but I do not feel the need to contribute any further on this topic. If anyone else feels that you you have genuine intentions, then perhaps they will help you.

My reasoning for this is simple : Almost 2 billion malware installs thwarted by Google Play Protect in 2019 | WeLiveSecurity
There is big business in malware and alot of it is dumped into apps. As I said, I don't believe your intent so I won't be a contributor to the problem Google already struggles to fight, so we will park this one here.

There is no reason why you shouldn't be using internal storage, and there is no reason for you to need to connect to USB!
 
Last edited:
I am not convinced that you're being as forthcoming as you should have been from the beginning, I've already expressed why above...

I also don't believe what you are doing is for good intentions, and I'm entitled to my gut feeling and opinions.

I also don't believe that your "game" is an app. And how one distinguishes confusion between the two I will never know.

I've also never seen anyone using Unity to create an "app" while Visual Studio is much more efficient for such task.

I am sorry, but I do not feel the need to contribute any further on this topic. If anyone else feels that you you have genuine intentions, then perhaps they will help you.

My reasoning for this is simple : Almost 2 billion malware installs thwarted by Google Play Protect in 2019 | WeLiveSecurity
There is big business in malware and alot of it is dumped into apps. As I said, I don't believe your intent so I won't be a contributor to the problem Google already struggles to fight, so we will park this one here.

There is no reason why you shouldn't be using internal storage, and there is no reason for you to need to connect to USB!

Why can't I do that? To create data persistence between android and windows build 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 I make you believe its nothing unethical?
 
Last edited:

Latest posts

Back
Top Bottom