D
D
Dmtm2019-08-23 06:56:12
Android
Dmtm, 2019-08-23 06:56:12

How to request permission from a background task (service, worker, thread...)?

Google teaches to request permissions only at the moment before use,
imagine a service that takes a long time to count something and sometimes wants to write to a card,
pre-checking permissions is not an option, the service is background, the user can minimize the application and revoke the permission.
Interested in the logic of the solution.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Varakosov, 2019-08-23
@thelongrunsmoke

int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.SOME_PERMISSION);

Check the permission, check the presence of a memory card, if something is wrong - display a notification that will send the user to the application to solve these problems.
Data can be saved to a file, to a sandbox, so that it is not unloaded from memory.

O
Oleg, 2019-08-23
@402d

I did so.
at the time of the first launch, I
display Press the button - a request for rights will be made.
On the settings page. If the permission is not given, Notification and button give.
If the service ran into an error due to permission. Work stop.
Output NotGrantPermActivity

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question