android.app.Activity.setResult()

Here are the examples of the java api android.app.Activity.setResult() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

65 Examples 7

19 Source : ActivityRouter.java
with Apache License 2.0
from Zane96

/**
 * setResult()
 * @param activity
 * @param message
 */
public void setResult(Activity activity, int resultCode, Message message) {
    Intent intent = new Intent();
    intent.putExtra(ROUTER_MESSAGE, message);
    activity.setResult(resultCode, intent);
}

19 Source : FlutterNativePageDelegate.java
with MIT License
from weidian

/**
 * 设置 activity 的页面结果
 */
public void setPageResult(@Nullable Object result) {
    Activity activity = page.getActivity();
    if (activity != null) {
        if (result == null) {
            activity.setResult(Activity.RESULT_OK);
        } else {
            Intent data = new Intent();
            FlutterStackManagerUtil.updateIntent(data, ARG_RESULT_KEY, result);
            activity.setResult(Activity.RESULT_OK, data);
        }
    }
}

19 Source : TransitionCompat.java
with GNU General Public License v3.0
from tianyuan168326

/**
 * 在Activity.onBackPressed()中执行的方法,请不要执行onBackPressed()的super方法体
 * 这时候已经可以确保要执行动画的view显示完成了,所以可以安全的执行这个方法
 *
 * @param activity
 */
public static void finishAfterTransition(Activity activity) {
    if (isPlaying) {
        return;
    }
    isEnter = false;
    activity.setResult(ActivityOptionsCompatICS.RESULT_CODE);
    mListener = new TransitionCompat().new MyTransitionListener();
    // 开始执行动画,这里的false表示执行结束的动画
    switch(mAnimationType) {
        case ActivityOptionsCompatICS.ANIM_SCALE_UP:
            scaleUpAnimation(activity, false);
            break;
        case ActivityOptionsCompatICS.ANIM_THUMBNAIL_SCALE_UP:
            thumbnailScaleUpAnimation(activity, false);
            break;
        case ActivityOptionsCompatICS.ANIM_SCENE_TRANSITION:
            sceneTransitionAnimation(activity, mLayoutResId, false);
            break;
        case ActivityOptionsCompatICS.ANIM_NONE:
            activity.finish();
            return;
        default:
            activity.finish();
            return;
    }
    // 执行场景退出的动画
    if (mTransitionAnims != null) {
        mTransitionAnims.setAnimsInterpolator(mInterpolator);
        mTransitionAnims.setAnimsStartDelay(mStartDelay);
        mTransitionAnims.setAnimsDuration(mAnimTime);
        mTransitionAnims.addListener(mListener);
        mTransitionAnims.playScreenExitAnims();
    }
    mTransitionAnims = null;
}

19 Source : ActNewAircraft.java
with GNU General Public License v3.0
from ericberman

private void Dismiss() {
    Intent i = new Intent();
    Activity a = getActivity();
    if (a != null) {
        a.setResult(Activity.RESULT_OK, i);
        a.finish();
    }
}

19 Source : FacialRecognitionFragment.java
with MIT License
from BioID-GmbH

@Override
public void navigateBack(boolean success) {
    Activity activity = getActivity();
    if (activity != null) {
        activity.setResult(success ? Activity.RESULT_OK : Activity.RESULT_CANCELED);
        activity.finish();
    }
}

19 Source : FacialRecognitionFragment.java
with MIT License
from BioID-GmbH

/**
 * Sometimes accessing the camera is not possible (e.g. the camera driver does perform a disconnect).
 * In these cases the activity will be closed.
 */
private void logErrorAndFinish(@NonNull String msg, Object... args) {
    log.e(msg, args);
    Activity activity = getActivity();
    if (activity != null) {
        activity.setResult(Activity.RESULT_CANCELED);
        activity.finish();
    }
}

18 Source : PickerErrorExecutor.java
with Apache License 2.0
from zhouhuandev

public static void executeError(Activity activity, int code) {
    activity.setResult(code);
    activity.finish();
}

18 Source : CaptureManager.java
with GNU General Public License v3.0
from umerov1999

protected void returnResultTimeout() {
    Intent intent = new Intent(Intents.Scan.ACTION);
    intent.putExtra(Intents.Scan.TIMEOUT, true);
    activity.setResult(Activity.RESULT_CANCELED, intent);
    closeAndFinish();
}

18 Source : CaptureManager.java
with GNU General Public License v3.0
from umerov1999

private void setMissingCameraPermissionResult() {
    Intent intent = new Intent(Intents.Scan.ACTION);
    intent.putExtra(Intents.Scan.MISSING_CAMERA_PERMISSION, true);
    activity.setResult(Activity.RESULT_CANCELED, intent);
}

18 Source : ScanQRCodeFragment.java
with GNU General Public License v3.0
from trojan-gfw

private void returnEmptyResult() {
    Activity activity = requireActivity();
    activity.setResult(Activity.RESULT_CANCELED);
    activity.finish();
}

