-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?

3
  • 2
    Can you please show to the community what have you done so far? Commented Oct 22, 2015 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] (stackoverflow.com/questions/16672074/…) Roughly third answer down, and so far haven't found much as to allowing users to select a file from a directory Commented Oct 22, 2015 at 14:53
  • Please have a look at the how to ask section! Commented Oct 22, 2015 at 15:51

1 Answer 1

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);
            }
        }
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Hi @Hossein, thanks for the link, however how would I do it so that the user selects which CSV file to import
added file chooser for selecting any csv file

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.