Pergunta

I am operating with a standard Nexus 5 which is un-rooted with standard vanilla android 4.4.2

I would like to create a new file that is accessible in Windows through the standard USB connector. I don't want to root my phone.

Here is a snippet of my code:

File outputFile = new File(new File(getFilesDir().getParentFile(), "assets"), "example.xml");

Does anyone know of any directories that are writable in app + readable via USB transfer ?

Thank you for any help ! :)

Foi útil?

Solução

You can create the file on the External Storage like this:

String fileName = "example.xml";
String myDirectory = "myDirectory";
String externalStorage = Environment.getExternalStorageDirectory().getAbsolutePath();

File outputFile = new File(externalStorage + File.separator + myDirectory + File.separator + fileName);

Outras dicas

Turns out there is not a automatic filesystem refresh for files displayed through USB, in my case I used a android file manager to view the files before they became visible over USB. The above answer supported me in getting to this answer.

I was also looking to do something similar as OP Snake. I used

Environment.getExternalStorageDirectory().getAbsolutePath()

to place a file in the top directory when opening Windows Explorer and going to my Android device.

However, the following post made it clear that you have to reboot your phone before you can actually see the newly created file. I had to do this extra step as well.

Source: https://android.stackexchange.com/questions/63640/how-to-access-storage-emulated-0-from-pc

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top