Development issue/problem:

My widget makes calls to protect permissions outside the activity zone. Can I request outside permission for Android M?

How can I solve this problem?

Solution 1:

No, you can’t. You can send a notification where the user can click a button and then use the action to request/manage permission (possibly with a dialogue subject).

Solution 2:

You can use the Easy Resolutions library.

Android requires that these requests come from the company. With Easy Permissions this is no longer a problem, you can ask permission anywhere, as long as you provide the context. In addition, if you request an authorization that has already been granted, the user is not asked to request it.

Enter a description of the image here

Our company manages and develops this open access library. At the same time, we are sure that it is a useful tool that we would not otherwise pass on.

Solution 3:

I think you can request an off-site authorization if you use the method.

ActivityCompat.requestPermissions (Activity, String[] permissions, int requestCode)

of the support library and pass Activity as a method parameter.

For example:

ActivityCompat.requestPermissions(targetActivity, new String[] {Manifest.permission.CAMERA}, PERMISSION_REQUEST_CODE) ;

where the target activity is the activity that the method is intended to perform :

onRequestPermissionsResult (int requestCode, String[] permissions, int[] grantResults)

This is the method that processes the outcome of the resolution request.

Solution 4:

You can only ask permission for an activity or an excerpt.

Define a point in the activity or fragment where you think the application needs authorization, and then call the requestPermission method. Sending a notification won’t work because your code needs to be processed until you get the requested permissions, then you continue your functionality with the onRequestPermissionResult() method.

Solution no. 5:

I have created an application that requires authorization control for many activities. So I created a static class that can be used globally in the application.
And it worked.
It worked for me.

I created a method to check the authorization request in another class like this.

The CheckForPermissions public class implements ActivityCompat.OnRequestPermissionsResultCallback {
private static final int MY_PERMISSIONS_REQUEST_READ_LOCATION = 1 ;

public static void checkForLocationPermissions(Activity context){if(ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION))| ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED| ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_WARRANTED){ActivityCompat.requestPermissions(context,new String[]{Manifest.permission.ACCESS_FINE_LOCATION},MY_PERMISSIONS_REQUEST_READ_LOCATION;)


In my work, I called method.

CheckForPermissions.checkForLocationPermissions(this) ;

Solution no. 6:

I have come up with a solution that seems to work well. The trick is to create a transparent activity that only requires authorization and ends right after. There has to be a context, of course, but not necessarily an event.
An activity can return a result (granted or denied) by translation (since startActivtyForResult is not possible outside the activity).

You can use this activity:

import android.content.intent
import android.os.bundle

Internal constant KEY_PERMISSIONS_KEY = permissions
Internal constant GRANTED_PERMISSIONS_ACTION = GetPermissionsActivity.permissions_grantated
Internal constant DENIED_PERMISSIONS_ACTION = GetPermissionsActivity.permissions_denied

GetPermissionsActivity Course : AppCompatActivity() {.

permission privateValueRequestCode = 0

lift fun onCreate(savedInstanceState: Bundle?) {

Override fun onRequestPermissionsResult(
requestCode: Int,
permissions : Array,
grantResults : IntArray
) {
if (requestCode == permissionRequestCode) {
if ((grantResults.isNotEmpty() && grantResults[0] == PackageManager.GUARANTEE_PERMISSION)) {
} else {
} else {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)

And this style for the activity

In the manifesto:

And then use it like this (context required).

Some class: BroadcastReceiver() {

private fun someFunction(context: Context) {
val intentFilter = IntentFilter()
context.registerReceiver(this, intentFilter)
val intent = Intent(context,
intent.putExtra(PERMISSIONS_KEY, arrayOf())

Override fun onReceive(context:Context, intent:intent) {
when {
intent.action == ACTION_PERMISSIONS_DENIED -> {
else -> super.onReceive(context, intent)

privatepleasureonPermissionsGranted() {
// …

privatePermissionDenied() {
// …

Good luck!

kotlin request permissionhow to ask permission (runtime) again if the user deny for the first timeandroid request permissionandroid runtime permissions example githubandroid request permission in serviceonrequestpermissionsresultpermission change listener androidmultiple runtime permissions android example

You May Also Like

How To View The Correct Colour Profile Using Colour Management In Windows 10

Each object has its own colour, and if one of them has…

Fixing Error Fatal: Origin does not appear to be a Git Repository

RECOMMENDED: Click here to fix Windows errors and optimize system performance. By…

Asus ZenBook UX330UA Laptop Review

Asus ZenBook UX330UA Laptop UNITED STATES 1+ Monetary valuation 8.6/10 Technical data…

Best Smartwatch Under $150 for 2021 [Our Reviews and Comparisons]

We have long waited for the watch on our wrist not only…