Example usage for android.app Activity RESULT_CANCELED

List of usage examples for android.app Activity RESULT_CANCELED

Introduction

In this page you can find the example usage for android.app Activity RESULT_CANCELED.

Prototype

int RESULT_CANCELED

To view the source code for android.app Activity RESULT_CANCELED.

Click Source Link

Document

Standard activity result: operation canceled.

Usage

From source file:com.twofortyfouram.locale.sdk.host.ui.fragment.AbstractSupportPluginEditFragment.java

/**
 * Processes sub-activity results for plug-ins being edited {@inheritDoc}
 *//*  ww  w.  j av  a  2s.c o m*/
@Override
public final void onActivityResult(final int requestCode, final int resultCode, @Nullable final Intent intent) {

    if (REQUEST_CODE_EDIT_PLUGIN == requestCode) {
        switch (resultCode) {
        case Activity.RESULT_OK: {
            Lumberjack.always("Received result code RESULT_OK"); //$NON-NLS-1$

            final EnumSet<PluginErrorEdit> errors = PluginEditDelegate.isIntentValid(intent, mPlugin);
            if (errors.isEmpty()) {
                final Bundle newBundle = intent
                        .getBundleExtra(com.twofortyfouram.locale.api.Intent.EXTRA_BUNDLE);
                final String newBlurb = intent
                        .getStringExtra(com.twofortyfouram.locale.api.Intent.EXTRA_STRING_BLURB);

                Bundle previousBundle = null;
                String previousBlurb = null;
                if (null != mPreviousPluginInstanceData) {
                    try {
                        previousBundle = com.twofortyfouram.locale.sdk.host.internal.BundleSerializer
                                .deserializeFromByteArray(mPreviousPluginInstanceData.getSerializedBundle());
                    } catch (final ClassNotFoundException e) {
                        Lumberjack.e("Error deserializing previous bundle %s", //$NON-NLS-1$
                                e);
                    }
                    previousBlurb = mPreviousPluginInstanceData.getBlurb();
                }

                handleSaveInternal(newBundle, newBlurb, previousBundle, previousBlurb);
            } else {
                handleErrorsInternal(mPlugin, errors);
            }

            break;
        }
        case Activity.RESULT_CANCELED: {
            Lumberjack.always("Received result code RESULT_CANCELED"); //$NON-NLS-1$
            handleCancelInternal(mPlugin);
            break;
        }
        default: {
            Lumberjack.always("ERROR: Received illegal result code %d", //$NON-NLS-1$
                    resultCode);
            handleErrorsInternal(mPlugin, EnumSet.of(PluginErrorEdit.UNKNOWN_ACTIVITY_RESULT_CODE));
            /*
             * Although this shouldn't happen, don't throw an exception
             * because bad 3rd party apps could give bad result codes
             */

        }
        }
    } else {
        super.onActivityResult(requestCode, resultCode, intent);
    }
}

From source file:com.artemchep.horario.ui.fragments.AuthFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case REQUEST_CODE_SIGN_UP_EMAIL:
        break;//w w w  .ja  v a  2 s.c  o m
    case REQUEST_CODE_SIGN_IN_EMAIL:
        if (resultCode == Activity.RESULT_CANCELED) {
            mSignInView.clearPassword();
        }
        break;
    case REQUEST_CODE_SIGN_IN_GOOGLE: {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        if (result.isSuccess() && result.getSignInAccount() != null) {
            String token = result.getSignInAccount().getIdToken();
            Intent intent = new Intent(getActivity(), AuthSlaveActivity.class);
            intent.putExtra(AuthSlaveActivity.AUTH_TYPE, AuthSlaveActivity.AUTH_SIGN_IN_GOOGLE);
            intent.putExtra(AuthSlaveActivity.AUTH_TOKEN, token);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
        break;
    }
    default:
        mFacebookCallbackManager.onActivityResult(requestCode, resultCode, data);
    }
}

