-1

maybe I can get help here. I'm working on an Android app in Java and try to pick a .csv file to import some data:

    public void onButtonImportClick(View view) {
        Log.d(TAG, "onButtonImportClick");
        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("text/*");
        intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] { "text/csv", "text/plain" });
        someActivityResultLauncher.launch(intent);
    }

The picker shows files but all are greyed out, besides the .txt files. Actually I expected to get .csv and .txt files. Obviously something is not correct with MIME type setting.
Any ideas or suggestions?

1 Answer 1

0

Use opencsv for read CSV file.

Add below gradle into gradle file.

implementation 'com.opencsv:opencsv:4.6'

Implement below function for read csv file

CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
List myEntries = reader.readAll();
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, but where do I store the yourfile.csv? Ideally it should be in the Download folder of the device. If I do not use a picker, user will not be able to navigate, right?
@reichi Yes, you have to select file from local storage & give that file to FileReader
Okay, but the file will not be in the local storage. It will be provided from user in the download folder. I think I need the file picker.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.