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

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

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

Fragment.getContext介绍

暂无

代码示例

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

private void setActivityOrFragment(Object activityOrFragment) {
  mActivityOrFragment = activityOrFragment;
  if (activityOrFragment instanceof Activity) {
    mContext = (Activity) activityOrFragment;
  } else if (activityOrFragment instanceof Fragment) {
    mContext = ((Fragment) activityOrFragment).getContext();
  } else {
    throw new IllegalStateException("Unknown object: " + activityOrFragment);
  }
}

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

/**
 * Create a new Builder for an {@link AppSettingsDialog}.
 *
 * @param fragment the {@link Fragment} in which to display the dialog.
 */
public Builder(@NonNull Fragment fragment) {
  mActivityOrFragment = fragment;
  mContext = fragment.getContext();
}

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

@Override
  public Context getContext() {
    if (getHost() instanceof Activity) {
      return (Context) getHost();
    } else if (getHost() instanceof Fragment) {
      return ((Fragment) getHost()).getContext();
    } else {
      throw new IllegalStateException("Unknown host: " + getHost());
    }
  }
}

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

public static void openDocuments(Fragment fragment, int type) {
  Intent intent = createDocumentsIntent(fragment.getContext(), type);
  fragment.startActivityForResult(intent, RequestCodes.PICK_PICTURE_FROM_DOCUMENTS);
}

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

/**
 * Opens default galery or a available galleries picker if there is no default
 *
 * @param type Custom type of your choice, which will be returned with the images
 */
public static void openGallery(Fragment fragment, int type) {
  Intent intent = createGalleryIntent(fragment.getContext(), type);
  fragment.startActivityForResult(intent, RequestCodes.PICK_PICTURE_FROM_GALLERY);
}

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

public Builder(Fragment fragment) {
  super(fragment.getContext());
}

代码示例来源:origin: jruesga/rview

public static void editChange( Fragment fragment, int legacyChangeId,
    String changeId, String revisionId, int requestCode) {
  Intent intent = new Intent(fragment.getContext(), EditorActivity.class);
  intent.putExtra(Constants.EXTRA_CHANGE_ID, changeId);
  intent.putExtra(Constants.EXTRA_LEGACY_CHANGE_ID, legacyChangeId);
  intent.putExtra(Constants.EXTRA_REVISION_ID, revisionId);
  intent.putExtra(Constants.EXTRA_HAS_PARENT, true);
  fragment.startActivityForResult(intent, requestCode);
}

代码示例来源:origin: jruesga/rview

public static void viewChangeFile(Fragment fragment, int legacyChangeId,
    String changeId, String revisionId, String fileName, File content) {
  Intent intent = new Intent(fragment.getContext(), EditorActivity.class);
  intent.putExtra(Constants.EXTRA_CHANGE_ID, changeId);
  intent.putExtra(Constants.EXTRA_LEGACY_CHANGE_ID, legacyChangeId);
  intent.putExtra(Constants.EXTRA_REVISION_ID, revisionId);
  intent.putExtra(Constants.EXTRA_FILE, fileName);
  intent.putExtra(Constants.EXTRA_CONTENT_FILE, content.getAbsolutePath());
  intent.putExtra(Constants.EXTRA_READ_ONLY, true);
  intent.putExtra(Constants.EXTRA_HAS_PARENT, true);
  fragment.startActivity(intent);
}

代码示例来源:origin: mars885/persistentsearchview

@SuppressWarnings("NewApi")
private Context getContext() {
  if(mActivity != null) {
    return mActivity;
  } else if(mSupportActivity != null) {
    return mSupportActivity;
  } else if(mFragment != null) {
    return mFragment.getContext();
  } else if(mSupportFragment != null) {
    return mSupportFragment.getContext();
  } else {
    throw new IllegalStateException("Could not get context in VoiceRecognitionDelegate.");
  }
}

代码示例来源: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: pranavpandey/dynamic-support

/**
 * Request the supplied permissions if not granted.
 *
 * @param fragment The fragment to start the activity.
 * @param permissions The array of permissions to be requested.
 * @param history {@code false} to exclude the system settings activity from the recents.
 * @param actionIntent The intent which should be called after all the permissions has been
 *                     granted.
 * @param action The intent action, either start an activity or a service.
 * @param requestCode The request code for the result.
 */
public void requestPermissions(@NonNull Fragment fragment,
    @NonNull String[] permissions, boolean history, @Nullable Intent actionIntent,
    @DynamicAction int action, int requestCode) {
  Intent intent = new Intent(fragment.getContext(), mPermissionActivity);
  intent.setAction(DynamicIntent.ACTION_PERMISSIONS);
  intent.putExtra(DynamicIntent.EXTRA_PERMISSIONS, permissions);
  if (!history) {
    intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
  }
  if (actionIntent != null) {
    intent.putExtra(DynamicIntent.EXTRA_PERMISSIONS_INTENT, actionIntent);
    intent.putExtra(DynamicIntent.EXTRA_PERMISSIONS_ACTION, action);
  }
  fragment.startActivityForResult(intent, requestCode);
}

代码示例来源:origin: jruesga/rview

public static void openDiffViewerActivity(Fragment fragment, ChangeInfo change,
    ArrayList<String> files, Map<String, FileInfo> info, String revisionId, String base, String current,
    String file, String comment, int requestCode) {
  Intent intent = getOpenDiffViewerActivityIntent(fragment.getContext(), change, files, info,
      revisionId, base, current, file, comment, requestCode);
  fragment.startActivityForResult(intent, requestCode);
}

相关文章