From source file:jen.jobs.application.UpdateJobSeeking.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_update_job_seeking);
    setTitle(getText(R.string.update_job_seeking));

    sharedPref = this.getSharedPreferences(MainActivity.JENJOBS_SHARED_PREFERENCE, Context.MODE_PRIVATE);
    profileId = sharedPref.getInt("js_profile_id", 0);
    isOnline = Jenjobs.isOnline(getApplicationContext());

    selectedMalaysiaState = (TextView) findViewById(R.id.selectedMalaysiaState);
    selectedCountry = (TextView) findViewById(R.id.selectedCountry);
    selectedJobSeekingStatus = (TextView) findViewById(R.id.selectedJobSeekingStatus);
    selectedJobNotice = (TextView) findViewById(R.id.selectedJobNotice);
    TextView licenseLabel = (TextView) findViewById(R.id.licenseLabel);
    TextView ownTransportLabel = (TextView) findViewById(R.id.ownTransportLabel);
    cbLicense = (CheckBox) findViewById(R.id.license);
    cbTransport = (CheckBox) findViewById(R.id.own_transport);

    LinearLayout selectJobSeekingStatus = (LinearLayout) findViewById(R.id.selectJobSeekingStatus);
    LinearLayout selectCountry = (LinearLayout) findViewById(R.id.selectCountry);
    selectMalaysiaState = (LinearLayout) findViewById(R.id.selectMalaysiaState);
    selectMalaysiaStateSibling = findViewById(R.id.selectMalaysiaStateSibling);
    LinearLayout selectJobNotice = (LinearLayout) findViewById(R.id.selectJobNotice);

    // TODO - read default values from db
    tableProfile = new TableProfile(getApplicationContext());
    tableAddress = new TableAddress(getApplicationContext());
    Profile profile = tableProfile.getProfile();

    Cursor c = tableAddress.getAddress();
    if (c.moveToFirst()) {
        int _country_id = c.getInt(8);
        String _country_name = c.getString(11);
        int _state_id = c.getInt(6);
        String _state_name = c.getString(7);

        //Log.e("country_id", ""+_country_id);
        //Log.e("country_name", _country_name);

        if (_country_id > 0 && _country_name.length() > 0) {
            selectedCountry.setText(_country_name);
            selectedCountryValues = new Country(_country_id, _country_name);
        }/*from w ww .j  av  a2  s . c o m*/

        if (_state_id > 0 && _state_name.length() > 0) {
            selectedMalaysiaStateValues = new State(_state_id, _state_name);
            selectedMalaysiaState.setText(_state_name);
        }
    }
    c.close();

    if (profile.js_jobseek_status_id > 0) {
        HashMap jobseekStatus = Jenjobs.getJobSeekingStatus();
        String _jssValue = (String) jobseekStatus.get(profile.js_jobseek_status_id);
        selectedJobSeekingStatusValues = new JobSeekingStatus(profile.js_jobseek_status_id, _jssValue);
        selectedJobSeekingStatus.setText(_jssValue);
    }

    if (profile.availability > 0 && profile.availability_unit.length() > 0) {
        selectedAvailability = String.valueOf(profile.availability);

        String[] _av = getResources().getStringArray(R.array.availability_unit);
        for (String a_av : _av) {
            if (a_av.substring(0, 1).equals(profile.availability_unit)) {
                selectedAvailabilityUnit = a_av;
            }
        }

        String a = selectedAvailability + " " + selectedAvailabilityUnit;
        selectedJobNotice.setText(a);
    }

    if (profile.driving_license) {
        cbLicense.setChecked(true);
    }

    if (profile.transport) {
        cbTransport.setChecked(true);
    }

    licenseLabel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            cbLicense.setChecked(!cbLicense.isChecked());
        }
    });

    ownTransportLabel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            cbTransport.setChecked(!cbTransport.isChecked());
        }
    });

    selectJobSeekingStatus.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), SelectJobSeekingStatus.class);
            if (selectedJobSeekingStatusValues != null) {
                intent.putExtra("jobseekingstatus", selectedJobSeekingStatusValues);
            }
            startActivityForResult(intent, SELECT_JOB_SEEKING_STATUS);
        }
    });

    selectCountry.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), SelectCountry.class);
            intent.putExtra("single", true);
            startActivityForResult(intent, SELECT_COUNTRY);
        }
    });

    selectMalaysiaState.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), SelectState.class);
            intent.putExtra("single", true);
            startActivityForResult(intent, SELECT_STATE);
        }
    });

    selectJobNotice.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), UpdateNoticePeriod.class);
            // TODO - set saved period
            startActivityForResult(intent, SELECT_JOB_NOTICE);
        }
    });

    Button update = (Button) findViewById(R.id.save_jobseeking_information);
    update.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });

    Button cancelButton = (Button) findViewById(R.id.cancel);
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setResult(Activity.RESULT_CANCELED);
            finish();
        }
    });
}

