-3

I have an app HTMLSpyII that I developed a few years ago when I was an absolute beginner at Android programming. Anyway here it is a few years later, I have been away from programming through this time, it has been running on my Samsung S4 mini KitKat 4.4.2, but it will not run on my Samsung Tab E Nougat 7.1.1. I am certain that I am missing something simple.

The program is trying to create a directory /HTMLSpyII/Jsoup in the Downloads directory of the device. It outputs this two-line runTimeAlert from the last line of the following code snippet...
Unable to create path
/storage/emulated/0/Download/HTMLSpyII/Jsoup

Here is the code snippet, which is part of onCreate...

    private File root;
    private String urlString, tokenString;
    private EditText url, token;
    ...
 root = Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_DOWNLOADS + "/HTMLSpyII/Jsoup");
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            urlString = extras.getString("urlKey");
            url.setText(urlString);
            tokenString = extras.getString("tokenKey");
            token.setText(tokenString);
            if (getIntent().hasExtra("redirectsKey"))
                followRedirects = extras.getBoolean("redirectsKey");
            else
                followRedirects = true;
            if (getIntent().hasExtra("rootKey"))
                root = new File (extras.getString("rootKey"));
        }
        if (!root.exists()) root.mkdirs();
        if (!root.isDirectory())
            runTimeAlert("Unable to create path\n" + root.toString())

Hope you can help :)

Mick
  • 663
  • 1
  • 9
  • 18

1 Answers1

0

I finally found that the answer to my question involves checking permissions at run time. This was new to me. The answer is provided by Tarun, in this StackOverflow post...
Android marshmallow request permission?
Tarun's answer is quite far down so easiest to find it by searching the post for the name Tarun; and found here also... http://revisitingandroid.blogspot.com/2017/01/how-to-check-and-request-for-run-time.html

Mick
  • 663
  • 1
  • 9
  • 18