Java Code Examples for androidx.fragment.app.Fragment#startActivityForResult()

The following examples show how to use androidx.fragment.app.Fragment#startActivityForResult() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SAFUtils.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * requestCodeに対応するUriへのアクセス要求を行う
 * @param fragment
 * @param requestCode
 * @return 既にrequestCodeに対応するUriが存在していればそれを返す, 存在していなければパーミッション要求をしてnullを返す
 * @throws UnsupportedOperationException
 * @throws IllegalStateException
 */
@Nullable
public static Uri requestPermission(
	@NonNull final Fragment fragment,
	final int requestCode) {

	if (BuildCheck.isLollipop()) {
		@NonNull
		final Uri uri = getStorageUri(fragment.requireContext(), requestCode);
		if (uri == null) {
			// requestCodeに対応するUriへのパーミッションを保持していない時は要求してnullを返す
			fragment.startActivityForResult(prepareStorageAccessPermission(), requestCode);
		}
		return uri;
	} else {
		throw new UnsupportedOperationException("should be API>=21");
	}
}
 
Example 2
Source File: GActivityBuilder.java    From grouter-android with Apache License 2.0 6 votes vote down vote up
public Result startForResult(Fragment fragment, int requestCode, @Nullable Bundle options) {
    if (fragment.getActivity() == null) {
        LoggerUtils.handleException(new NullPointerException("fragment.getActivity() == null"));
        return new Result(false);
    }
    ActivityRequest request = getActivityRequest();
    request.setContext(fragment.getActivity());
    request.setRequestCode(requestCode);

    try {
        if (InterceptorUtils.processActivity(request).isInterrupt()) {
            return new Result(request, false);
        }
        fragment.startActivityForResult(request.getIntent().addFlags(flags), requestCode, options);
        if (enterAnim != 0) {
            fragment.getActivity().overridePendingTransition(enterAnim, exitAnim);
        }
        return new Result(request, true);
    } catch (Exception e) {
        InterceptorUtils.onActivityError(request, e);
    }
    return new Result(request, false);
}
 
Example 3
Source File: PictureSelector.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
/**
 * 选择图片(指定宽高及宽高比例裁剪)
 *
 * @param cropEnabled 是否裁剪
 * @param cropWidth   裁剪宽
 * @param cropHeight  裁剪高
 * @param ratioWidth  宽比例
 * @param ratioHeight 高比例
 */
public void selectPicture(boolean cropEnabled, int cropWidth, int cropHeight, int ratioWidth, int ratioHeight) {
    Activity activity = this.mActivity.get();
    Fragment fragment = this.mFragment.get();
    Intent intent = new Intent(activity, PictureSelectActivity.class);
    intent.putExtra(PictureSelectActivity.ENABLE_CROP, cropEnabled);
    intent.putExtra(PictureSelectActivity.CROP_WIDTH, cropWidth);
    intent.putExtra(PictureSelectActivity.CROP_HEIGHT, cropHeight);
    intent.putExtra(PictureSelectActivity.RATIO_WIDTH, ratioWidth);
    intent.putExtra(PictureSelectActivity.RATIO_HEIGHT, ratioHeight);
    if (fragment != null) {
        fragment.startActivityForResult(intent, mRequestCode);
    } else {
        activity.startActivityForResult(intent, mRequestCode);
    }
}
 
Example 4
Source File: SAFSingleFileUtils.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
 * ファイル保存用のUriを要求
 * KITKAT以降で個別のファイル毎にパーミッション要求する場合
 * @param fragment
 * @param mime
 * @param requestCode
 */
public static void requestCreateDocument(
	@NonNull final Fragment fragment,
	final String mime, final int requestCode) {

	if (BuildCheck.isKitKat()) {
		fragment.startActivityForResult(prepareCreateDocument(mime, null), requestCode);
	}
}
 