18 Source : BroadcastManagerImpl.java
with MIT License
from kinecosystem

@Override
public void setActivityResult(int resultCode, Intent data) {
    activity.setResult(resultCode, data);
}

18 Source : BackResult.java
with Apache License 2.0
from foreveruseful

/**
 * Finish the activity with your given result code and or intent and or params.
 * @param activity
 *  The activity that will be finish, it's finish() will be called in this method.
 */
public void finishWithResult(Activity activity) {
    Intent in = intent;
    if (params != null) {
        in = in == null ? params.buildIntent() : in.putExtras(params.buildIntent().getExtras());
    }
    if (in != null) {
        activity.setResult(code, in);
    } else {
        activity.setResult(code);
    }
    activity.finish();
    ;
}

17 Source : StateManager.java
with Apache License 2.0
from yuchuangu85

void finishState(ActivityState state, boolean fireOnPause) {
    // The finish() request could be rejected (only happens under Monkey),
    // If it is rejected, we won't close the last page.
    if (mStack.size() == 1) {
        Activity activity = (Activity) mActivity.getAndroidContext();
        if (mResult != null) {
            activity.setResult(mResult.resultCode, mResult.resultData);
        }
        activity.finish();
        if (!activity.isFinishing()) {
            Log.w(TAG, "finish is rejected, keep the last state");
            return;
        }
        Log.v(TAG, "no more state, finish activity");
    }
    Log.v(TAG, "finishState " + state);
    if (state != mStack.peek().activityState) {
        if (state.isDestroyed()) {
            Log.d(TAG, "The state is already destroyed");
            return;
        } else {
            throw new IllegalArgumentException("The stateview to be finished" + " is not at the top of the stack: " + state + ", " + mStack.peek().activityState);
        }
    }
    // Remove the top state.
    mStack.pop();
    state.mIsFinishing = true;
    ActivityState top = !mStack.isEmpty() ? mStack.peek().activityState : null;
    if (mIsResumed && fireOnPause) {
        if (top != null) {
            state.transitionOnNextPause(state.getClreplaced(), top.getClreplaced(), StateTransitionAnimation.Transition.Outgoing);
        }
        state.onPause();
    }
    mActivity.getGLRoot().setContentPane(null);
    state.onDestroy();
    if (top != null && mIsResumed)
        top.resume();
    if (top != null) {
        UsageStatistics.onContentViewChanged(UsageStatistics.COMPONENT_GALLERY, top.getClreplaced().getSimpleName());
    }
}

17 Source : BackFlow.java
with Apache License 2.0
from xuyt11

static void request(@NonNull Activity activity, @NonNull Intent backFlowData) {
    activity.setResult(RESULT_CODE, backFlowData);
    activity.finish();
}

17 Source : SignRequestHelper.java
with GNU General Public License v3.0
from xieyueshu

private void result(Activity activity, int error, byte[] sign) {
    Intent intent = makeResultIntent(error, sign);
    if (request.getCallbackUri() == null) {
        int code;
        if (error != NONE) {
            code = error == CANCELED ? RESULT_CANCELED : RESULT_ERROR;
        } else {
            code = RESULT_OK;
        }
        activity.setResult(code, intent);
        activity.finish();
    } else if (Trust.canStartActivity(activity, intent)) {
        activity.startActivity(intent);
        activity.finish();
    } else {
        new AlertDialog.Builder(activity).setreplacedle("No application found").setMessage("No proper application to handle result").create().show();
    }
}

17 Source : ActivityUtils.java
with Apache License 2.0
from vsona

public static void backResult(Activity sourceActivity, int resultCode, Bundle bdl) {
    Intent intent = new Intent();
    if (bdl != null) {
        intent.putExtras(bdl);
    }
    sourceActivity.setResult(resultCode, intent);
}

17 Source : CaptureManager.java
with GNU General Public License v3.0
from umerov1999

protected void returnResult(BarcodeResult rawResult) {
    Intent intent = resultIntent(rawResult, getBarcodeImagePath(rawResult));
    activity.setResult(Activity.RESULT_OK, intent);
    closeAndFinish();
}

17 Source : ScanQRCodeFragment.java
with GNU General Public License v3.0
from trojan-gfw

private void returnScanResult(String qrCode) {
    Activity activity = requireActivity();
    activity.setResult(Activity.RESULT_OK, new Intent().putExtra(KEY_SCAN_CONTENT, qrCode));
    activity.finish();
}

17 Source : ExemptAppFragment.java
with GNU General Public License v3.0
from trojan-gfw

@Override
public void exit(boolean configurationChanged) {
    Activity activity = getActivity();
    if (activity != null) {
        activity.setResult(configurationChanged ? Activity.RESULT_OK : Activity.RESULT_CANCELED);
        activity.finish();
    }
}

17 Source : NoteFragment.java
with GNU Affero General Public License v3.0
from Shouheng88