From source file:com.tomeokin.lspush.ui.widget.dialog.BaseDialogFragment.java

@Override
public void onClick(DialogInterface dialog, int which) {
    if (hasActionClickListener) {
        OnActionClickListener listener = getDialogListener(OnActionClickListener.class);
        if (listener != null) {
            listener.onDialogActionClick(dialog, requestCode, which);
        } else {/*w  w  w .  ja v a2  s  . c om*/
            Intent data = new Intent();
            data.putExtra(BaseDialogBuilder.EXTRA_ACTION_TYPE, which);
            int resultCode = which == DialogInterface.BUTTON_NEGATIVE ? Activity.RESULT_CANCELED
                    : Activity.RESULT_OK;
            setResult(requestCode, resultCode, data);
        }
    }
}

From source file:de.schildbach.wallet.ui.ChannelRequestActivity.java

@Override
public void onBackPressed() {
    disconnectAndFinish(Activity.RESULT_CANCELED);
}

From source file:com.soomla.store.billing.google.GoogleIabHelper.java

/**
 * Handles an activity result that's part of the purchase flow in in-app billing. If you
 * are calling {@link #launchPurchaseFlow}, then you must call this method from your
 * Activity's {@link android.app.Activity@onActivityResult} method. This method
 * MUST be called from the UI thread of the Activity.
 *
 * @param requestCode The requestCode as you received it.
 * @param resultCode The resultCode as you received it.
 * @param data The data (Intent) as you received it.
 * @return Returns true if the result was related to a purchase flow and was handled;
 *     false if the result was not related to a purchase, in which case you should
 *     handle it normally./*  www .j  a v a 2s .  c  o  m*/
 */
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
    IabResult result;
    if (requestCode != RC_REQUEST)
        return false;

    checkSetupDoneAndThrow("handleActivityResult");

    // cancellation moved here b/c there can be a cancellation with null data
    if (resultCode == Activity.RESULT_CANCELED) {
        SoomlaUtils.LogDebug(TAG, "IabPurchase canceled.");
        try {
            IabPurchase purchase = new IabPurchase(mPurchasingItemType,
                    "{\"productId\":" + mPurchasingItemSku + "}", null);
            result = new IabResult(IabResult.BILLING_RESPONSE_RESULT_USER_CANCELED, "User canceled.");
            purchaseFailed(result, purchase);
            return true;
        } catch (JSONException e) {
            SoomlaUtils.LogError(TAG, "Failed to generate canceled purchase.");
            e.printStackTrace();
            result = new IabResult(IabResult.IABHELPER_BAD_RESPONSE, "Failed to generate canceled purchase.");
            purchaseFailed(result, null);
            return true;
        }
    }

    if (data == null) {
        SoomlaUtils.LogError(TAG, "Null data in IAB activity result.");
        result = new IabResult(IabResult.IABHELPER_BAD_RESPONSE, "Null data in IAB result");
        purchaseFailed(result, null);
        return true;
    }

    int responseCode = getResponseCodeFromIntent(data);
    String purchaseData = data.getStringExtra(RESPONSE_INAPP_PURCHASE_DATA);
    String dataSignature = data.getStringExtra(RESPONSE_INAPP_SIGNATURE);

    if (resultCode == Activity.RESULT_OK && responseCode == IabResult.BILLING_RESPONSE_RESULT_OK) {
        SoomlaUtils.LogDebug(TAG, "Successful resultcode from purchase activity.");
        SoomlaUtils.LogDebug(TAG, "IabPurchase data: " + purchaseData);
        SoomlaUtils.LogDebug(TAG, "Data signature: " + dataSignature);
        SoomlaUtils.LogDebug(TAG, "Extras: " + data.getExtras());
        SoomlaUtils.LogDebug(TAG, "Expected item type: " + mPurchasingItemType);

        if (purchaseData == null || dataSignature == null) {
            SoomlaUtils.LogError(TAG, "BUG: either purchaseData or dataSignature is null.");
            SoomlaUtils.LogDebug(TAG, "Extras: " + data.getExtras().toString());
            result = new IabResult(IabResult.IABHELPER_UNKNOWN_ERROR,
                    "IAB returned null purchaseData or dataSignature");
            purchaseFailed(result, null);
            return true;
        }

        IabPurchase purchase = null;
        try {
            purchase = new IabPurchase(mPurchasingItemType, purchaseData, dataSignature);
            String sku = purchase.getSku();

            SharedPreferences prefs = SoomlaApp.getAppContext().getSharedPreferences(SoomlaConfig.PREFS_NAME,
                    Context.MODE_PRIVATE);
            String publicKey = prefs.getString(GooglePlayIabService.PUBLICKEY_KEY, "");

            // Verify signature
            if (!Security.verifyPurchase(publicKey, purchaseData, dataSignature)) {
                SoomlaUtils.LogError(TAG, "IabPurchase signature verification FAILED for sku " + sku);
                result = new IabResult(IabResult.IABHELPER_VERIFICATION_FAILED,
                        "Signature verification failed for sku " + sku);
                purchaseFailed(result, purchase);
                return true;
            }
            SoomlaUtils.LogDebug(TAG, "IabPurchase signature successfully verified.");
        } catch (JSONException e) {
            SoomlaUtils.LogError(TAG, "Failed to parse purchase data.");
            e.printStackTrace();
            result = new IabResult(IabResult.IABHELPER_BAD_RESPONSE, "Failed to parse purchase data.");
            purchaseFailed(result, null);
            return true;
        }

        purchaseSucceeded(purchase);
    } else if (resultCode == Activity.RESULT_OK) {
        // result code was OK, but in-app billing response was not OK.
        SoomlaUtils.LogDebug(TAG, "Result code was OK but in-app billing response was not OK: "
                + IabResult.getResponseDesc(responseCode));
        result = new IabResult(responseCode, "Problem purchashing item.");
        purchaseFailed(result, null);
    } else {
        SoomlaUtils.LogError(TAG, "IabPurchase failed. Result code: " + Integer.toString(resultCode)
                + ". Response: " + IabResult.getResponseDesc(responseCode));
        result = new IabResult(IabResult.IABHELPER_UNKNOWN_PURCHASE_RESPONSE, "Unknown purchase response.");
        purchaseFailed(result, null);
    }
    return true;
}