Example 5
Source File: PhotoSelectActivity.java    From NewFastFrame with Apache License 2.0 5 votes vote down vote up
public static void start(Fragment fragment, String from, boolean isOne, boolean isCrop, ArrayList<SystemUtil.ImageItem> selectedImageItemList) {
    Intent intent = new Intent(fragment.getContext(), PhotoSelectActivity.class);
    intent.putExtra(ConstantUtil.DATA, selectedImageItemList);
    intent.putExtra(ConstantUtil.IS_ONE, isOne);
    intent.putExtra(ConstantUtil.IS_CROP, isCrop);
    intent.putExtra(ConstantUtil.FROM, from);
    if (isOne) {
        fragment.startActivityForResult(intent, com.example.commonlibrary.utils.SystemUtil.REQUEST_CODE_ONE_PHOTO);
    } else {
        fragment.startActivity(intent);
    }
}
 
Example 6
Source File: CropperImageActivity.java    From WanAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 通过Fragment启动Activity
 * @param uri 图片uri
 * @param isFace 是否改变背景图片
 */
public static void startActivityByFragment(Activity activity, Fragment fragment, Uri uri, int isFace) {
    Intent intent = new Intent(activity, CropperImageActivity.class);
    Bundle bundle = new Bundle();
    bundle.putParcelable(Constant.KEY_IMAGE_URI, uri);
    bundle.putParcelable(Constant.KEY_IMAGE_OPTIONS, new CropImageOptions());
    bundle.putInt(Constant.KEY_IS_FACE, isFace);
    intent.putExtra(Constant.KEY_CROP_BUNDLE, bundle);
    fragment.startActivityForResult(intent, Constant.REQUEST_CROP_IMAGE_ACTIVITY);
}
 
Example 7
Source File: CommCarePreferenceFragment.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
/**
 * Utility function to request a file using a file browser
 * @param fragment Fragment implementing onActivityResult for this file request
 * @param requestCode Request code to fire the file fetch intent with
 * @param errorTitle Title of the error dialogue that appears if no file browser is installed
 */
public static void startFileBrowser(Fragment fragment, int requestCode, String errorTitle) {
    Intent chooseTemplateIntent = new Intent()
            .setAction(Intent.ACTION_GET_CONTENT)
            .setType("file/*")
            .addCategory(Intent.CATEGORY_OPENABLE);
    try {
        fragment.startActivityForResult(chooseTemplateIntent, requestCode);
    } catch (ActivityNotFoundException e) {
        // Means that there is no file browser installed on the device
        TemplatePrinterUtils.showAlertDialog(fragment.getActivity(), Localization.get(errorTitle),
                Localization.get("no.file.browser"), false);
    }
}
 
Example 8
Source File: SAFUtil.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
public static void openFilePicker(Fragment fragment) {
    Intent i = new Intent(Intent.ACTION_CREATE_DOCUMENT);
    i.addCategory(Intent.CATEGORY_OPENABLE);
    i.setType("audio/*");
    i.putExtra("android.content.extra.SHOW_ADVANCED", true);
    fragment.startActivityForResult(i, SAFUtil.REQUEST_SAF_PICK_FILE);
}
 
Example 9
Source File: EditDataProto.java    From Easer with GNU General Public License v3.0 4 votes vote down vote up
public static void delete(@NonNull Fragment fragment, @NonNull Intent intent, int requestCode, @NonNull String name) {
    intent.putExtra(EditDataProto.PURPOSE, EditDataProto.Purpose.delete);
    intent.putExtra(EditDataProto.CONTENT_NAME, name);
    fragment.startActivityForResult(intent, requestCode);
}
 
Example 10
Source File: PictureUtils.java    From science-journal with Apache License 2.0 4 votes vote down vote up
public static void launchPhotoPicker(Fragment fragment) {
  Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
  photoPickerIntent.addCategory(Intent.CATEGORY_OPENABLE);
  photoPickerIntent.setType("image/*");
  fragment.startActivityForResult(photoPickerIntent, REQUEST_SELECT_PHOTO);
}
 
Example 11
Source File: ImageUtil.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void getGaleryPict(Fragment pF) {
    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
    photoPickerIntent.setType("image/*");
    pF.startActivityForResult(photoPickerIntent, REQUEST_PICK_GALERY_PHOTO);
}
 
