user5943422
user5943422

Reputation:

Moving a file from a PC to an Android-readable location

I am creating a simple Android app. To run properly, it needs the contents of a file (example.xml) that is currently on my PC.

On creation, the app would look for the file, and then do some stuff with it.

@Override
protected void onCreate(Bundle savedInstanceState)
{
    ...
    File file = new File("I wish I knew what to put here");
    doStuffWithFile(file);
}

Unfortunately, I don't know where to put the file.

I need a location in internal storage to which both my PC and my Android app have access.

Is there such a location? If so, what file path String would I use to access it?

Upvotes: 0

Views: 39

Answers (2)

ChristopheCVB
ChristopheCVB

Reputation: 7315

You could include the file in the assets folder of your project and then retrieve it with this.getContext().getAssets().open("example.xml")

Upvotes: 0

beta
beta

Reputation: 131

You can get the Download folder by using Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)

Then you can add a filename and use this e.g. with DownloadManager

Upvotes: 1

Related Questions