RequiresPermission
public
abstract
@interface
RequiresPermission
implements
Annotation
android.support.annotation.RequiresPermission |
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);
@RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
public abstract Location getLastKnownLocation(String provider);
@RequiresPermission(allOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
public abstract Location getLastKnownLocation(String 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) { ... }
Intent intent = new Intent(Intent.ACTION_CALL);
startActivity(intent);
@RequiresPermission(Manifest.permission.CALL_PHONE)
public static final String ACTION_CALL = "android.intent.action.CALL";
Summary
Nested classes | |
---|---|
@interface |
RequiresPermission.Read
Specifies that the given permission is required for read operations. |
@interface |
RequiresPermission.Write
Specifies that the given permission is required for write operations. |
Public methods | |
---|---|
String[]
|
allOf()
Specifies a list of permission names that are all required. |
String[]
|
anyOf()
Specifies a list of permission names where at least one is required |
boolean
|
conditional()
If true, the permission may not be required in all cases (e.g. |
String
|
value()
The name of the permission that is required, if precisely one permission is required. |
Inherited methods | |
---|---|
From
interface
java.lang.annotation.Annotation
|
Public methods
allOf
String[] allOf ()
Specifies a list of permission names that are all required.
If specified, anyOf()
and value()
must both be null.
Returns | |
---|---|
String[] |
anyOf
String[] anyOf ()
Specifies a list of permission names where at least one is required
If specified, allOf()
and value()
must both be null.
Returns | |
---|---|
String[] |
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.
Returns | |
---|---|
boolean |
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()
or anyOf()
instead.
If specified, anyOf()
and allOf()
must both be null.
Returns | |
---|---|
String |
Annotations
- AnimatorRes
- AnimRes
- AnyRes
- AnyThread
- ArrayRes
- AttrRes
- BinderThread
- BoolRes
- CallSuper
- CheckResult
- ColorInt
- ColorLong
- ColorRes
- DimenRes
- Dimension
- DrawableRes
- FloatRange
- FontRes
- FractionRes
- GuardedBy
- HalfFloat
- IdRes
- IntDef
- IntegerRes
- InterpolatorRes
- IntRange
- Keep
- LayoutRes
- LongDef
- MainThread
- MenuRes
- NavigationRes
- NonNull
- Nullable
- PluralsRes
- Px
- RawRes
- RequiresApi
- RequiresPermission
- RequiresPermission.Read
- RequiresPermission.Write
- RestrictTo
- Size
- StringDef
- StringRes
- StyleableRes
- StyleRes
- TransitionRes
- UiThread
- VisibleForTesting
- WorkerThread
- XmlRes
Enums
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-04-11 UTC.