androidx.fragment.app.Fragment.requestPermissions()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(2.9k)|赞(0)|评价(0)|浏览(186)

本文整理了Java中androidx.fragment.app.Fragment.requestPermissions()方法的一些代码示例,展示了Fragment.requestPermissions()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Fragment.requestPermissions()方法的具体详情如下:
包路径:androidx.fragment.app.Fragment
类名称:Fragment
方法名:requestPermissions

Fragment.requestPermissions介绍

暂无

代码示例

代码示例来源:origin: googlesamples/easypermissions

@Override
public void directRequestPermissions(int requestCode, @NonNull String... perms) {
  getHost().requestPermissions(perms, requestCode);
}

代码示例来源:origin: googlesamples/easypermissions

@Test
public void shouldRequestPermissions_whenPositiveButtonFromFragment() {
  when(dialogFragmentCompat.getParentFragment()).thenReturn(fragment);
  RationaleDialogClickListener listener = new RationaleDialogClickListener(dialogFragmentCompat, dialogConfig,
      permissionCallbacks, rationaleCallbacks);
  listener.onClick(dialogInterface, Dialog.BUTTON_POSITIVE);
  verify(fragment, times(1)).requestPermissions(PERMS, REQUEST_CODE);
}

代码示例来源:origin: cemrich/zapp

public static boolean writeExternalStorageAllowed(Fragment fragment) {
  if (ActivityCompat.checkSelfPermission(fragment.getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
    fragment.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE_WRITE_EXTERNAL_STORAGE);
    return false;
  } else {
    return true;
  }
}

代码示例来源:origin: akshay2211/PixImagePicker

public static void checkForCamaraWritePermissions(final Fragment fragment, WorkFinish workFinish) {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
    workFinish.onWorkFinish(true);
  } else {
    List<String> permissionsNeeded = new ArrayList<String>();
    final List<String> permissionsList = new ArrayList<String>();
    if (!addPermission(permissionsList, Manifest.permission.CAMERA, fragment.getActivity()))
      permissionsNeeded.add("CAMERA");
    if (!addPermission(permissionsList, Manifest.permission.WRITE_EXTERNAL_STORAGE, fragment.getActivity()))
      permissionsNeeded.add("WRITE_EXTERNAL_STORAGE");
    if (permissionsList.size() > 0) {
      fragment.requestPermissions(permissionsList.toArray(new String[permissionsList.size()]),
          REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS);
    } else {
      workFinish.onWorkFinish(true);
    }
  }
}

代码示例来源:origin: raphaelbussa/PermissionUtils

@SuppressWarnings("deprecation")
private void ask(android.app.Activity activity, androidx.fragment.app.Fragment fragmentX, android.app.Fragment fragment) {
  initArray();
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    String[] permissionToAsk = permissionToAsk(activity, fragmentX, fragment);
    if (permissionToAsk.length == 0) {
      showResult();
    } else {
      if (activity != null) {
        ActivityCompat.requestPermissions(activity, permissionToAsk, key);
      } else if (fragment != null) {
        FragmentCompat.requestPermissions(fragment, permissionToAsk, key);
      } else if (fragmentX != null) {
        fragmentX.requestPermissions(permissionToAsk, key);
      }
    }
  } else {
    permissionsGranted.addAll(permissions);
    showResult();
  }
}

相关文章