private void addSubscriptions() {
    viewModel.getNoteObservable().observe(this, resources -> {
        replacedert resources != null;
        switch(resources.status) {
            case SUCCESS:
                replacedert resources.data != null;
                viewModel.fetchNoteContent();
                break;
        }
    });
    viewModel.getNoteContentObservable().observe(this, resources -> {
        replacedert resources != null;
        switch(resources.status) {
            case SUCCESS:
                Note note = viewModel.getNote();
                etreplacedle.setText(note.getreplacedle());
                eme.setText(note.getContent());
                break;
            case FAILED:
                ToastUtils.showShort(R.string.text_failed_to_read_note_file);
                break;
        }
    });
    viewModel.getSaveOrUpdateObservable().observe(this, resources -> {
        replacedert resources != null;
        switch(resources.status) {
            case SUCCESS:
                Activity activity = getActivity();
                replacedert resources.data != null;
                if (resources.data) {
                    AppWidgetUtils.notifyAppWidgets(getContext());
                    postEvent(new RxMessage(RxMessage.CODE_NOTE_DATA_CHANGED, null));
                    if (activity != null) {
                        activity.setResult(RESULT_OK);
                    }
                }
                if (activity != null) {
                    activity.finish();
                }
                break;
            case FAILED:
                ToastUtils.showShort(R.string.text_failed_to_save_note);
                break;
            case LOADING:
                break;
        }
    });
}

17 Source : QuickUtil.java
with BSD 3-Clause "New" or "Revised" License
from quickhybrid

/**
 * 本地页面回传数据给Quick页面
 *
 * @param activity
 * @param json
 */
public static void quickResult(Activity activity, String json) {
    Intent intent = new Intent();
    intent.putExtra("resultData", json);
    activity.setResult(Activity.RESULT_OK, intent);
}

17 Source : JavaFileStorageBase.java
with GNU General Public License v3.0
from PhilippC

protected void finishWithError(final FileStorageSetupActivity setupAct, Exception error) {
    logDebug("Exception: " + error.toString());
    error.printStackTrace();
    final Activity activity = (Activity) setupAct;
    int resultCode = Activity.RESULT_CANCELED;
    // check if we should return OK anyways.
    // This can make sense if there is a higher-level FileStorage which has the file cached.
    if (activity.getIntent().getBooleanExtra(EXTRA_ALWAYS_RETURN_SUCCESS, false)) {
        logDebug("Returning success as desired in intent despite of exception.");
        finishActivityWithSuccess(setupAct);
        return;
    }
    Intent retData = new Intent();
    retData.putExtra(EXTRA_ERROR_MESSAGE, error.getMessage());
    activity.setResult(resultCode, retData);
    activity.finish();
}

17 Source : JavaFileStorageBase.java
with GNU General Public License v3.0
from PhilippC

protected void finishActivityWithSuccess(FileStorageSetupActivity setupActivity) {
    // Log.d("KP2AJ", "Success with authenticating!");
    Activity activity = (Activity) setupActivity;
    if (setupActivity.getProcessName().equals(PROCESS_NAME_FILE_USAGE_SETUP)) {
        Intent data = new Intent();
        data.putExtra(EXTRA_IS_FOR_SAVE, setupActivity.isForSave());
        data.putExtra(EXTRA_PATH, setupActivity.getPath());
        activity.setResult(RESULT_FILEUSAGE_PREPARED, data);
        activity.finish();
        return;
    }
    if (setupActivity.getProcessName().equals(PROCESS_NAME_SELECTFILE)) {
        Intent data = new Intent();
        String path = setupActivity.getState().getString(EXTRA_PATH);
        if (path != null)
            data.putExtra(EXTRA_PATH, path);
        activity.setResult(RESULT_FILECHOOSER_PREPARED, data);
        activity.finish();
        return;
    }
    logDebug("Unknown process: " + setupActivity.getProcessName());
}

17 Source : DisableSecurityCheck.java
with MIT License
from neoblackxt

private void bypreplacedSuperNotCalledException(XC_MethodHook.MethodHookParam param) {
    Activity activity = (Activity) param.thisObject;
    findField(Activity.clreplaced, "mCalled").setAccessible(true);
    setBooleanField(activity, "mCalled", true);
    activity.setResult(Activity.RESULT_OK);
    activity.finish();
    param.setResult(null);
}

17 Source : AccountInfoManager.java
with MIT License
from kinecosystem

private void respondCancel(boolean hasError) {
    Intent intent = new Intent();
    if (hasError) {
        intent.putExtra(EXTRA_HAS_ERROR, hasError);
    }
    if (activity != null) {
        activity.setResult(Activity.RESULT_CANCELED, intent);
    }
}

17 Source : CommonUtils.java
with Apache License 2.0
from JackChan1999

@TargetApi(16)
public static void finishAffinity(Activity activity, int resultCode) {
    if (activity != null) {
        if (VERSION.SDK_INT >= 16) {
            activity.finishAffinity();
            return;
        }
        activity.setResult(resultCode);
        activity.finish();
    }
}