Example 12
Source File: SAFUtil.java    From VinylMusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void openTreePicker(Fragment fragment) {
    Intent i = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
    i.putExtra("android.content.extra.SHOW_ADVANCED", true);
    fragment.startActivityForResult(i, SAFUtil.REQUEST_SAF_PICK_TREE);
}
 
Example 13
Source File: NoteEditActivity.java    From CrazyDaily with Apache License 2.0 4 votes vote down vote up
public static void start(Fragment fragment, NoteEntity note) {
    Intent intent = new Intent(fragment.getContext(), NoteEditActivity.class);
    intent.putExtra(ActivityConstant.DATA, note);
    fragment.startActivityForResult(intent, REQUEST_CODE);
}
 
Example 14
Source File: UCrop.java    From PictureSelector with Apache License 2.0 2 votes vote down vote up
/**
 * Send the crop Intent with a custom request code
 *
 * @param fragment    Fragment to receive result
 * @param requestCode requestCode for result
 */
public void start(@NonNull Context context, @NonNull Fragment fragment, int requestCode) {
    fragment.startActivityForResult(getIntent(context), requestCode);
}
 
Example 15
Source File: UCropMulti.java    From Matisse-Kotlin with Apache License 2.0 2 votes vote down vote up
/**
 * Send the crop Intent with a custom request code
 *
 * @param fragment    Fragment to receive result
 * @param requestCode requestCode for result
 */
public void start(@NonNull Context context, @NonNull Fragment fragment, int requestCode) {
    fragment.startActivityForResult(getIntent(context), requestCode);
}
 
Example 16
Source File: CropImage.java    From Lassi-Android with MIT License 2 votes vote down vote up
/**
 * Same as {@link #startPickImageActivity(Activity) startPickImageActivity} method but instead of
 * being called and returning to an Activity, this method can be called and return to a Fragment.
 *
 * @param context  The Fragments context. Use getContext()
 * @param fragment The calling Fragment to start and return the image to
 */
public static void startPickImageActivity(@NonNull Context context, @NonNull Fragment fragment) {
    fragment.startActivityForResult(
            getPickImageChooserIntent(context), PICK_IMAGE_CHOOSER_REQUEST_CODE);
}
 
Example 17
Source File: CropImage.java    From Android-Image-Cropper with Apache License 2.0 2 votes vote down vote up
/**
 * Same as {@link #startPickImageActivity(Activity) startPickImageActivity} method but instead of
 * being called and returning to an Activity, this method can be called and return to a Fragment.
 *
 * @param context The Fragments context. Use getContext()
 * @param fragment The calling Fragment to start and return the image to
 */
public static void startPickImageActivity(@NonNull Context context, @NonNull Fragment fragment) {
  fragment.startActivityForResult(
      getPickImageChooserIntent(context), PICK_IMAGE_CHOOSER_REQUEST_CODE);
}
 
Example 18
Source File: ImageSelectorActivity.java    From ImageSelector with Apache License 2.0 2 votes vote down vote up
/**
 * 启动图片选择器
 *
 * @param fragment
 * @param requestCode
 * @param config
 */
public static void openActivity(Fragment fragment, int requestCode, RequestConfig config) {
    Intent intent = new Intent(fragment.getActivity(), ImageSelectorActivity.class);
    intent.putExtra(ImageSelector.KEY_CONFIG, config);
    fragment.startActivityForResult(intent, requestCode);
}
 
Example 19
Source File: CropImage.java    From Android-Image-Cropper with Apache License 2.0 2 votes vote down vote up
/**
 * Start {@link CropImageActivity}.
 *
 * @param fragment fragment to receive result
 */
public void start(@NonNull Context context, @NonNull Fragment fragment) {
  fragment.startActivityForResult(getIntent(context), CROP_IMAGE_ACTIVITY_REQUEST_CODE);
}
 
Example 20
Source File: CropImage.java    From Lassi-Android with MIT License 2 votes vote down vote up
/**
 * Start {@link CropImageActivity}.
 *
 * @param fragment fragment to receive result
 */
public void start(@NonNull Context context, @NonNull Fragment fragment) {
    fragment.startActivityForResult(getIntent(context), CROP_IMAGE_ACTIVITY_REQUEST_CODE);
}