-
public class FragmentCompat
Helper for accessing features in Fragment in a backwards compatible fashion.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interface
FragmentCompat.PermissionCompatDelegate
Customizable delegate that allows delegating permission related compatibility methodsto a custom implementation.
To delegate fragment compatibility methods to a custom class, implement this interface,and call
Fragment.{@code FragmentCompat.setPermissionCompatDelegate(delegate);}
. All future callsto the compatibility methods in this class will first check whether the delegate canhandle the method call, and invoke the corresponding method if it can.public interface
FragmentCompat.OnRequestPermissionsResultCallback
This interface is the contract for receiving the results for permission requests. Fragment.
-
Constructor Summary
Constructors Constructor Description FragmentCompat()
-
Method Summary
Modifier and Type Method Description static void
setPermissionCompatDelegate(FragmentCompat.PermissionCompatDelegate delegate)
Sets the permission delegate for {@code FragmentCompat}
.static FragmentCompat.PermissionCompatDelegate
getPermissionCompatDelegate()
static void
setMenuVisibility(Fragment f, boolean visible)
Call Fragment.setMenuVisibility(boolean) if running on an appropriate version of the platform. static void
setUserVisibleHint(Fragment f, boolean deferStart)
Call setUserVisibleHint(boolean) if running on an appropriate version of the platform. static void
requestPermissions(@NonNull() Fragment fragment, @NonNull() Array<String> permissions, int requestCode)
Requests permissions to be granted to this application. static boolean
shouldShowRequestPermissionRationale(@NonNull() Fragment fragment, @NonNull() String permission)
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 inwhich the permission is requested does not clearly communicate to the userwhat would be the benefit from granting this permission. -
-
Method Detail
-
setPermissionCompatDelegate
@Deprecated() static void setPermissionCompatDelegate(FragmentCompat.PermissionCompatDelegate delegate)
Sets the permission delegate for
{@code FragmentCompat}
. Replaces the previously setdelegate.- Parameters:
delegate
- The delegate to be set.
-
getPermissionCompatDelegate
@Deprecated() static FragmentCompat.PermissionCompatDelegate getPermissionCompatDelegate()
-
setMenuVisibility
@Deprecated() static void setMenuVisibility(Fragment f, boolean visible)
Call Fragment.setMenuVisibility(boolean) if running on an appropriate version of the platform. Fragment.
-
setUserVisibleHint
@Deprecated() static void setUserVisibleHint(Fragment f, boolean deferStart)
Call setUserVisibleHint(boolean) if running on an appropriate version of the platform. Fragment.
-
requestPermissions
@Deprecated() static void requestPermissions(@NonNull() Fragment fragment, @NonNull() Array<String> permissions, int requestCode)
Requests permissions to be granted to this application. These permissionsmust 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 bythe 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 atinstall time if requested in the manifest and the signature of your app matchesthe signature of the app declaring the permissions.
If your app does not have the requested permissions the user will be presentedwith UI for accepting them. After the user has accepted or rejected therequested permissions you will receive a callback reporting whether thepermissions were granted or not. Your fragment has to implement and the results of permission requests will be delivered to its onRequestPermissionsResult.
Note that requesting a permission does not guarantee it will be granted andyour app should be able to run without having this permission.
This method may start an activity allowing the user to choose which permissionsto grant and which to reject. Hence, you should be prepared that your activitymay be paused and resumed. Further, granting some permissions may requirea restart of you application. In such a case, the system will recreate theactivity stack before delivering the result to your onRequestPermissionsResult(int, String[], int[]).
When checking whether you have a permission you should use String).
- Parameters:
fragment
- The target fragment.permissions
- The requested permissions.requestCode
- Application specific request code to match with a resultreported to onRequestPermissionsResult.
-
shouldShowRequestPermissionRationale
@Deprecated() static boolean shouldShowRequestPermissionRationale(@NonNull() Fragment fragment, @NonNull() String permission)
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 inwhich the permission is requested does not clearly communicate to the userwhat would be the benefit from granting this permission.
For example, if you write a camera app, requesting the camera permissionwould be expected by the user and no rationale for why it is requested isneeded. If however, the app needs location for tagging photos then a non-techsavvy user may wonder how location is related to taking photos. In this caseyou may choose to show UI with rationale of requesting this permission.
- Parameters:
fragment
- The target fragment.permission
- A permission your app wants to request.
-
-
-
-