Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.
added in version 22.1.0
belongs to Maven artifact com.android.support:support-v13:28.0.0-alpha1
Deprecated since version 27.1.0

FragmentCompat

public class FragmentCompat
extends Object

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


This class was deprecated in API level 27.1.0.
Use Fragment instead of the framework fragment.

Helper for accessing features in Fragment in a backwards compatible fashion.

Summary

Nested classes

interface FragmentCompat.OnRequestPermissionsResultCallback

This interface was deprecated in API level 27.1.0. Use Fragment instead of the framework Fragment.  

interface FragmentCompat.PermissionCompatDelegate

This interface was deprecated in API level 27.1.0. Use Fragment instead of the framework Fragment.  

Public constructors

FragmentCompat()

This constructor was deprecated in API level 27.1.0. Use Fragment instead of the framework fragment.

Public methods

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

This method was deprecated in API level 27.1.0. Use Fragment instead of the framework Fragment.

static void setMenuVisibility(Fragment f, boolean visible)

This method was deprecated in API level 26.1.0. Use Fragment instead of the framework Fragment.

static void setPermissionCompatDelegate(FragmentCompat.PermissionCompatDelegate delegate)

This method was deprecated in API level 27.1.0. Use Fragment instead of the framework Fragment.

static void setUserVisibleHint(Fragment f, boolean deferStart)

This method was deprecated in API level 27.1.0. Use Fragment instead of the framework Fragment.

static boolean shouldShowRequestPermissionRationale(Fragment fragment, String permission)

This method was deprecated in API level 27.1.0. Use Fragment instead of the framework Fragment.

Inherited methods

From class java.lang.Object

Public constructors

FragmentCompat

added in version 22.1.0
FragmentCompat ()

This constructor was deprecated in API level 27.1.0.
Use Fragment instead of the framework fragment.

Public methods

requestPermissions

added in version 24.1.0
void requestPermissions (Fragment fragment, 
                String[] permissions, 
                int requestCode)

This method was deprecated in API level 27.1.0.
Use Fragment instead of the framework Fragment.

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, regardless whether they are declared by the platform or a third-party app.

Normal permissions PROTECTION_NORMAL are granted at install time if requested in the manifest. Signature permissions 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 and the results of permission requests will be delivered to its onRequestPermissionsResult(int, 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).

Parameters
fragment Fragment: The target fragment.

permissions String: The requested permissions.

requestCode int: Application specific request code to match with a result reported to onRequestPermissionsResult(int, String[], int[]).

setMenuVisibility

added in version 22.1.0
void setMenuVisibility (Fragment f, 
                boolean visible)

This method was deprecated in API level 26.1.0.
Use Fragment instead of the framework Fragment.

Call Fragment.setMenuVisibility(boolean) if running on an appropriate version of the platform.

Parameters
f Fragment

visible boolean

setPermissionCompatDelegate

added in version 27.1.0
void setPermissionCompatDelegate (FragmentCompat.PermissionCompatDelegate delegate)

This method was deprecated in API level 27.1.0.
Use Fragment instead of the framework Fragment.

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

Parameters
delegate FragmentCompat.PermissionCompatDelegate: The delegate to be set. null to clear the set delegate.

setUserVisibleHint

added in version 22.1.0
void setUserVisibleHint (Fragment f, 
                boolean deferStart)

This method was deprecated in API level 27.1.0.
Use Fragment instead of the framework Fragment.

Call setUserVisibleHint(boolean) if running on an appropriate version of the platform.

Parameters
f Fragment

deferStart boolean

shouldShowRequestPermissionRationale

added in version 24.1.0
boolean shouldShowRequestPermissionRationale (Fragment fragment, 
                String permission)

This method was deprecated in API level 27.1.0.
Use Fragment instead of the framework Fragment.

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.

Parameters
fragment Fragment: The target fragment.

permission String: A permission your app wants to request.

Returns
boolean Whether you can show permission rationale UI.