O
O
Oleg2021-08-28 12:54:39
Android
Oleg, 2021-08-28 12:54:39

Problem with custom permishin. How to re-request permission?

Service and client. Two applications.

<service
            android:name=".NameService"
           .....
            android:permission="my.package.custom.PERMISSION"
            android:exported="true">
           .....
</service>

To connect to the service, I require that the client application manifest contains the line
<uses-permission android:name=""my.package.custom.PERMISSION" />


It works. If the client is installed after the service application.

Service upgrade results in
Caused by: java.lang.SecurityException: 
  at android.app.ContextImpl.bindServiceCommon (ContextImpl.java:1918)
  at android.app.ContextImpl.bindService (ContextImpl.java:1829)


framed the service binding in catching the exception.

Now the task is how to re-request your permission programmatically?

https://developer.android.com/training/permissions...
closest in meaning to the documentation. But I don't see how to make a request. It is mentioned how to check.

upd
https://stackoverflow.com/questions/22934416/andro...
comments to the answer confuse even more

upd2

this is not in the documentation because you need to work as usual
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

                    if (checkSelfPermission("my.package.custom.PERMISSION")
                            != PackageManager.PERMISSION_GRANTED) {

                        mRequestPermission.launch("my.package.custom.PERMISSION");

                        return;
                    }

            }


If you make the permission declaration as dangerous in the service application manifest, then we will see a dialog similar to a request to read files. In this case, it starts working.
Returns notGranted when set to normal .

The version with the signature of the developer does not suit me. The service is intended to be public.

Question . More convenient without unnecessary confirmations is there a way?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question