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

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

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

Fragment.getActivity介绍

暂无

代码示例

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

@Override
  public Context getContext() {
    return getHost().getActivity();
  }
}

代码示例来源:origin: google/santa-tracker-android

public static PlayGamesActivity getPlayGamesActivity(Fragment fragment) {
  Activity act = fragment.getActivity();
  if (act == null || !(act instanceof PlayGamesActivity)) {
    SantaLog.w(TAG, "Fragment is not in a PlayGamesActivity!");
    return null;
  }
  return (PlayGamesActivity) act;
}

代码示例来源:origin: jkwiecien/EasyImage

public static void openChooserWithGallery(Fragment fragment, @Nullable String chooserTitle, int type) {
  try {
    Intent intent = createChooserIntent(fragment.getActivity(), chooserTitle, true, type);
    fragment.startActivityForResult(intent, RequestCodes.SOURCE_CHOOSER | RequestCodes.PICK_PICTURE_FROM_GALLERY);
  } catch (IOException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: jkwiecien/EasyImage

public static void openChooserWithDocuments(Fragment fragment, @Nullable String chooserTitle, int type) {
  try {
    Intent intent = createChooserIntent(fragment.getActivity(), chooserTitle, type);
    fragment.startActivityForResult(intent, RequestCodes.SOURCE_CHOOSER | RequestCodes.PICK_PICTURE_FROM_DOCUMENTS);
  } catch (IOException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: jkwiecien/EasyImage

public static void openCameraForImage(Fragment fragment, int type) {
  Intent intent = createCameraForImageIntent(fragment.getActivity(), type);
  fragment.startActivityForResult(intent, RequestCodes.TAKE_PICTURE);
}

代码示例来源:origin: jkwiecien/EasyImage

public static void openCameraForVideo(Fragment fragment, int type) {
  Intent intent = createCameraForVideoIntent(fragment.getActivity(), type);
  fragment.startActivityForResult(intent, RequestCodes.CAPTURE_VIDEO);
}

代码示例来源:origin: florent37/ViewTooltip

public Activity getActivity() {
  if (activity != null) {
    return activity;
  } else {
    return fragment.getActivity();
  }
}

代码示例来源:origin: florent37/ViewTooltip

public Context getContext() {
  if (activity != null) {
    return activity;
  } else {
    return ((Context) fragment.getActivity());
  }
}

代码示例来源:origin: MCMrARM/revolution-irc

public SettingsListAdapter(Fragment fragment) {
  mFragment = fragment;
  mActivity = mFragment.getActivity();
}

代码示例来源:origin: nguyenhoanglam/ImagePicker

@Override
  public Intent getIntent() {
    Intent intent;
    if (!config.isCameraOnly()) {
      intent = new Intent(fragment.getActivity(), ImagePickerActivity.class);
      intent.putExtra(Config.EXTRA_CONFIG, config);
    } else {
      intent = new Intent(fragment.getActivity(), CameraActivty.class);
      intent.putExtra(Config.EXTRA_CONFIG, config);
      intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    }
    return intent;
  }
}

代码示例来源:origin: florent37/RuntimePermission

public RxPermissions(final Fragment fragment) {
  runtimePermission = RuntimePermission.askPermission(fragment.getActivity());
}

代码示例来源:origin: esafirm/android-image-picker

void captureImage(Fragment fragment, BaseConfig config, int requestCode) {
  Context context = fragment.getActivity().getApplicationContext();
  Intent intent = getCameraModule().getCameraIntent(fragment.getActivity(), config);
  if (intent == null) {
    Toast.makeText(context, context.getString(R.string.ef_error_create_image_file), Toast.LENGTH_LONG).show();
    return;
  }
  fragment.startActivityForResult(intent, requestCode);
}

代码示例来源:origin: florent37/ViewTooltip

public Window getWindow() {
    if (activity != null) {
      return activity.getWindow();
    } else {
      if (fragment instanceof DialogFragment) {
        return ((DialogFragment) fragment).getDialog().getWindow();
      }
      return fragment.getActivity().getWindow();
    }
  }
}

代码示例来源:origin: florent37/RuntimePermission

/**
 * Fill permissions to only ask If we do not call this method,
 * If not set or empty, the library will find all needed permissions to ask from manifest
 * You can call .request(permissions) after this method if you want to give permissions in a separate method
 */
public static RuntimePermission askPermission(@Nullable final Fragment fragment, String... permissions) {
  @Nullable FragmentActivity activity = null;
  if(fragment != null){
    activity = fragment.getActivity();
  }
  return askPermission(activity).request(permissions);
}

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

@Override
  public void onWorkFinish(Boolean check) {
    Intent i = new Intent(context.getActivity(), Pix.class);
    i.putExtra(OPTIONS, options);
    context.startActivityForResult(i, options.getRequestCode());
  }
});

代码示例来源:origin: esafirm/android-image-picker

@Override
  public void start() {
    fragment.startActivityForResult(getIntent(fragment.getActivity()), IpCons.RC_IMAGE_PICKER);
  }
}

代码示例来源:origin: esafirm/android-image-picker

public void start(Fragment fragment, int requestCode) {
  fragment.startActivityForResult(getIntent(fragment.getActivity()), requestCode);
}

代码示例来源: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: esafirm/android-image-picker

@Override
public void start(int requestCode) {
  fragment.startActivityForResult(getIntent(fragment.getActivity()), requestCode);
}

代码示例来源:origin: nguyenhoanglam/ImagePicker

@Override
public void start() {
  Intent intent = getIntent();
  int requestCode = config.getRequestCode() != 0 ? config.getRequestCode() : Config.RC_PICK_IMAGES;
  if (!config.isCameraOnly()) {
    fragment.startActivityForResult(intent, requestCode);
  } else {
    fragment.getActivity().overridePendingTransition(0, 0);
    fragment.startActivityForResult(intent, requestCode);
  }
}

相关文章