17 Source : ERecorderActivityImpl.java
with Apache License 2.0
from f-evil

/**
 * 设置返回值并关闭页面
 *
 * @param activity    activity
 * @param videoPath   压缩地址
 * @param thumblePath 视频截图地址
 * @param originPath  当前地址
 */
static void setResultAndFinish(Activity activity, String videoPath, String thumblePath, String originPath) {
    Intent i = new Intent();
    i.putExtra(MEDIA_PATH, StringUtil.removeEmpty(videoPath, ""));
    i.putExtra(MEDIA_THUMBLE_PATH, StringUtil.removeEmpty(thumblePath, ""));
    i.putExtra(MEDIA_ORIGIN_PATH, StringUtil.removeEmpty(originPath, ""));
    activity.setResult(activity.RESULT_OK, i);
    activity.finish();
}

17 Source : ERecorderActivityImpl.java
with Apache License 2.0
from f-evil

public static void setResultAndFinish(Activity activity, VideoInfo videoInfo) {
    Intent i = new Intent();
    i.putExtra(MEDIA_VIDEO_INFO, videoInfo);
    activity.setResult(activity.RESULT_OK, i);
    activity.finish();
}

17 Source : SignInFragment.java
with Apache License 2.0
from arduino

private void finish() {
    Activity activity = getActivity();
    accountsProvider.setShowSignInActivityIfNotSignedIn(false);
    activity.setResult(Activity.RESULT_OK);
    activity.finish();
}

17 Source : PreviewFragment.java
with MIT License
from 0ranko0P

protected void finishActivity(boolean success) {
    Activity activity = getActivity();
    if (activity == null) {
        return;
    }
    if (success) {
        activity.setResult(Activity.RESULT_OK);
    }
    activity.overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
    activity.finish();
}

16 Source : YcShareElement.java
with Apache License 2.0
from yellowcath

public static void finishAfterTransition(Activity activity, IShareElements IShareElements) {
    ShareElementInfo[] shareElements = IShareElements == null ? null : IShareElements.getShareElements();
    if (shareElements != null) {
        ArrayList<ShareElementInfo> list = new ArrayList<>(Arrays.asList(shareElements));
        Intent intent = new Intent();
        intent.putParcelableArrayListExtra(KEY_SHARE_ELEMENTS, list);
        activity.setResult(RESULT_OK, intent);
    }
}

16 Source : ActivityResultModule.java
with MIT License
from rozele

@ReactMethod
public void finish(int result, String action, ReadableMap map) {
    Activity activity = getReactApplicationContext().getCurrentActivity();
    Intent intent = new Intent(action);
    intent.putExtras(Arguments.toBundle(map));
    activity.setResult(result, intent);
    activity.finish();
}

16 Source : DatePickerFragment.java
with Apache License 2.0
from Qinlong275

private void sendResult(int resultCode, Date date) {
    Intent data = new Intent();
    data.putExtra(EXTRA_DATE, date);
    if (getTargetFragment() == null) {
        Activity hostingActivity = getActivity();
        hostingActivity.setResult(resultCode, data);
        hostingActivity.finish();
    } else {
        dismiss();
        getTargetFragment().onActivityResult(getTargetRequestCode(), resultCode, data);
    }
}

16 Source : PCloudFileStorage.java
with GNU General Public License v3.0
from PhilippC

private void handleAuthResult(FileStorageSetupActivity activity, AuthorizationData authorizationData) {
    if (authorizationData.result == AuthorizationResult.ACCESS_GRANTED) {
        String authToken = authorizationData.token;
        String apiHost = authorizationData.apiHost;
        setAuthToken(authToken, apiHost);
        finishActivityWithSuccess(activity);
    } else {
        Activity castedActivity = (Activity) activity;
        Intent resultData = new Intent();
        resultData.putExtra(EXTRA_ERROR_MESSAGE, "Authentication failed!");
        // reset any stored token in case we have an invalid one
        clearAuthToken();
        castedActivity.setResult(Activity.RESULT_CANCELED, resultData);
        castedActivity.finish();
    }
}

16 Source : ActivityUtils.java
with GNU Lesser General Public License v3.0
from OracleChain

/**
 * 返回到上一个页面并返回值
 * @param curActivity
 * @param retCode
 * @param retData
 * @param inAnimId
 * @param outAnimId
 */
public static void goBackWithResult(Activity curActivity, int retCode, Bundle retData, int inAnimId, int outAnimId) {
    Intent intent = null;
    intent = new Intent();
    if (null != retData) {
        intent.putExtras(retData);
    }
    curActivity.setResult(retCode, intent);
    curActivity.finish();
    curActivity.overridePendingTransition(inAnimId, outAnimId);
}

16 Source : OpenNoteCameraView.java
with MIT License
from Michaelvilleneuve

