Java Code Examples for android.app.Activity#startActivityForResult()

The following examples show how to use android.app.Activity#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: GActivityBuilder.java    From grouter-android with Apache License 2.0 8 votes vote down vote up
public Result startForResult(Activity activity, int requestCode, @Nullable Bundle options) {
    ActivityRequest request = getActivityRequest();
    request.setContext(activity);
    request.setRequestCode(requestCode);
    try {
        if (InterceptorUtils.processActivity(request).isInterrupt()) {
            return new Result(request, false);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            activity.startActivityForResult(request.getIntent().addFlags(flags), requestCode, options);
        }else {
            activity.startActivityForResult(request.getIntent().addFlags(flags), requestCode);
        }
        if (enterAnim != 0 || exitAnim != 0) {
            activity.overridePendingTransition(enterAnim, exitAnim);
        }
        return new Result(request, true);
    } catch (Exception e) {
        InterceptorUtils.onActivityError(request, e);
    }
    return new Result(request, false);
}
 
Example 2
Source File: PictureUtil.java    From Android-Application-ZJB with Apache License 2.0 7 votes vote down vote up
/**
 * get the photo and crop it .
 * here I find an important thing.
 * we can use this( intent.putExtra("output", uri) ) to put the pic into the uri
 *
 * @param activity
 * @param uri
 */
public static void FindPhotoCrop(Activity activity, Uri uri) {
    if (uri == null) {
        imgUri = createImageUri(activity);
    } else {
        imgUri = uri;
    }
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setDataAndType(imgUri, "image/*")
            .putExtra(MediaStore.EXTRA_OUTPUT, imgUri)
            .putExtra("crop", "true")
            .putExtra("scale", true)
            .putExtra("aspectX", 1)// 裁剪框比例
            .putExtra("aspectY", 1)
            .putExtra("outputX", 300)// 输出图片大小
            .putExtra("outputY", 300)
            .putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString())
            .putExtra("noFaceDetection", true)
            .putExtra("scaleUpIfNeeded", true)
            .putExtra("return-data", false);
    activity.startActivityForResult(intent, REQUEST_CODE_ALBUM_CROP);
}
 
Example 3
Source File: AvatarChangeUtil.java    From landlord_client with Apache License 2.0 7 votes vote down vote up
/**
 * 头像图片裁剪
 */
public static void crop(Activity activity, Uri uri) {
    File pictureCropFile = createImageFile(activity, CROP);
    Uri imgCropUri = Uri.fromFile(pictureCropFile);
    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setDataAndType(uri, "image/*");
    intent.putExtra("crop", "true");
    //缩略图的比例是1:1
    intent.putExtra("aspectX", 1);
    intent.putExtra("aspectY", 1);
    intent.putExtra("outputX", 500);
    intent.putExtra("outputY", 500);
    intent.putExtra("return-data", false);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, imgCropUri);
    ((MainActivity) activity).setCropUri(imgCropUri);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    activity.startActivityForResult(intent, MainActivity.REQUEST_IMAGE_CROP);
}
 
Example 4
Source File: SimpleSearchView.java    From SimpleSearchView with Apache License 2.0 5 votes vote down vote up
private void voiceSearch() {
    Activity activity = ContextUtils.scanForActivity(context);
    if (activity == null) {
        return;
    }

    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    if (voiceSearchPrompt != null && voiceSearchPrompt.isEmpty()) {
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, voiceSearchPrompt);
    }
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
    intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);

    activity.startActivityForResult(intent, REQUEST_VOICE_SEARCH);
}
 
Example 5
Source File: ImageUtils.java    From WifiChat with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 通过手机照相获取图片
 * 
 * @param activity
 * @return 照相后图片的路径
 */
public static String takePicture(Activity activity) {
    FileUtils.createDirFile(BaseApplication.CAMERA_IMAGE_PATH);
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    String path = BaseApplication.CAMERA_IMAGE_PATH + UUID.randomUUID().toString() + "jpg";
    File file = FileUtils.createNewFile(path);
    if (file != null) {
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
    }
    activity.startActivityForResult(intent, INTENT_REQUEST_CODE_CAMERA);
    return path;
}
 
