I'm developing an Android app that need to read csv files saved by another app. However, I'm not sure how to access the csv files saved by another app. Is there anyone have some suggestions about this?
Asked
Active
Viewed 40 times
1 Answers
0
You can use Cloud Firestore. Or if you want to read csv from storage:
private void loadCsvFromStorage() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, PICK_CSV_REQUEST);
}
// When results returned
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_CSV_REQUEST && resultCode == RESULT_OK
&& data != null && data.getData() != null){
Uri uri = data.getData();
if(uri.getPath().endsWith(".csv")) {
try {
InputStream inputStream = getContentResolver().openInputStream(data.getData());
BufferedReader reader = new BufferedReader(
new InputStreamReader(inputStream, Charset.forName("UTF-8"))
);
String line = "";
try {
reader.readLine();
while ((line = reader.readLine()) != null) {
String[] tokens = line.split(",");
//Read data
}
Toast.makeText(Activity.this, "Done!", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
}
} catch (FileNotFoundException e) {
Toast.makeText(Activity.this, "Failed!", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
else{
Toast.makeText(Activity.this, "Please select the .csv file!", Toast.LENGTH_SHORT).show();
}
}
}
Refer to the answer Reading CSV File In Android App

Andy Alert
- 1
- 2
-
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/32325499) – vanje Jul 27 '22 at 20:25