# RequiresPermission

Summary:[Nested Classes](https://developer.android.com/reference/android/support/annotation/RequiresPermission#nestedclasses)\|[Methods](https://developer.android.com/reference/android/support/annotation/RequiresPermission#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/annotation/RequiresPermission#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/annotation/RequiresPermission#)  

# RequiresPermission

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public


abstract
@interface
RequiresPermission
`  
`


implements

Annotation


`

|-----------------------------------------------|
| android.support.annotation.RequiresPermission |

<br />

*** ** * ** ***

Denotes that the annotated element requires (or may require) one or more permissions.

Example of requiring a single permission:  


       @RequiresPermission(Manifest.permission.SET_WALLPAPER)
       public abstract void setWallpaper(Bitmap bitmap) throws IOException;

       @RequiresPermission(ACCESS_COARSE_LOCATION)
       public abstract Location getLastKnownLocation(String provider);
     
Example of requiring at least one permission from a set:  


       @RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
       public abstract Location getLastKnownLocation(String provider);
     
Example of requiring multiple permissions:  


       @RequiresPermission(allOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
       public abstract Location getLastKnownLocation(String provider);
     
Example of requiring separate read and write permissions for a content provider:  


       @RequiresPermission.Read(@RequiresPermission(READ_HISTORY_BOOKMARKS))
       @RequiresPermission.Write(@RequiresPermission(WRITE_HISTORY_BOOKMARKS))
       public static final Uri BOOKMARKS_URI = Uri.parse("content://browser/bookmarks");
     
When specified on a parameter, the annotation indicates that the method requires a permission which depends on the value of the parameter. For example, consider`android.app.Activity.startActivity(android.content.Intent)`:  

    public void startActivity(@RequiresPermission Intent intent) { ... }
     
Notice how there are no actual permission names listed in the annotation. The actual permissions required will depend on the particular intent passed in. For example, the code may look like this:  

    Intent intent = new Intent(Intent.ACTION_CALL);
       startActivity(intent);
     
and the actual permission requirement for this particular intent is described on the Intent name itself:  


       @RequiresPermission(Manifest.permission.CALL_PHONE)
       public static final String ACTION_CALL = "android.intent.action.CALL";
     
<br />

## Summary

|                                                                                              ### Nested classes                                                                                              ||
|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` @interface` | [RequiresPermission.Read](https://developer.android.com/reference/android/support/annotation/RequiresPermission.Read) Specifies that the given permission is required for read operations.    |
| ` @interface` | [RequiresPermission.Write](https://developer.android.com/reference/android/support/annotation/RequiresPermission.Write) Specifies that the given permission is required for write operations. |

|                                                                                                                                                                                                                 ### Public methods                                                                                                                                                                                                                 ||
|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` String[]` | ` `[allOf](https://developer.android.com/reference/android/support/annotation/RequiresPermission#allOf())`() ` Specifies a list of permission names that are all required.                                                                                                                                                                                                                                                            |
| ` String[]` | ` `[anyOf](https://developer.android.com/reference/android/support/annotation/RequiresPermission#anyOf())`() ` Specifies a list of permission names where at least one is required If specified,[allOf()](https://developer.android.com/reference/android/support/annotation/RequiresPermission#allOf())and[value()](https://developer.android.com/reference/android/support/annotation/RequiresPermission#value())must both be null. |
| ` boolean`  | ` `[conditional](https://developer.android.com/reference/android/support/annotation/RequiresPermission#conditional())`() ` If true, the permission may not be required in all cases (e.g.                                                                                                                                                                                                                                             |
| ` String`   | ` `[value](https://developer.android.com/reference/android/support/annotation/RequiresPermission#value())`() ` The name of the permission that is required, if precisely one permission is required.                                                                                                                                                                                                                                  |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/annotation/RequiresPermission#)From interface` java.lang.annotation.Annotation ` |-----------------------------------------|-------------------------| | ` abstract Class<? extends Annotation>` | ` annotationType() `    | | ` abstract boolean`                     | ` equals(Object arg0) ` | | ` abstract int`                         | ` hashCode() `          | | ` abstract String`                      | ` toString() `          | ||

## Public methods

### allOf

```
String[] allOf ()
```

Specifies a list of permission names that are all required.

If specified,[anyOf()](https://developer.android.com/reference/android/support/annotation/RequiresPermission#anyOf())and[value()](https://developer.android.com/reference/android/support/annotation/RequiresPermission#value())must both be null.

<br />

|      Returns       ||
|------------|--------|
| `String[]` | <br /> |

### anyOf

```
String[] anyOf ()
```

Specifies a list of permission names where at least one is required

If specified,[allOf()](https://developer.android.com/reference/android/support/annotation/RequiresPermission#allOf())and[value()](https://developer.android.com/reference/android/support/annotation/RequiresPermission#value())must both be null.

<br />

|      Returns       ||
|------------|--------|
| `String[]` | <br /> |

### conditional

```
boolean conditional ()
```

If true, the permission may not be required in all cases (e.g. it may only be enforced on certain platforms, or for certain call parameters, etc.

<br />

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

### value

```
String value ()
```

The name of the permission that is required, if precisely one permission is required. If more than one permission is required, specify either[allOf()](https://developer.android.com/reference/android/support/annotation/RequiresPermission#allOf())or[anyOf()](https://developer.android.com/reference/android/support/annotation/RequiresPermission#anyOf())instead.

If specified,[anyOf()](https://developer.android.com/reference/android/support/annotation/RequiresPermission#anyOf())and[allOf()](https://developer.android.com/reference/android/support/annotation/RequiresPermission#allOf())must both be null.

<br />

|     Returns      ||
|----------|--------|
| `String` | <br /> |

-

  ## Annotations

  - [AnimatorRes](https://developer.android.com/reference/android/support/annotation/AnimatorRes)
  - [AnimRes](https://developer.android.com/reference/android/support/annotation/AnimRes)
  - [AnyRes](https://developer.android.com/reference/android/support/annotation/AnyRes)
  - [AnyThread](https://developer.android.com/reference/android/support/annotation/AnyThread)
  - [ArrayRes](https://developer.android.com/reference/android/support/annotation/ArrayRes)
  - [AttrRes](https://developer.android.com/reference/android/support/annotation/AttrRes)
  - [BinderThread](https://developer.android.com/reference/android/support/annotation/BinderThread)
  - [BoolRes](https://developer.android.com/reference/android/support/annotation/BoolRes)
  - [CallSuper](https://developer.android.com/reference/android/support/annotation/CallSuper)
  - [CheckResult](https://developer.android.com/reference/android/support/annotation/CheckResult)
  - [ColorInt](https://developer.android.com/reference/android/support/annotation/ColorInt)
  - [ColorLong](https://developer.android.com/reference/android/support/annotation/ColorLong)
  - [ColorRes](https://developer.android.com/reference/android/support/annotation/ColorRes)
  - [DimenRes](https://developer.android.com/reference/android/support/annotation/DimenRes)
  - [Dimension](https://developer.android.com/reference/android/support/annotation/Dimension)
  - [DrawableRes](https://developer.android.com/reference/android/support/annotation/DrawableRes)
  - [FloatRange](https://developer.android.com/reference/android/support/annotation/FloatRange)
  - [FontRes](https://developer.android.com/reference/android/support/annotation/FontRes)
  - [FractionRes](https://developer.android.com/reference/android/support/annotation/FractionRes)
  - [GuardedBy](https://developer.android.com/reference/android/support/annotation/GuardedBy)
  - [HalfFloat](https://developer.android.com/reference/android/support/annotation/HalfFloat)
  - [IdRes](https://developer.android.com/reference/android/support/annotation/IdRes)
  - [IntDef](https://developer.android.com/reference/android/support/annotation/IntDef)
  - [IntegerRes](https://developer.android.com/reference/android/support/annotation/IntegerRes)
  - [InterpolatorRes](https://developer.android.com/reference/android/support/annotation/InterpolatorRes)
  - [IntRange](https://developer.android.com/reference/android/support/annotation/IntRange)
  - [Keep](https://developer.android.com/reference/android/support/annotation/Keep)
  - [LayoutRes](https://developer.android.com/reference/android/support/annotation/LayoutRes)
  - [LongDef](https://developer.android.com/reference/android/support/annotation/LongDef)
  - [MainThread](https://developer.android.com/reference/android/support/annotation/MainThread)
  - [MenuRes](https://developer.android.com/reference/android/support/annotation/MenuRes)
  - [NavigationRes](https://developer.android.com/reference/android/support/annotation/NavigationRes)
  - [NonNull](https://developer.android.com/reference/android/support/annotation/NonNull)
  - [Nullable](https://developer.android.com/reference/android/support/annotation/Nullable)
  - [PluralsRes](https://developer.android.com/reference/android/support/annotation/PluralsRes)
  - [Px](https://developer.android.com/reference/android/support/annotation/Px)
  - [RawRes](https://developer.android.com/reference/android/support/annotation/RawRes)
  - [RequiresApi](https://developer.android.com/reference/android/support/annotation/RequiresApi)
  - [RequiresPermission](https://developer.android.com/reference/android/support/annotation/RequiresPermission)
  - [RequiresPermission.Read](https://developer.android.com/reference/android/support/annotation/RequiresPermission.Read)
  - [RequiresPermission.Write](https://developer.android.com/reference/android/support/annotation/RequiresPermission.Write)
  - [RestrictTo](https://developer.android.com/reference/android/support/annotation/RestrictTo)
  - [Size](https://developer.android.com/reference/android/support/annotation/Size)
  - [StringDef](https://developer.android.com/reference/android/support/annotation/StringDef)
  - [StringRes](https://developer.android.com/reference/android/support/annotation/StringRes)
  - [StyleableRes](https://developer.android.com/reference/android/support/annotation/StyleableRes)
  - [StyleRes](https://developer.android.com/reference/android/support/annotation/StyleRes)
  - [TransitionRes](https://developer.android.com/reference/android/support/annotation/TransitionRes)
  - [UiThread](https://developer.android.com/reference/android/support/annotation/UiThread)
  - [VisibleForTesting](https://developer.android.com/reference/android/support/annotation/VisibleForTesting)
  - [WorkerThread](https://developer.android.com/reference/android/support/annotation/WorkerThread)
  - [XmlRes](https://developer.android.com/reference/android/support/annotation/XmlRes)
-

  ## Enums

  - [RestrictTo.Scope](https://developer.android.com/reference/android/support/annotation/RestrictTo.Scope)