Class BasePermissionHelper

    • Nested Class Summary

      • Nested classes/interfaces inherited from class androidx.fragment.app.Fragment

        androidx.fragment.app.Fragment.InstantiationException, androidx.fragment.app.Fragment.SavedState
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected android.app.Activity mActivity  
      protected android.content.Context mContext  
      protected java.lang.String[] mPermissions  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void checkPermission()
      Checks the permissions that was set on the getPermissions() method
      abstract java.lang.String getPermissionRationale()
      Set the description on why the permission is needed
      abstract java.lang.String[] getPermissions()
      Set the name of the permissions you need to check
      boolean isGranted()
      Check permission grant status
      void onAttach​(android.content.Context context)  
      void onCancel​(java.lang.String tag)
      Method called on rational dialog negative button click
      void onConfirm​(java.lang.String tag)
      Method called on rationale dialog positive button click
      void onCreate​(android.os.Bundle savedInstanceState)  
      void onDetach()  
      protected abstract void onPermissionDenied()
      Method called after permission was denied
      protected abstract void onPermissionGranted()
      Method called after permission was granted
      void onRequestPermissionsResult​(int requestCode, java.lang.String[] permissions, int[] grantResults)  
      void requestPermissions()
      Request permissions that was set on the getPermissions() method
      boolean shouldShowPermissionRationale()
      Check if appropriate to show explanation on why the permission is being requested
      void showPermissionRationale​(int title, int message, int positive, int negative)
      Shows a dialog explaining why the needs the permission
      void showPermissionRationale​(int title, int message, int positive, int negative, ConfirmDialogFragment.ConfirmDialogListener listener)
      Shows a dialog explaining why the needs the permission
      • Methods inherited from class androidx.fragment.app.Fragment

        dump, equals, getActivity, getAllowEnterTransitionOverlap, getAllowReturnTransitionOverlap, getArguments, getChildFragmentManager, getContext, getEnterTransition, getExitTransition, getFragmentManager, getHost, getId, getLayoutInflater, getLayoutInflater, getLifecycle, getLoaderManager, getParentFragment, getReenterTransition, getResources, getRetainInstance, getReturnTransition, getSavedStateRegistry, getSharedElementEnterTransition, getSharedElementReturnTransition, getString, getString, getTag, getTargetFragment, getTargetRequestCode, getText, getUserVisibleHint, getView, getViewLifecycleOwner, getViewLifecycleOwnerLiveData, getViewModelStore, hashCode, hasOptionsMenu, instantiate, instantiate, isAdded, isDetached, isHidden, isInLayout, isMenuVisible, isRemoving, isResumed, isStateSaved, isVisible, onActivityCreated, onActivityResult, onAttach, onAttachFragment, onConfigurationChanged, onContextItemSelected, onCreateAnimation, onCreateAnimator, onCreateContextMenu, onCreateOptionsMenu, onCreateView, onDestroy, onDestroyOptionsMenu, onDestroyView, onGetLayoutInflater, onHiddenChanged, onInflate, onInflate, onLowMemory, onMultiWindowModeChanged, onOptionsItemSelected, onOptionsMenuClosed, onPause, onPictureInPictureModeChanged, onPrepareOptionsMenu, onPrimaryNavigationFragmentChanged, onResume, onSaveInstanceState, onStart, onStop, onViewCreated, onViewStateRestored, postponeEnterTransition, postponeEnterTransition, registerForContextMenu, requestPermissions, requireActivity, requireArguments, requireContext, requireFragmentManager, requireHost, requireParentFragment, requireView, setAllowEnterTransitionOverlap, setAllowReturnTransitionOverlap, setArguments, setEnterSharedElementCallback, setEnterTransition, setExitSharedElementCallback, setExitTransition, setHasOptionsMenu, setInitialSavedState, setMenuVisibility, setReenterTransition, setRetainInstance, setReturnTransition, setSharedElementEnterTransition, setSharedElementReturnTransition, setTargetFragment, setUserVisibleHint, shouldShowRequestPermissionRationale, startActivity, startActivity, startActivityForResult, startActivityForResult, startIntentSenderForResult, startPostponedEnterTransition, toString, unregisterForContextMenu
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • mContext

        protected android.content.Context mContext
      • mActivity

        protected android.app.Activity mActivity
      • mPermissions

        protected java.lang.String[] mPermissions
    • Constructor Detail

      • BasePermissionHelper

        public BasePermissionHelper()
    • Method Detail

      • onAttach

        public void onAttach​(android.content.Context context)
        Overrides:
        onAttach in class androidx.fragment.app.Fragment
      • onCreate

        public void onCreate​(android.os.Bundle savedInstanceState)
        Overrides:
        onCreate in class androidx.fragment.app.Fragment
      • onDetach

        public void onDetach()
        Overrides:
        onDetach in class androidx.fragment.app.Fragment
      • isGranted

        public boolean isGranted()
        Check permission grant status
        Returns:
        true if permission is already granted
      • requestPermissions

        public void requestPermissions()
        Request permissions that was set on the getPermissions() method
      • shouldShowPermissionRationale

        public boolean shouldShowPermissionRationale()
        Check if appropriate to show explanation on why the permission is being requested
        Returns:
        true if the app has requested this permission previously and the user denied the request.
      • showPermissionRationale

        public void showPermissionRationale​(@StringRes
                                            int title,
                                            @StringRes
                                            int message,
                                            @StringRes
                                            int positive,
                                            @StringRes
                                            int negative)
        Shows a dialog explaining why the needs the permission
        Parameters:
        title - dialog title
        message - explaining why the app needs the permission
        positive - first action
        negative - second action
      • showPermissionRationale

        public void showPermissionRationale​(@StringRes
                                            int title,
                                            @StringRes
                                            int message,
                                            @StringRes
                                            int positive,
                                            @StringRes
                                            int negative,
                                            ConfirmDialogFragment.ConfirmDialogListener listener)
        Shows a dialog explaining why the needs the permission
        Parameters:
        title - dialog title
        message - explaining why the app needs the permission
        positive - first action
        negative - second action
        listener - callback for dialog
      • checkPermission

        public void checkPermission()
        Checks the permissions that was set on the getPermissions() method
      • onRequestPermissionsResult

        public void onRequestPermissionsResult​(int requestCode,
                                               @NonNull
                                               java.lang.String[] permissions,
                                               @NonNull
                                               int[] grantResults)
        Overrides:
        onRequestPermissionsResult in class androidx.fragment.app.Fragment
      • getPermissions

        public abstract java.lang.String[] getPermissions()
        Set the name of the permissions you need to check
        Returns:
        permissions to check
      • getPermissionRationale

        public abstract java.lang.String getPermissionRationale()
        Set the description on why the permission is needed
        Returns:
        description
      • onPermissionGranted

        protected abstract void onPermissionGranted()
        Method called after permission was granted
      • onPermissionDenied

        protected abstract void onPermissionDenied()
        Method called after permission was denied