# FragmentCompat

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  
belongs to Maven artifact com.android.support:support-v13:28.0.0-alpha1  
Deprecated since version 27.1.0  
Summary:[Nested Classes](https://developer.android.com/reference/android/support/v13/app/FragmentCompat#nestedclasses)\|[Ctors](https://developer.android.com/reference/android/support/v13/app/FragmentCompat#pubctors)\|[Methods](https://developer.android.com/reference/android/support/v13/app/FragmentCompat#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/v13/app/FragmentCompat#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/v13/app/FragmentCompat#)  

# FragmentCompat

| 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


class
FragmentCompat
`  
`

extends Object


``


`

|---|----------------------------------------|
| java.lang.Object                          ||
| ↳ | android.support.v13.app.FragmentCompat |

<br />

*** ** * ** ***

<br />

**This class was deprecated in API level 27.1.0.**   
Use[Fragment](https://developer.android.com/reference/android/support/v4/app/Fragment)instead of the framework fragment.

Helper for accessing features in[Fragment](https://developer.android.com/reference/android/app/Fragment.html)in a backwards compatible fashion.

## Summary

|                                                                                                                                                                                                           ### Nested classes                                                                                                                                                                                                           ||
|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` interface` | [FragmentCompat.OnRequestPermissionsResultCallback](https://developer.android.com/reference/android/support/v13/app/FragmentCompat.OnRequestPermissionsResultCallback) *This interface was deprecated in API level 27.1.0. Use[Fragment](https://developer.android.com/reference/android/support/v4/app/Fragment)instead of the framework[Fragment](https://developer.android.com/reference/android/app/Fragment.html).* |
| ` interface` | [FragmentCompat.PermissionCompatDelegate](https://developer.android.com/reference/android/support/v13/app/FragmentCompat.PermissionCompatDelegate) *This interface was deprecated in API level 27.1.0. Use[Fragment](https://developer.android.com/reference/android/support/v4/app/Fragment)instead of the framework[Fragment](https://developer.android.com/reference/android/app/Fragment.html).*                     |

|                                                                                                                                           ### Public constructors                                                                                                                                            ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[FragmentCompat](https://developer.android.com/reference/android/support/v13/app/FragmentCompat#FragmentCompat())`() ` *This constructor was deprecated in API level 27.1.0. Use[Fragment](https://developer.android.com/reference/android/support/v4/app/Fragment)instead of the framework fragment.* |

|                                                                                                                                                                                                                                                                                                                ### Public methods                                                                                                                                                                                                                                                                                                                 ||
|-------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` static void`    | ` `[requestPermissions](https://developer.android.com/reference/android/support/v13/app/FragmentCompat#requestPermissions(android.app.Fragment, java.lang.String[], int))`(`[Fragment](https://developer.android.com/reference/android/app/Fragment.html)` fragment, String[] permissions, int requestCode) ` *This method was deprecated in API level 27.1.0. Use[Fragment](https://developer.android.com/reference/android/support/v4/app/Fragment)instead of the framework[Fragment](https://developer.android.com/reference/android/app/Fragment.html).*                                                                   |
| ` static void`    | ` `[setMenuVisibility](https://developer.android.com/reference/android/support/v13/app/FragmentCompat#setMenuVisibility(android.app.Fragment, boolean))`(`[Fragment](https://developer.android.com/reference/android/app/Fragment.html)` f, boolean visible) ` *This method was deprecated in API level 26.1.0. Use[Fragment](https://developer.android.com/reference/android/support/v4/app/Fragment)instead of the framework[Fragment](https://developer.android.com/reference/android/app/Fragment.html).*                                                                                                                  |
| ` static void`    | ` `[setPermissionCompatDelegate](https://developer.android.com/reference/android/support/v13/app/FragmentCompat#setPermissionCompatDelegate(android.support.v13.app.FragmentCompat.PermissionCompatDelegate))`(`[FragmentCompat.PermissionCompatDelegate](https://developer.android.com/reference/android/support/v13/app/FragmentCompat.PermissionCompatDelegate)` delegate) ` *This method was deprecated in API level 27.1.0. Use[Fragment](https://developer.android.com/reference/android/support/v4/app/Fragment)instead of the framework[Fragment](https://developer.android.com/reference/android/app/Fragment.html).* |
| ` static void`    | ` `[setUserVisibleHint](https://developer.android.com/reference/android/support/v13/app/FragmentCompat#setUserVisibleHint(android.app.Fragment, boolean))`(`[Fragment](https://developer.android.com/reference/android/app/Fragment.html)` f, boolean deferStart) ` *This method was deprecated in API level 27.1.0. Use[Fragment](https://developer.android.com/reference/android/support/v4/app/Fragment)instead of the framework[Fragment](https://developer.android.com/reference/android/app/Fragment.html).*                                                                                                             |
| ` static boolean` | ` `[shouldShowRequestPermissionRationale](https://developer.android.com/reference/android/support/v13/app/FragmentCompat#shouldShowRequestPermissionRationale(android.app.Fragment, java.lang.String))`(`[Fragment](https://developer.android.com/reference/android/app/Fragment.html)` fragment, String permission) ` *This method was deprecated in API level 27.1.0. Use[Fragment](https://developer.android.com/reference/android/support/v4/app/Fragment)instead of the framework[Fragment](https://developer.android.com/reference/android/app/Fragment.html).*                                                          |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v13/app/FragmentCompat#)From class` java.lang.Object ` |-------------------|-------------------------------| | ` Object`         | ` clone() `                   | | ` boolean`        | ` equals(Object arg0) `       | | ` void`           | ` finalize() `                | | ` final Class<?>` | ` getClass() `                | | ` int`            | ` hashCode() `                | | ` final void`     | ` notify() `                  | | ` final void`     | ` notifyAll() `               | | ` String`         | ` toString() `                | | ` final void`     | ` wait(long arg0, int arg1) ` | | ` final void`     | ` wait(long arg0) `           | | ` final void`     | ` wait() `                    | ||

## Public constructors

### FragmentCompat

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
FragmentCompat ()
```

<br />

**This constructor was deprecated in API level 27.1.0.**   
Use[Fragment](https://developer.android.com/reference/android/support/v4/app/Fragment)instead of the framework fragment.

<br />

<br />

## Public methods

### requestPermissions

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void requestPermissions (Fragment fragment, 
                String[] permissions, 
                int requestCode)
```

<br />

**This method was deprecated in API level 27.1.0.**   
Use[Fragment](https://developer.android.com/reference/android/support/v4/app/Fragment)instead of the framework[Fragment](https://developer.android.com/reference/android/app/Fragment.html).

Requests permissions to be granted to this application. These permissions must be requested in your manifest, they should not be granted to your app, and they should have protection level[#PROTECTION_DANGEROUS dangerous](https://developer.android.com/reference/android/content/pm/PermissionInfo.html), regardless whether they are declared by the platform or a third-party app.

Normal permissions[PROTECTION_NORMAL](https://developer.android.com/reference/android/content/pm/PermissionInfo.html#PROTECTION_NORMAL)are granted at install time if requested in the manifest. Signature permissions[PROTECTION_SIGNATURE](https://developer.android.com/reference/android/content/pm/PermissionInfo.html#PROTECTION_SIGNATURE)are granted at install time if requested in the manifest and the signature of your app matches the signature of the app declaring the permissions.

If your app does not have the requested permissions the user will be presented with UI for accepting them. After the user has accepted or rejected the requested permissions you will receive a callback reporting whether the permissions were granted or not. Your fragment has to implement[FragmentCompat.OnRequestPermissionsResultCallback](https://developer.android.com/reference/android/support/v13/app/FragmentCompat.OnRequestPermissionsResultCallback)and the results of permission requests will be delivered to its[onRequestPermissionsResult(int, String[], int[])](https://developer.android.com/reference/android/support/v13/app/FragmentCompat.OnRequestPermissionsResultCallback#onRequestPermissionsResult(int, java.lang.String[], int[])).

Note that requesting a permission does not guarantee it will be granted and your app should be able to run without having this permission.

This method may start an activity allowing the user to choose which permissions to grant and which to reject. Hence, you should be prepared that your activity may be paused and resumed. Further, granting some permissions may require a restart of you application. In such a case, the system will recreate the activity stack before delivering the result to your onRequestPermissionsResult( int, String\[\], int\[\]).

When checking whether you have a permission you should use[checkSelfPermission(android.content.Context, String)](https://developer.android.com/reference/android/support/v4/content/ContextCompat#checkSelfPermission(android.content.Context, java.lang.String)).

<br />

<br />

|                                                                                                                                                             Parameters                                                                                                                                                             ||
|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `fragment`    | `Fragment`: The target fragment. <br />                                                                                                                                                                                                                                                                             |
| `permissions` | `String`: The requested permissions. <br />                                                                                                                                                                                                                                                                         |
| `requestCode` | `int`: Application specific request code to match with a result reported to[onRequestPermissionsResult(int, String[], int[])](https://developer.android.com/reference/android/support/v13/app/FragmentCompat.OnRequestPermissionsResultCallback#onRequestPermissionsResult(int, java.lang.String[], int[])). <br /> |

**See also:**

- [checkSelfPermission(android.content.Context, String)](https://developer.android.com/reference/android/support/v4/content/ContextCompat#checkSelfPermission(android.content.Context, java.lang.String))
- [shouldShowRequestPermissionRationale(android.app.Fragment, String)](https://developer.android.com/reference/android/support/v13/app/FragmentCompat#shouldShowRequestPermissionRationale(android.app.Fragment, java.lang.String))  

### setMenuVisibility

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setMenuVisibility (Fragment f, 
                boolean visible)
```

<br />

**This method was deprecated in API level 26.1.0.**   
Use[Fragment](https://developer.android.com/reference/android/support/v4/app/Fragment)instead of the framework[Fragment](https://developer.android.com/reference/android/app/Fragment.html).

Call[Fragment.setMenuVisibility(boolean)](https://developer.android.com/reference/android/app/Fragment.html#setMenuVisibility(boolean))if running on an appropriate version of the platform.

<br />

|          Parameters          ||
|-----------|-------------------|
| `f`       | `Fragment` <br /> |
| `visible` | `boolean` <br />  |

### setPermissionCompatDelegate

added in[version 27.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setPermissionCompatDelegate (FragmentCompat.PermissionCompatDelegate delegate)
```

<br />

**This method was deprecated in API level 27.1.0.**   
Use[Fragment](https://developer.android.com/reference/android/support/v4/app/Fragment)instead of the framework[Fragment](https://developer.android.com/reference/android/app/Fragment.html).

Sets the permission delegate for`FragmentCompat`. Replaces the previously set delegate.

<br />

|                                                      Parameters                                                       ||
|------------|-----------------------------------------------------------------------------------------------------------|
| `delegate` | `FragmentCompat.PermissionCompatDelegate`: The delegate to be set.`null`to clear the set delegate. <br /> |

### setUserVisibleHint

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setUserVisibleHint (Fragment f, 
                boolean deferStart)
```

<br />

**This method was deprecated in API level 27.1.0.**   
Use[Fragment](https://developer.android.com/reference/android/support/v4/app/Fragment)instead of the framework[Fragment](https://developer.android.com/reference/android/app/Fragment.html).

Call[setUserVisibleHint(boolean)](https://developer.android.com/reference/android/app/Fragment.html#setUserVisibleHint(boolean))if running on an appropriate version of the platform.

<br />

|           Parameters            ||
|--------------|-------------------|
| `f`          | `Fragment` <br /> |
| `deferStart` | `boolean` <br />  |

### shouldShowRequestPermissionRationale

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean shouldShowRequestPermissionRationale (Fragment fragment, 
                String permission)
```

<br />

**This method was deprecated in API level 27.1.0.**   
Use[Fragment](https://developer.android.com/reference/android/support/v4/app/Fragment)instead of the framework[Fragment](https://developer.android.com/reference/android/app/Fragment.html).

Gets whether you should show UI with rationale for requesting a permission. You should do this only if you do not have the permission and the context in which the permission is requested does not clearly communicate to the user what would be the benefit from granting this permission.

For example, if you write a camera app, requesting the camera permission would be expected by the user and no rationale for why it is requested is needed. If however, the app needs location for tagging photos then a non-tech savvy user may wonder how location is related to taking photos. In this case you may choose to show UI with rationale of requesting this permission.

<br />

<br />

|                               Parameters                               ||
|--------------|----------------------------------------------------------|
| `fragment`   | `Fragment`: The target fragment. <br />                  |
| `permission` | `String`: A permission your app wants to request. <br /> |

|                             Returns                             ||
|-----------|------------------------------------------------------|
| `boolean` | Whether you can show permission rationale UI. <br /> |

**See also:**

- [checkSelfPermission(android.content.Context, String)](https://developer.android.com/reference/android/support/v4/content/ContextCompat#checkSelfPermission(android.content.Context, java.lang.String))
- [requestPermissions(android.app.Fragment, String[], int)](https://developer.android.com/reference/android/support/v13/app/FragmentCompat#requestPermissions(android.app.Fragment, java.lang.String[], int))  
-

  ## Interfaces

  - [FragmentCompat.OnRequestPermissionsResultCallback](https://developer.android.com/reference/android/support/v13/app/FragmentCompat.OnRequestPermissionsResultCallback)
  - [FragmentCompat.PermissionCompatDelegate](https://developer.android.com/reference/android/support/v13/app/FragmentCompat.PermissionCompatDelegate)
-

  ## Classes

  - [ActivityCompat](https://developer.android.com/reference/android/support/v13/app/ActivityCompat)
  - [FragmentCompat](https://developer.android.com/reference/android/support/v13/app/FragmentCompat)
  - [FragmentPagerAdapter](https://developer.android.com/reference/android/support/v13/app/FragmentPagerAdapter)
  - [FragmentStatePagerAdapter](https://developer.android.com/reference/android/support/v13/app/FragmentStatePagerAdapter)
  - [FragmentTabHost](https://developer.android.com/reference/android/support/v13/app/FragmentTabHost)