From source file:com.soomla.store.billing.tapclash.TapClashIabHelper.java

/**
 * Handles an activity result that's part of the purchase flow in in-app billing. If you
 * are calling {@link #launchPurchaseFlow}, then you must call this method from your
 * Activity's {@link android.app.Activity@onActivityResult} method. This method
 * MUST be called from the UI thread of the Activity.
 *
 * @param requestCode The requestCode as you received it.
 * @param resultCode The resultCode as you received it.
 * @param data The data (Intent) as you received it.
 * @return Returns true if the result was related to a purchase flow and was handled;
 *     false if the result was not related to a purchase, in which case you should
 *     handle it normally./*from   www .j a v a 2  s  . c  o m*/
 */
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
    IabResult result;
    if (requestCode != RC_REQUEST)
        return false;

    checkSetupDoneAndThrow("handleActivityResult");

    // cancellation moved here b/c there can be a cancellation with null data
    if (resultCode == Activity.RESULT_CANCELED) {
        SoomlaUtils.LogDebug(TAG, "IabPurchase canceled.");
        try {
            IabPurchase purchase = new IabPurchase(mPurchasingItemType,
                    "{\"productId\":" + mPurchasingItemSku + "}", null);
            result = new IabResult(IabResult.BILLING_RESPONSE_RESULT_USER_CANCELED, "User canceled.");
            purchaseFailed(result, purchase);
            return true;
        } catch (JSONException e) {
            SoomlaUtils.LogError(TAG, "Failed to generate canceled purchase.");
            e.printStackTrace();
            result = new IabResult(IabResult.IABHELPER_BAD_RESPONSE, "Failed to generate canceled purchase.");
            purchaseFailed(result, null);
            return true;
        }
    }

    if (data == null) {
        SoomlaUtils.LogError(TAG, "Null data in IAB activity result.");
        result = new IabResult(IabResult.IABHELPER_BAD_RESPONSE, "Null data in IAB result");
        purchaseFailed(result, null);
        return true;
    }

    int responseCode = getResponseCodeFromIntent(data);
    String purchaseData = data.getStringExtra(RESPONSE_INAPP_PURCHASE_DATA);
    String dataSignature = data.getStringExtra(RESPONSE_INAPP_SIGNATURE);

    if (resultCode == Activity.RESULT_OK && responseCode == IabResult.BILLING_RESPONSE_RESULT_OK) {
        SoomlaUtils.LogDebug(TAG, "Successful resultcode from purchase activity.");
        SoomlaUtils.LogDebug(TAG, "IabPurchase data: " + purchaseData);
        SoomlaUtils.LogDebug(TAG, "Data signature: " + dataSignature);
        SoomlaUtils.LogDebug(TAG, "Extras: " + data.getExtras());
        SoomlaUtils.LogDebug(TAG, "Expected item type: " + mPurchasingItemType);

        if (purchaseData == null || dataSignature == null) {
            SoomlaUtils.LogError(TAG, "BUG: either purchaseData or dataSignature is null.");
            SoomlaUtils.LogDebug(TAG, "Extras: " + data.getExtras().toString());
            result = new IabResult(IabResult.IABHELPER_UNKNOWN_ERROR,
                    "IAB returned null purchaseData or dataSignature");
            purchaseFailed(result, null);
            return true;
        }

        IabPurchase purchase = null;
        try {
            purchase = new IabPurchase(mPurchasingItemType, purchaseData, dataSignature);
            String sku = purchase.getSku();

            SharedPreferences prefs = SoomlaApp.getAppContext().getSharedPreferences(SoomlaConfig.PREFS_NAME,
                    Context.MODE_PRIVATE);
            String publicKey = prefs.getString(TapClashIabService.PUBLICKEY_KEY, "");

            // Verify signature
            if (!Security.verifyPurchase(publicKey, purchaseData, dataSignature)) {
                SoomlaUtils.LogError(TAG, "IabPurchase signature verification FAILED for sku " + sku);
                result = new IabResult(IabResult.IABHELPER_VERIFICATION_FAILED,
                        "Signature verification failed for sku " + sku);
                purchaseFailed(result, purchase);
                return true;
            }
            SoomlaUtils.LogDebug(TAG, "IabPurchase signature successfully verified.");
        } catch (JSONException e) {
            SoomlaUtils.LogError(TAG, "Failed to parse purchase data.");
            e.printStackTrace();
            result = new IabResult(IabResult.IABHELPER_BAD_RESPONSE, "Failed to parse purchase data.");
            purchaseFailed(result, null);
            return true;
        }

        purchaseSucceeded(purchase);
    } else if (resultCode == Activity.RESULT_OK) {
        // result code was OK, but in-app billing response was not OK.
        SoomlaUtils.LogDebug(TAG, "Result code was OK but in-app billing response was not OK: "
                + IabResult.getResponseDesc(responseCode));
        result = new IabResult(responseCode, "Problem purchashing item.");
        purchaseFailed(result, null);
    } else {
        SoomlaUtils.LogError(TAG, "IabPurchase failed. Result code: " + Integer.toString(resultCode)
                + ". Response: " + IabResult.getResponseDesc(responseCode));
        result = new IabResult(IabResult.IABHELPER_UNKNOWN_PURCHASE_RESPONSE, "Unknown purchase response.");
        purchaseFailed(result, null);
    }
    return true;
}

