Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
315 views
in Technique[技术] by (71.8m points)

Import and export CSV file in android

I have an app where I want to be able to export to/import from CSV Files.

In a Use-Case I want to export data into a CSV File, connect the phone to a PC and edit the CSV there and re-import the file afterwards back into the app.

I am currently using a Motorola Razor I (latest android version) and no matter where I try to save the file, it does not appear to be public when connecting the phone to a computer (it's not there)

I can see the file on the android File Browser itself, so it is there, but in Windows Explorer the file is not there.

What would be a proper way to implement such a feature:

  • Export to CSV
  • Edit on Computer
  • Reimport same file

I've used function getExternalDirectory() and have also tried getExternalDirectoryPublic() - in either cases the file doesn't appear on the computer.

Any hints highly appreciated!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Ok, it seems, I missed something in order to make the file appear on the computer. Thing is, android treats the files not directly, but the MediaScanner does - so all I had to do is tell the MediaScanner about the new File and it works!

Writing the File with getExternalStoragePublicDirectory() and after the file is saved call

MediaScannerConnection.scanFile(MainActivity.this, new String[] { filename }, null, null);

to tell the MediaScanner about the newly file

Hopefully anyone find it useful


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...