Example 6
Source File: VideoPicker.java    From androidnative.pri with Apache License 2.0 5 votes vote down vote up
static void takeVideo(Map message) {
    if (message.containsKey("broadcast")) {
        broadcast = (Boolean) message.get("broadcast");
    }

   Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
   Activity activity = org.qtproject.qt5.android.QtNative.activity();
   if (takeVideoIntent.resolveActivity(activity.getPackageManager()) != null) {
       activity.startActivityForResult(takeVideoIntent, TAKE_VIDEO_ACTION );
   }
}
 
Example 7
Source File: ShareUtil.java    From ShareSDK with MIT License 5 votes vote down vote up
/**
 * 调起ShareDialogActivity
 * @param activity Activity
 * @param data {@link ShareEntity}
 * @param channel {@link ShareConstant#SHARE_CHANNEL_ALL}
 * @param requestCode requestCode
 */
public static void showShareDialog(Activity activity, int channel, ShareEntity data, int requestCode) {
    if (null == activity || activity.isFinishing()) {
        return;
    }
    Intent intent = new Intent(activity, ShareDialogActivity.class);
    intent.putExtra(ShareConstant.EXTRA_SHARE_DATA, data);
    intent.putExtra(ShareConstant.EXTRA_SHARE_CHANNEL, channel);
    activity.startActivityForResult(intent, requestCode);
}
 
Example 8
Source File: AnalogComplicationConfigRecyclerViewAdapter.java    From wear-os-samples with Apache License 2.0 5 votes vote down vote up
private void launchComplicationHelperActivity(
        Activity currentActivity, ComplicationLocation complicationLocation) {

    mSelectedComplicationId =
            AnalogComplicationWatchFaceService.getComplicationId(complicationLocation);

    mBackgroundComplicationEnabled = false;

    if (mSelectedComplicationId >= 0) {

        int[] supportedTypes =
                AnalogComplicationWatchFaceService.getSupportedComplicationTypes(
                        complicationLocation);

        ComponentName watchFace =
                new ComponentName(
                        currentActivity, AnalogComplicationWatchFaceService.class);

        currentActivity.startActivityForResult(
                ComplicationHelperActivity.createProviderChooserHelperIntent(
                        currentActivity,
                        watchFace,
                        mSelectedComplicationId,
                        supportedTypes),
                AnalogComplicationConfigActivity.COMPLICATION_CONFIG_REQUEST_CODE);

    } else {
        Log.d(TAG, "Complication not supported by watch face.");
    }
}
 
Example 9
Source File: Session.java    From aws-mobile-self-paced-labs-samples with Apache License 2.0 5 votes vote down vote up
AuthorizationRequest(final Activity activity) {
    startActivityDelegate = new StartActivityDelegate() {
        @Override
        public void startActivityForResult(Intent intent, int requestCode) {
            activity.startActivityForResult(intent, requestCode);
        }

        @Override
        public Activity getActivityContext() {
            return activity;
        }
    };
}
 
Example 10
Source File: RootToolsInternalMethods.java    From RedEnvelopeAssistant with MIT License 5 votes vote down vote up
/**
 * This will launch the Android market looking for SuperUser, but will return the intent fired
 * and starts the activity with startActivityForResult
 *
 * @param activity    pass in your Activity
 * @param requestCode pass in the request code
 * @return intent fired
 */
public Intent offerSuperUser(Activity activity, int requestCode)
{
    RootTools.log("Launching Market for SuperUser");
    Intent i = new Intent(Intent.ACTION_VIEW,
            Uri.parse("market://details?id=com.noshufou.android.su"));
    activity.startActivityForResult(i, requestCode);
    return i;
}
 
Example 11
Source File: CalculatorBuilder.java    From CalculatorInputView with Apache License 2.0 5 votes vote down vote up
/**
 * Start the activity using the parent activity
 *
 * @param activity the current activity
 */
public void start(Activity activity) {
    Intent i = new Intent(activity, CalculatorActivity.class);
    if (!TextUtils.isEmpty(activityTitle)) {
        i.putExtra(CalculatorActivity.TITLE_ACTIVITY, activityTitle);
    }

    if (!TextUtils.isEmpty(value)) {
        i.putExtra(CalculatorActivity.VALUE, value);
    }

    activity.startActivityForResult(i, CalculatorActivity.REQUEST_RESULT_SUCCESSFUL);
}
 
Example 12
Source File: IntentUtils.java    From SmileEssence with MIT License 5 votes vote down vote up
/**
 * Start activity for result if callable apps are found
 *
 * @param activity
 * @param intent
 * @param requestCode
 * @return
 */
