Help With Code: My App is having to restart twice when users deny the WRITE_EXTERNAL_STORAGE permission

Hello there!

Could any of you tell me what is wrong with my code?

  1. When users first start the App it shows the “Ask For Permission” - working okay…
  2. If they allow the permission and are connected, it downloads some resources - working okay…
  3. If they deny, it shows a message saying they should restart the App and allow the “Write External Storage” permission in order to download the resources.
    But when they do so it shows my “Denying Message” once again, telling them to restart the app…

When they restart the App once again it finally downloads the resources. I don’t want them to restart the app once again…

Here are the blocks I used:



3

Thank you in advance for your time. :slightly_smiling_face:

Use if else condition when download needed…

condition will be is permission granted the download file else ask for permission again

1 Like

It is because you have directly set the blocks for download even if the permission is denied, so according to your blocks even if permission is denied it will try to download and since permission is denied and still it is trying to download it asks to restart, so you néed to change your code, use the when permission granted event and under it place the blocks to download whatever you want

1 Like

I appreciate your answer but I did not understand how to exacly do it the way you are saying.

Thank you for your answer.

I was doing this way at first and it works almost fine, but if the users allow the permission when disconnected, they won’t be able to download it again when they restart the App connected. (I was not having this specific problem when my blocks were the other way around…)

Look at my rearranged blocks, please:


2

3

Use a tinydb component, when screen permission granted store a value 1 in any of the tag of tinydb, and in screen initialize add a logic if network is connected and tinydb tag value = 1, download

1 Like

Did not work… :frowning:
An error occurs because it seems that TinyDB component just accepts values TRUE or FALSE when using the AND operation:

Error

Then I tried to use the value TRUE instead, the error stops but nothing happens, not even after restarting the App…

Have a look at the blocks:

blocks (13)

That is because you have not put any condition to check the value of tinydb

1 Like

In the and block you need to put a logic = block and compare whether tinydb value is 1 then download

This is because you have set no condition for tinydb value

1 Like

I’ve tried this:


blocks (16)

and this:


blocks (13)

What am I doing wrong this time, since nothing happens after granting the permission?
I tested clicking on “Deny Permission”, it starts downloading and stays downloading forever…
I closed the App and restarted it, I chose “Allow Permission” and it shows my Deny Message but starts Downloading…

I guess I’ll have to create a button in my sidebar for users to click and download the resources… That should be an easier solution, but I woudn’t be learning nothing from it all… :pensive:

@Daniel_Miranda
You are doing just one thing wrong that is you have put your blocks that checks tinydb value is granted/true in screen initializing while you have to move all blocks from screen initializing to if permission granted except ask permission block then it will work definitely

1 Like

You mean all the other blocks (AdMob, Sidebar, Get Column…), except Tiny DB checking and Ask For Permission?

All blocks except ask permission and put it under your tinydb store value block

1 Like

Well, thank you for your answers… I tried it:

But download still does not start after allowing the permission… When I restart the App another problem comes up: My AdMob and my Get Column stop working, my images from Airtable does not load… So I noticed that I can’t put those blocks on “When permission granted” event… and if I put the download blocks in the “When permission granted” event and users allow permission with no Internet, they won’t be able to download even if they restart the app as well…

Ok now do one more thing in your screen initializing use a if then condition check if tinydb value = “GRANTED” then copy all blocks from permission granted except tinydb store Value and paste inside it and else ask for permission then it should work try it and don’t remove the blocks from if permission granted

1 Like

Almost working, as in my second case:

Blocks:


It’s this simple…

1 Like

Thank you Nathan, but:

  1. When I allow permission it does nothing at first, it does not start my Download.
    When I restart the App the Download starts normally…

  2. If I deny the permission, the custom choose dialog does not show.
    I restarted the App to see what happens: It asks for permission once again, but if I choose to allow it, the Download still does not start at first, it starts only when I restart the App for a second time.

  3. If I allow permission when not connected and return to the App when connected, it works pretty fine. Download starts normally and get completed…

Blocks:

Thank you for your time by the way…

Well, I’ve just figured it out why it is not working, these blocks must have just the permission name, not “android.permission.”:

blocks (32)

blocks (31)

The only block that must have all the “android.permission.WRITE_EXTERNAL_STORAGE” is the Ask For Permission:

blocks (33)

Well, the only thing I must correct now is that when users allow permission when disconnected an error shows:

What should I do?
I’ll try to use an “if else” condition to show a message that they must be connected next time they start the App, so download may start.

If it works I’ll mark @hammerhai answer as a solution.

Edit: Everything is working fine now. Thank you so much, @hammerhai and all the others who tried to help me somehow. I’m really pleased for your help guys. :innocent:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.