Request permission for READ_EXTERNAL_STORAGE

edited December 2017 in Android Mode

I need to READ a .txt from the external storage on my android device, it works but i have to grant the permission accessing to my phone´s settings. What i want is the app I made asks me if I want to grant the permission after o when its beeing instaled. Doing some research I found this code for WRITE in the example "DataCapture" in the ketai library. It works, I get the dialog box asking me for the permission. I´ve been triying to modify this for the READ_EXTERNAL_STORAGE but i failed. I have checked the box in the sketch permissions, still does not work.

     setup {

      requestPermission("android.permission.WRITE_EXTERNAL_STORAGE", "handleRequest"); 

          }

      void handleRequest(boolean granted) {

        if (granted) {    

      db = new KetaiSQLite(this);

     //lets make our table if it is the first time we're running 

     if ( db.connect() )

      {

       // for initial app launch there are no tables so we make one

       if (!db.tableExists("data"))

        db.execute(CREATE_DB_SQL);

                       }       

                  } 

          }

There are a lot of examples for android about this but for processing-android mode only found this one. Hope someone can help me. Thanks

Answers

  • I´ve been triying to modify this for the READ_EXTERNAL_STORAGE but i failed.

    What error do you get. Notice you are requesting for reading permissions. If you want to modify, you need to request for writing privileges. What Android API are you using, OS, Android mode and Processing version?

    Try adding the persmission to write to external storage via the Processing IDE. Also check the example that ketai.org provides.

    Kf

  • edited December 2017

    Hi, thank you for answering, I´m using processing 3.3.6, and working in android mode, my phone is a xperia x, android version 7.1.1. android minsdk version 17 target sdk version 26 I have no errors, I actually can read the txt and everyting else works if I check the box for READ_EXTERNAL_STORAGE and after installation modify the setting permissions on my phone for my app to acces the storage. But i cant get to ask me if i want to grant the permission after it´s installed,this in order to install the app in other devicess without giving the permission manually. I just did this:

     requestPermission("android.permission.READ_EXTERNAL_STORAGE");
    

    It makes no erros and gets installed, but still not getting the text box, i have to grant permission the same way as before and everyting else works.

Sign In or Register to comment.