title: Request "Write External Storage" Permission for an Android 6 Native Process
body: <p>Recently, I wrote a native executable program:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int main() {
     FILE* f = fopen("/storage/&lt;external_sdcard_root&gt;/test.txt", "w+");
     fprintf(f, "hello");
     fclose(f);
     return 0;
  }
  </code></pre>
  
  <p>I used NDK to compile it as "test" and put it to the res/raw folder of an Android project. I read the resource as a stream at runtime and write it to application data dir; then grant it executable permission. In my MainActivity, it requests write permission at the beginning when activity init as following: <a href="https://developer.android.com/training/permissions/requesting.html" rel="nofollow noreferrer">https://developer.android.com/training/permissions/requesting.html</a>; then the activity run <code>Runtime.getRuntime().exec(cmd) /* cmd=["/path/to/datadir/test"] */</code> to start <code>test</code> process but it fails to create a file to my external storage. it works when I change the file path to my internal storage.</p>
  
  <p>Can someone point out what should I do to grant the permission to the <code>test</code> process to get able to write files to the external storage? Thanks!</p>