public void saveDoreplacedent(ScannedDoreplacedent scannedDoreplacedent) {
    Mat doc = (scannedDoreplacedent.processed != null) ? scannedDoreplacedent.processed : scannedDoreplacedent.original;
    Intent intent = mActivity.getIntent();
    boolean isIntent = false;
    Uri fileUri = null;
    String fileName = this.saveToDirectory(doc);
    String initialFileName = this.saveToDirectory(scannedDoreplacedent.original);
    WritableMap data = new WritableNativeMap();
    if (this.listener != null) {
        data.putInt("height", scannedDoreplacedent.heightWithRatio);
        data.putInt("width", scannedDoreplacedent.widthWithRatio);
        data.putString("croppedImage", "file://" + fileName);
        data.putString("initialImage", "file://" + initialFileName);
        data.putMap("rectangleCoordinates", scannedDoreplacedent.previewPointsAsHash());
        this.listener.onPictureTaken(data);
    }
    if (isIntent) {
        InputStream inputStream = null;
        OutputStream realOutputStream = null;
        try {
            inputStream = new FileInputStream(fileName);
            realOutputStream = mActivity.getContentResolver().openOutputStream(fileUri);
            // Transfer bytes from in to out
            byte[] buffer = new byte[1024];
            int len;
            while ((len = inputStream.read(buffer)) > 0) {
                realOutputStream.write(buffer, 0, len);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return;
        } catch (IOException e) {
            e.printStackTrace();
            return;
        } finally {
            try {
                inputStream.close();
                realOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    Log.d(TAG, "wrote: " + fileName);
    if (isIntent) {
        new File(fileName).delete();
        mActivity.setResult(Activity.RESULT_OK, intent);
        mActivity.finish();
    } else {
        animateDoreplacedent(fileName, scannedDoreplacedent);
        addImageToGallery(fileName, mContext);
    }
    // Record goal "PictureTaken"
    // ((OpenNoteScannerApplication) getApplication()).getTracker().trackGoal(1);
    refreshCamera();
}

16 Source : AssistActivity.java
with Apache License 2.0
from JackChan1999

public static void setResultDataForLogin(Activity activity, Intent intent) {
    if (intent == null) {
        activity.setResult(Constants.RESULT_LOGIN, intent);
        return;
    }
    try {
        Object stringExtra = intent.getStringExtra(Constants.KEY_RESPONSE);
        f.b(TAG, "replacedistActivity--setResultDataForLogin-- " + stringExtra);
        if (!TextUtils.isEmpty(stringExtra)) {
            JSONObject jSONObject = new JSONObject(stringExtra);
            CharSequence optString = jSONObject.optString("openid");
            CharSequence optString2 = jSONObject.optString("access_token");
            if (TextUtils.isEmpty(optString) || TextUtils.isEmpty(optString2)) {
                activity.setResult(LetvBaseWebViewActivity.Login_OK, intent);
            } else {
                activity.setResult(Constants.RESULT_LOGIN, intent);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

16 Source : FirstRunActivity.java
with Apache License 2.0
from derry

protected static void finishAllFREActivities(int result, Intent data) {
    List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities();
    for (WeakReference<Activity> weakActivity : activities) {
        Activity activity = weakActivity.get();
        if (activity instanceof FirstRunActivity) {
            activity.setResult(result, data);
            activity.finish();
        }
    }
}

16 Source : NavigatorModule.java
with MIT License
from airbnb

private void dismiss(Activity activity, ReadableMap payload) {
    Intent intent = new Intent().putExtra(EXTRA_PAYLOAD, payloadToMap(payload));
    if (activity instanceof ReactInterface) {
        // TODO: 10/6/16 emily this doesn't work for ReactNativeFragment
        intent.putExtra(EXTRA_IS_DISMISS, ((ReactInterface) activity).isDismissible());
    }
    activity.setResult(getResultCodeFromPayload(payload), intent);
    activity.finish();
}

15 Source : ImagePicker.java
with Apache License 2.0
from zhouhuandev

/**
 * 关闭选择器并回调数据
 *
 * @param list 回调数组
 */
public static void closePickerWithCallback(ArrayList<ImageItem> list) {
    Activity activity = PickerActivityManager.getLastActivity();
    if (activity == null || list == null || list.size() == 0) {
        return;
    }
    Intent intent = new Intent();
    intent.putExtra(ImagePicker.INTENT_KEY_PICKER_RESULT, list);
    activity.setResult(ImagePicker.REQ_PICKER_RESULT_CODE, intent);
    activity.finish();
    PickerActivityManager.clear();
}

15 Source : PersonalInfoFragment.java
with Apache License 2.0
from JackChan1999

public static void sysLogout(Activity activity) {
    if (PreferencesManager.getInstance().isVip()) {
        DownloadManager.pauseVipDownloadTask();
    }
    LoginManager.getLoginManager().unBindLogin(activity);
    LoginManager.getLoginManager().sendLogInOutIntent("logout_success", activity);
    PreferencesManager.getInstance().logoutUser();
    PreferencesManager.getInstance().setUserPhoneNumberBindState(false);
    LoginManager.getLoginManager().LogoutUser(activity);
    LogInfo.log("ZSM", "ID == " + PreferencesManager.getInstance().getUserId());
    UserInfoTools.logout(activity);
    RedPacketSdkManager.getInstance().setUid("");
    RedPacketSdkManager.getInstance().setToken("");
    try {
        LeMessageManager.getInstance().dispatchMessage(activity, new LeMessage(LeMessageIds.MSG_WEBVIEW_SYNC_LOGIN));
        activity.setResult(9528);
        activity.finish();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

15 Source : OcrDetectorProcessor.java
with Apache License 2.0
from HMS-Core

@Override
public void transactResult(MLreplacedyzer.Result<MLText.Block> results) {
    SparseArray<MLText.Block> items = results.getreplacedyseList();
    for (int i = 0; i < items.size(); i++) {
        String str = items.get(i).getStringValue().replace(" ", "");
        String result = str;
        if (replacedle == null) {
            continue;
        }
        if (!result.contains(replacedle)) {
            continue;
        }
        int number = replacedle.length();
        if (number > 0) {
            result = str.substring(number, number + regexpnumber);
        }
        match = pattern.matcher(result);
        if (match.matches()) {
            Intent intent = new Intent();
            intent.putExtra("result", result);
            activity.setResult(RESULT_OK, intent);
            activity.finish();
        }
    }
}

15 Source : OpenNoteCameraView.java
with MIT License
from andreluisjunqueira

public void saveDoreplacedent(ScannedDoreplacedent scannedDoreplacedent) {
    Mat doc = (scannedDoreplacedent.processed != null) ? scannedDoreplacedent.processed : scannedDoreplacedent.original;
    Intent intent = mActivity.getIntent();
    String fileName;
    boolean isIntent = false;
    Uri fileUri = null;
    if (intent.getAction() != null && intent.getAction().equals("android.media.action.IMAGE_CAPTURE")) {
        fileUri = ((Uri) intent.getParcelableExtra(MediaStore.EXTRA_OUTPUT));
        Log.d(TAG, "intent uri: " + fileUri.toString());
        try {
            fileName = File.createTempFile("onsFile", ".jpg", mContext.getCacheDir()).getPath();
        } catch (IOException e) {
            e.printStackTrace();
            return;
        }
        isIntent = true;
    } else {
        String folderName = "doreplacedents";
        File folder = new File(Environment.getExternalStorageDirectory().toString() + "/" + folderName);
        if (!folder.exists()) {
            folder.mkdirs();
            Log.d(TAG, "wrote: created folder " + folder.getPath());
        }
        fileName = Environment.getExternalStorageDirectory().toString() + "/" + folderName + "/DOC-" + new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date()) + ".jpg";
    }
    Mat endDoc = new Mat(Double.valueOf(doc.size().width).intValue(), Double.valueOf(doc.size().height).intValue(), CvType.CV_8UC4);
    Core.flip(doc.t(), endDoc, 1);
    Imgcodecs.imwrite(fileName, endDoc);
    endDoc.release();
    WritableMap data = new WritableNativeMap();
    if (this.listener != null) {
        data.putString("path", fileName);
        this.listener.onPictureTaken(data);
    }
    if (isIntent) {
        InputStream inputStream = null;
        OutputStream realOutputStream = null;
        try {
            inputStream = new FileInputStream(fileName);
            realOutputStream = mActivity.getContentResolver().openOutputStream(fileUri);
            // Transfer bytes from in to out
            byte[] buffer = new byte[1024];
            int len;
            while ((len = inputStream.read(buffer)) > 0) {
                realOutputStream.write(buffer, 0, len);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return;
        } catch (IOException e) {
            e.printStackTrace();
            return;
        } finally {
            try {
                inputStream.close();
                realOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    Log.d(TAG, "wrote: " + fileName);
    if (isIntent) {
        new File(fileName).delete();
        mActivity.setResult(Activity.RESULT_OK, intent);
        mActivity.finish();
    } else {
        animateDoreplacedent(fileName, scannedDoreplacedent);
        addImageToGallery(fileName, mContext);
    }
    // Record goal "PictureTaken"
    // ((OpenNoteScannerApplication) getApplication()).getTracker().trackGoal(1);
    refreshCamera();
}

14 Source : CaptureActivityHandler.java
with GNU Lesser General Public License v3.0
from LiuhangZhang

@Override
public void handleMessage(Message message) {
    if (message.what == R.id.restart_preview) {
        restartPreviewAndDecode();
    } else if (message.what == R.id.decode_succeeded) {
        state = State.SUCCESS;
        ivew.handleDecode((Result) message.obj);
    } else if (message.what == R.id.decode_failed) {
        // We're decoding as fast as possible, so when one
        // decode fails,
        // start another.
        state = State.PREVIEW;
        cameraManager.requestPreviewFrame(decodeThread.getHandler(), R.id.decode);
    } else if (message.what == R.id.return_scan_result) {
        activity.setResult(Activity.RESULT_OK, (Intent) message.obj);
        activity.finish();
    }
}

14 Source : DownloadGif.java
with MIT License
from klinker24

@Override
protected void onPostExecute(Uri downloadedTo) {
    try {
        if (callback != null) {
            callback.onGifSelected(downloadedTo);
            dialog.dismiss();
        } else if (downloadedTo != null) {
            activity.setResult(Activity.RESULT_OK, new Intent().setData(downloadedTo));
            activity.finish();
            try {
                dialog.dismiss();
            } catch (Exception e) {
                Log.e("Exception", String.valueOf(e));
            }
        } else {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                Toast.makeText(activity, R.string.error_downloading_gif, Toast.LENGTH_SHORT).show();
                activity.finish();
            } else {
                Toast.makeText(activity, R.string.error_downloading_gif_permission, Toast.LENGTH_SHORT).show();
                activity.finish();
            }
        }
    } catch (IllegalStateException e) {
        Log.e("Exception", String.valueOf(e));
    }
}

13 Source : CommonHandler.java
with Apache License 2.0
from HMS-Core

@Override
public void handleMessage(Message message) {
    Log.e(TAG, String.valueOf(message.what));
    removeMessages(1);
    if (message.what == 0) {
        CommonActivity commonActivity1 = (CommonActivity) activity;
        commonActivity1.scanResultView.clear();
        Intent intent = new Intent();
        intent.putExtra(CommonActivity.SCAN_RESULT, (HmsScan[]) message.obj);
        activity.setResult(RESULT_OK, intent);
        // Show the scanning result on the screen.
        if (mode == MainActivity.MULTIPROCESSOR_ASYN_CODE || mode == MainActivity.MULTIPROCESSOR_SYN_CODE) {
            CommonActivity commonActivity = (CommonActivity) activity;
            HmsScan[] arr = (HmsScan[]) message.obj;
            for (int i = 0; i < arr.length; i++) {
                if (i == 0) {
                    commonActivity.scanResultView.add(new ScanResultView.HmsScanGraphic(commonActivity.scanResultView, arr[i], Color.YELLOW));
                } else if (i == 1) {
                    commonActivity.scanResultView.add(new ScanResultView.HmsScanGraphic(commonActivity.scanResultView, arr[i], Color.BLUE));
                } else if (i == 2) {
                    commonActivity.scanResultView.add(new ScanResultView.HmsScanGraphic(commonActivity.scanResultView, arr[i], Color.RED));
                } else if (i == 3) {
                    commonActivity.scanResultView.add(new ScanResultView.HmsScanGraphic(commonActivity.scanResultView, arr[i], Color.GREEN));
                } else {
                    commonActivity.scanResultView.add(new ScanResultView.HmsScanGraphic(commonActivity.scanResultView, arr[i]));
                }
            }
            commonActivity.scanResultView.setCameraInfo(1080, 1920);
            commonActivity.scanResultView.invalidate();
            sendEmptyMessageDelayed(1, 1000);
        } else {
            activity.finish();
        }
    } else if (message.what == 1) {
        CommonActivity commonActivity1 = (CommonActivity) activity;
        commonActivity1.scanResultView.clear();
    }
}

13 Source : CommonHandler.java
with Apache License 2.0
from HMS-Core

@Override
public void handleMessage(final Message message) {
    Log.e(TAG, String.valueOf(message.what));
    removeMessages(1);
    if (message.what == 0) {
        final CommonActivity commonActivity1 = (CommonActivity) activity;
        commonActivity1.scanResultView.clear();
        final Intent intent = new Intent();
        intent.putExtra(CommonActivity.SCAN_RESULT, (HmsScan[]) message.obj);
        activity.setResult(RESULT_OK, intent);
        // Show the scanning result on the screen.
        if (mode == MULTIPROCESSOR_ASYN_CODE || mode == MULTIPROCESSOR_SYN_CODE) {
            final CommonActivity commonActivity = (CommonActivity) activity;
            final HmsScan[] arr = (HmsScan[]) message.obj;
            for (int i = 0; i < arr.length; i++) {
                if (i == 0) {
                    commonActivity.scanResultView.add(new ScanResultView.HmsScanGraphic(commonActivity.scanResultView, arr[i], Color.YELLOW));
                } else if (i == 1) {
                    commonActivity.scanResultView.add(new ScanResultView.HmsScanGraphic(commonActivity.scanResultView, arr[i], Color.BLUE));
                } else if (i == 2) {
                    commonActivity.scanResultView.add(new ScanResultView.HmsScanGraphic(commonActivity.scanResultView, arr[i], Color.RED));
                } else if (i == 3) {
                    commonActivity.scanResultView.add(new ScanResultView.HmsScanGraphic(commonActivity.scanResultView, arr[i], Color.GREEN));
                } else {
                    commonActivity.scanResultView.add(new ScanResultView.HmsScanGraphic(commonActivity.scanResultView, arr[i]));
                }
            }
            commonActivity.scanResultView.setCameraInfo(1080, 1920);
            commonActivity.scanResultView.invalidate();
            sendEmptyMessageDelayed(1, 1000);
        } else {
            activity.finish();
        }
    }
    if (message.what == 1) {
        final CommonActivity commonActivity1 = (CommonActivity) activity;
        commonActivity1.scanResultView.clear();
    }
}

13 Source : AndroidSharing.java
with MIT License
from FalsinSoft

public boolean shareFile(boolean fileAvailable, String mimeType, String filePath) {
    final String packageName = mActivityInstance.getApplicationContext().getPackageName();
    final Intent returnFileIntent = new Intent(packageName + ".ACTION_RETURN_FILE");
    if (fileAvailable == true) {
        Uri fileUri;
        try {
            fileUri = FileProvider.getUriForFile(mActivityInstance, packageName + ".qtandroidtoolsfileprovider", new File(filePath));
        } catch (IllegalArgumentException e) {
            Log.e(TAG, "The selected file can't be shared: " + filePath);
            return false;
        }
        returnFileIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        returnFileIntent.setDataAndType(fileUri, mimeType);
        mActivityInstance.setResult(Activity.RESULT_OK, returnFileIntent);
    } else {
        returnFileIntent.setDataAndType(null, "");
        mActivityInstance.setResult(Activity.RESULT_CANCELED, returnFileIntent);
    }
    return true;
}

13 Source : ListAppFragment.java
with GNU General Public License v3.0
from android-hacker

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    mRecyclerView = (DragSelectRecyclerView) view.findViewById(R.id.select_app_recycler_view);
    mProgressBar = (ProgressBar) view.findViewById(R.id.select_app_progress_bar);
    mInstallButton = (Button) view.findViewById(R.id.select_app_install_btn);
    mSelectFromExternal = view.findViewById(R.id.select_app_from_external);
    mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(1, OrientationHelper.VERTICAL));
    DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL);
    dividerItemDecoration.setDrawable(new ColorDrawable(0x1f000000));
    mRecyclerView.addItemDecoration(dividerItemDecoration);
    mAdapter = new CloneAppListAdapter(getActivity(), getSelectFrom());
    mRecyclerView.setAdapter(mAdapter);
    mAdapter.setOnItemClickListener(new CloneAppListAdapter.ItemEventListener() {

        @Override
        public void onItemClick(AppInfo info, int position) {
            if (!NativeLibraryHelperCompat.isApk64(info.path)) {
                Toast.makeText(getContext(), R.string.unsupported_for_32bit_app, Toast.LENGTH_SHORT).show();
                return;
            }
            int count = mAdapter.getSelectedCount();
            if (!mAdapter.isIndexSelected(position)) {
                if (count >= 9) {
                    Toast.makeText(getContext(), R.string.install_too_much_once_time, Toast.LENGTH_SHORT).show();
                    return;
                }
            }
            mAdapter.toggleSelected(position);
        }

        @Override
        public boolean isSelectable(int position) {
            return mAdapter.isIndexSelected(position) || mAdapter.getSelectedCount() < 9;
        }
    });
    mAdapter.setSelectionListener(count -> {
        mInstallButton.setEnabled(count > 0);
        mInstallButton.setText(String.format(Locale.ENGLISH, XApp.getApp().getResources().getString(R.string.install_d), count));
    });
    mInstallButton.setOnClickListener(v -> {
        Integer[] selectedIndices = mAdapter.getSelectedIndices();
        ArrayList<AppInfoLite> dataList = new ArrayList<AppInfoLite>(selectedIndices.length);
        for (int index : selectedIndices) {
            AppInfo info = mAdapter.gereplacedem(index);
            dataList.add(new AppInfoLite(info.packageName, info.path, info.fastOpen, info.disableMultiVersion));
        }
        if (dataList.size() > 0) {
            String path = dataList.get(0).path;
            chooseInstallWay(() -> {
                Activity activity = getActivity();
                if (activity == null) {
                    return;
                }
                Installd.startInstallerActivity(activity, dataList);
                activity.setResult(Activity.RESULT_OK);
            }, path);
        }
    });
    mSelectFromExternal.setOnClickListener(v -> {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        // apk file
        intent.setType("application/vnd.android.package-archive");
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        try {
            startActivityForResult(intent, REQUEST_GET_FILE);
        } catch (Throwable ignored) {
            Toast.makeText(getActivity(), "Error", Toast.LENGTH_SHORT).show();
        }
    });
    new ListAppPresenterImpl(getActivity(), this, getSelectFrom()).start();
}

13 Source : ScreenResultHelper.java
with MIT License
from aartikov

public void setActivityResult(@NonNull Activity activity, @NonNull ScreenResult screenResult) throws NavigationException {
    ActivityDestination activityDestination = getAndValidateActivityDestination(activity, screenResult);
    ActivityResult activityResult = activityDestination.createActivityResult(screenResult);
    activity.setResult(activityResult.getResultCode(), activityResult.getIntent());
}

See More Examples