-2

I want to enable my users to be able to import their CSV files into their SQLite Database, for now it will only be for one table which is called Inventory

How would I do it so that the user can select where the CSV file is within the app and then load in the data to the database WITHOUT replacing what is already there?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sjharrison
  • 729
  • 3
  • 16
  • 39
  • 2
    Can you please show to the community what have you done so far? – AuroMetal Oct 22 '15 at 14:50
  • So far I've been looking online and only found examples where CSV files are in an Asset folder which I don't think is going to help me [link] (http://stackoverflow.com/questions/16672074/import-csv-file-to-sqlite-in-android) Roughly third answer down, and so far haven't found much as to allowing users to select a file from a directory – Sjharrison Oct 22 '15 at 14:53
  • Please have a look at the [how to ask](http://stackoverflow.com/help/how-to-ask) section! – jkalden Oct 22 '15 at 15:51

1 Answers1

1

you must read content of csv file and add content to database. this is for read from csv file.

edited

you can using this for read any csv file from storage

public class MainActivity extends AppCompatActivity {

    private static final int REQUEST_CODE = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("file/*");
        startActivityForResult(intent, REQUEST_CODE);

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if(resultCode == RESULT_OK){
            if(requestCode == REQUEST_CODE){
                Uri fileUri = data.getData();

                Log.i(getClass().getName(), "fileUri" + fileUri);
            }
        }
    }
}
Community
  • 1
  • 1
Mohammad Hossein Gerami
  • 1,360
  • 1
  • 10
  • 26