public static boolean startActivityForResultIfFound(Activity activity, Intent intent, int requestCode) {
    if (canStartActivity(activity, intent)) {
        activity.startActivityForResult(intent, requestCode);
        return true;
    } else {
        new Notificator(activity, R.string.notice_error_start_activity, NotificationType.ALERT).publish();
    }
    return false;
}
 
Example 13
Source File: SchemeDispatcher.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public static void sendSchemeForResult(Activity activity, String url, int requestCode, Bundle bundle, int flag) {

        Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(url));
        if(bundle != null) {
            intent.putExtras(bundle);
        }

        if(flag != 0) {
            intent.setFlags(flag);
        }

        activity.startActivityForResult(intent, requestCode);
    }
 
Example 14
Source File: Audio.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Fire an intent to start the speech recognition activity. onActivityResult
 * is handled in BaseActivity
 */
private void startVoiceRecognitionActivity(Activity a) {

    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Tell me something!");
    a.startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}
 
Example 15
Source File: EditIssueActivity.java    From OpenHub with GNU General Public License v3.0 4 votes vote down vote up
public static void showForEdit(@NonNull Activity activity, @NonNull Issue issue, int requestCode) {
    Intent intent = new Intent(activity, EditIssueActivity.class);
    intent.putExtras(BundleHelper.builder().put("addMode", false).put("issue", issue).build());
    activity.startActivityForResult(intent, requestCode);
}
 
Example 16
Source File: HoundifyVoiceSearchActivity.java    From mirror with Apache License 2.0 4 votes vote down vote up
public static void newInstance(Activity context) {
    final Intent intent = new Intent(context, HoundifyVoiceSearchActivity.class);
    intent.putExtra(SAFE_TOKEN, true);
    context.startActivityForResult(intent, Houndify.REQUEST_CODE);
    context.overridePendingTransition(com.hound.android.voicesdk.R.anim.houndify_search_enter, 0);
}
 
Example 17
Source File: InstagramLoginActivity.java    From InstagramPhotoPicker-Android with MIT License 4 votes vote down vote up
public static void startLoginForResult(Activity activity, String clientId, String redirectUri, int requestCode) {
    Intent i = new Intent(activity, InstagramLoginActivity.class);
    i.putExtra(EXTRA_CLIENT_ID, clientId);
    i.putExtra(EXTRA_REDIRECT_URI, redirectUri);
    activity.startActivityForResult(i, requestCode);
}
 
Example 18
Source File: ImportWalletRouter.java    From ETHWallet with GNU General Public License v3.0 4 votes vote down vote up
public void openForResult(Activity activity, int requestCode) {
	Intent intent = new Intent(activity, ImportWalletActivity.class);
	activity.startActivityForResult(intent, requestCode);
}
 
Example 19
Source File: ActivityCompat.java    From adt-leanback-support with Apache License 2.0 3 votes vote down vote up
/**
 * Start new activity with options, if able, for which you would like a
 * result when it finished.
 *
 * <p>In Android 4.1+ additional options were introduced to allow for more
 * control on activity launch animations. Applications can use this method
 * along with {@link ActivityOptionsCompat} to use these animations when
 * available. When run on versions of the platform where this feature does
 * not exist the activity will be launched normally.</p>
 *
 * @param activity Origin activity to launch from.
 * @param intent The description of the activity to start.
 * @param requestCode If >= 0, this code will be returned in
 *                   onActivityResult() when the activity exits.
 * @param options Additional options for how the Activity should be started.
 *                May be null if there are no options. See
 *                {@link ActivityOptionsCompat} for how to build the Bundle
 *                supplied here; there are no supported definitions for
 *                building it manually.
 */
public static void startActivityForResult(Activity activity, Intent intent, int requestCode,
        @Nullable Bundle options) {
    if (Build.VERSION.SDK_INT >= 16) {
        ActivityCompatJB.startActivityForResult(activity, intent, requestCode, options);
    } else {
        activity.startActivityForResult(intent, requestCode);
    }
}
 
Example 20
Source File: ImageSelectorActivity.java    From ImageSelector with Apache License 2.0 2 votes vote down vote up
/**
 * 启动图片选择器
 *
 * @param activity
 * @param requestCode
 * @param config
 */
public static void openActivity(Activity activity, int requestCode, RequestConfig config) {
    Intent intent = new Intent(activity, ImageSelectorActivity.class);
    intent.putExtra(ImageSelector.KEY_CONFIG, config);
    activity.startActivityForResult(intent, requestCode);
}