From source file:com.jtechme.apphub.privileged.install.InstallExtensionDialogActivity.java

/**
 * first time/*from   w  w w.j  av  a2s  . c  o m*/
 */
private void firstTime() {
    // hack to get theme applied (which is not automatically applied due to activity's Theme.NoDisplay
    ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId());

    String message = getString(R.string.system_install_first_time_message) + "<br/><br/>"
            + getString(R.string.system_install_question);

    AlertDialog.Builder builder = new AlertDialog.Builder(theme).setMessage(Html.fromHtml(message))
            .setPositiveButton(R.string.system_install_button_open, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    // Open details of F-Droid Privileged
                    Intent intent = new Intent(InstallExtensionDialogActivity.this, AppDetails.class);
                    intent.putExtra(AppDetails.EXTRA_APPID,
                            PrivilegedInstaller.PRIVILEGED_EXTENSION_PACKAGE_NAME);
                    startActivity(intent);
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    InstallExtensionDialogActivity.this.setResult(Activity.RESULT_CANCELED);
                    InstallExtensionDialogActivity.this.finish();
                }
            });
    builder.create().show();
}

From source file:org.gluu.super_gluu.app.fragment.HomeFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
    case IntentIntegrator.REQUEST_CODE:
        if (resultCode == Activity.RESULT_OK) {
            // Parsing bar code reader result
            IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
            if (BuildConfig.DEBUG)
                Log.d(TAG, "Parsing QR code result: " + result.toString());
            OxPush2Request oxPush2Request;
            try {
                oxPush2Request = new Gson().fromJson(result.getContents(), OxPush2Request.class);
            } catch (Exception ex) {
                oxPush2Request = null;
            }/*from   w w w.j  a  va 2 s.  c  om*/
            onQrRequest(oxPush2Request);
        }
        if (resultCode == Activity.RESULT_CANCELED) {
            showToastWithText(context.getString(R.string.canceled_process_qr_code));
        }
        break;
    }
}

