How do you create files in the downloads directory, that are visible to all users in Android?
<p>I am trying to create a file at run-time and save it in the Downloads directory. I am successfully creating the file as you can see in the screenshot below, however I can't view it.</p>

<p>In the code below I am checking for permissions, creating a file, writing to it and closing it. Afterwards I print the contents of the Downloads directory, so that I can confirm that the file was made. It was!</p>

<pre><code>        Log.d("DOM", Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) + "");

        // check for permission at runtime
        if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)
            ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);

        // create new file in downloads dir with name test.json
        File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "test.json");

        if (!file.exists())
            file.createNewFile();

        file.setReadable(true, false);

        FileOutputStream fileOutputStream = new FileOutputStream(file);
        fileOutputStream.write("test string".getBytes());
        fileOutputStream.close();

        for (int i = 0; i &lt; Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).listFiles().length; i++)
            Log.d("DOM", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).listFiles()[i].getAbsolutePath() + "");
</code></pre>

<p><a href="http://i.stack.imgur.com/RMdUa.png" rel="nofollow">A screenshot of all the files in the Downloads directory.</a></p>

<p>The problem is that if I look at the phone's Downloads application, I don't see the created files. When I look at the folder on my computer, I also can't see the files.</p>

<p>Extra details:
Btw, my manifest... This is outside the application tag.</p>

<pre><code>&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
</code></pre>

<p>The following line returns false (I was printing it to the log earlier) </p>

<pre><code>file.setReadable(true, false);
</code></pre>

<p>Also, the app only requested permission once. I think that's exactly what's supposed to happen.</p>