0

I am downloading a .csv file from the internet on my Android phone. This isn't done through my app. However, I want to import this file from the system downloads folder into my raw directory. I select a button in the action bar and call the method below. I'm new to Android and the developer docs kind of suck for beginners. I'm not sure where to start. This is what I've come up with.

I create this implicit intent:

Intent i = new Intent();
        i.setAction(DownloadManager.ACTION_VIEW_DOWNLOADS);
        startActivity(i);

and it shows me the downloads folder. How can I select something from this folder and import it into my raw directory? Do I need to set up a broadcast reciever? Do I need an intent filter? Should I use a service? Am I using the wrong Intent action?

Please cut me a little slack. I'm new and I don't see a lot of good explanations of the process. I would be just as happy if someone just pointed me in the right direction. Thanks in advance.

Jo Momma
  • 1,126
  • 15
  • 31

1 Answers1

0

How can I select something from this folder and import it into my raw directory?

I assume that by "my raw directory", you are referring to raw resources (res/raw/ in an Android project).

If so, resources are read-only at runtime. They are files on your development machine; they are not files on the device. You cannot import things in any fashion that turn them into raw resources at runtime.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • So if I need to import the file to another directory, what would you suggest? Do I need to create one using getDir()? And if so, how do I select a file form the download folder and bring it in to my project? – Jo Momma Mar 01 '18 at 19:47
  • @I'mStillStoopid: "So if I need to import the file to another directory, what would you suggest?" -- I do not quite know what you mean by "import". [Use `ACTION_OPEN_DOCUMENT` to allow the user to pick a document](https://developer.android.com/guide/topics/providers/document-provider.html) (or `ACTION_GET_CONTENT` on older devices, if you `minSdkVersion` is below 19). Then, either use the data immediately, or copy it to [internal storage](https://commonsware.com/blog/2017/11/13/storage-situation-internal-storage.html) or something. – CommonsWare Mar 01 '18 at 19:53
  • Let me try to simplify what I was saying. I want to push a button in my app. That button should open the downloads folder on my device. I want to select a file from the download folder and save it somewhere in my app. So I probably need to create a new directory or store it in my main file directory. But ACTION_OPEN_Document threw an error when I tried it. Claimed that I didn't have an app that could preform that operation. What should I use then to grab a file from downlaods – Jo Momma Mar 02 '18 at 02:47
  • @I'mStillStoopid: "But ACTION_OPEN_Document threw an error when I tried it. Claimed that I didn't have an app that could preform that operation" -- either you set up the `Intent` incorrectly, or your device is running Android 4.3 or older. "What should I use then to grab a file from downlaods" -- there is nothing in Android that will do precisely what you ask for: picking content by starting in the "Downloads" directory. You could use [a file chooser library](https://android-arsenal.com/tag/35) for that. – CommonsWare Mar 02 '18 at 11:31