From source file:com.dm.material.dashboard.candybar.helpers.IconsHelper.java

public static void selectIcon(@NonNull Context context, int action, Icon icon) {
    if (action == IntentHelper.ICON_PICKER) {
        Intent intent = new Intent();
        Bitmap bitmap = ImageLoader.getInstance().loadImageSync("drawable://" + icon.getRes(),
                ImageConfig.getRawImageOptions().build());

        intent.putExtra("icon", bitmap);
        ((AppCompatActivity) context).setResult(bitmap != null ? Activity.RESULT_OK : Activity.RESULT_CANCELED,
                intent);/*  w  w w. j  a va  2 s. c  o  m*/
        ((AppCompatActivity) context).finish();
    } else if (action == IntentHelper.IMAGE_PICKER) {
        Intent intent = new Intent();
        Bitmap bitmap = ImageLoader.getInstance().loadImageSync("drawable://" + icon.getRes(),
                ImageConfig.getRawImageOptions().build());
        if (bitmap != null) {
            File file = new File(context.getCacheDir(), icon.getTitle() + ".png");
            FileOutputStream outStream;
            try {
                outStream = new FileOutputStream(file);
                bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
                outStream.flush();
                outStream.close();

                Uri uri = FileHelper.getUriFromFile(context, context.getPackageName(), file);
                if (uri == null)
                    uri = Uri.fromFile(file);
                intent.putExtra(Intent.EXTRA_STREAM, uri);
                intent.setData(uri);
                intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            } catch (Exception | OutOfMemoryError e) {
                LogUtil.e(Log.getStackTraceString(e));
            }
            intent.putExtra("return-data", false);
        }
        ((AppCompatActivity) context).setResult(bitmap != null ? Activity.RESULT_OK : Activity.RESULT_CANCELED,
                intent);
        ((AppCompatActivity) context).finish();
    } else {
        IconPreviewFragment.showIconPreview(((AppCompatActivity) context).getSupportFragmentManager(),
                icon.getTitle(), icon.getRes());
    }
}