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.enstage.wibmo.sdk.inapp.InAppInitActivity.java

private void sendAbort(String resCode, String resDesc) {
    Intent resultData = new Intent();
    resultData.putExtra(InAppUtil.EXTRA_KEY_RES_CODE, resCode);
    resultData.putExtra(InAppUtil.EXTRA_KEY_RES_DESC, resDesc);
    if (w2faInitResponse != null) {
        resultData.putExtra(InAppUtil.EXTRA_KEY_WIBMO_TXN_ID, w2faInitResponse.getWibmoTxnId());
        if (w2faInitResponse.getTransactionInfo() != null) {
            resultData.putExtra(InAppUtil.EXTRA_KEY_MER_TXN_ID,
                    w2faInitResponse.getTransactionInfo().getMerTxnId());
            resultData.putExtra(InAppUtil.EXTRA_KEY_MER_APP_DATA,
                    w2faInitResponse.getTransactionInfo().getMerAppData());
        }/* w  ww.  j a  v  a 2s . c  o m*/
    } else if (wPayInitResponse != null) {
        resultData.putExtra(InAppUtil.EXTRA_KEY_WIBMO_TXN_ID, wPayInitResponse.getWibmoTxnId());
        if (wPayInitResponse.getTransactionInfo() != null) {
            resultData.putExtra(InAppUtil.EXTRA_KEY_MER_TXN_ID,
                    wPayInitResponse.getTransactionInfo().getMerTxnId());
            resultData.putExtra(InAppUtil.EXTRA_KEY_MER_APP_DATA,
                    wPayInitResponse.getTransactionInfo().getMerAppData());
        }
    }
    setResult(Activity.RESULT_CANCELED, resultData);
    finish();
}

From source file:com.example.user.wase.view.fragment.EquipmentScanner.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    // User chose not to enable Bluetooth.
    if (requestCode == REQUEST_ENABLE_BT && resultCode == Activity.RESULT_CANCELED) {
        getActivity().finish();//from w w w. j  a va2s . co m
        return;
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:org.onepf.oms.appstore.SamsungAppsBillingService.java

@Override
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == options.samsungCertificationRequestCode) {
        if (resultCode == Activity.RESULT_OK) {
            bindIapService();// ww w . java 2  s . c om
        } else if (resultCode == Activity.RESULT_CANCELED) {
            setupListener.onIabSetupFinished(new IabResult(IabHelper.BILLING_RESPONSE_RESULT_USER_CANCELED,
                    "Account certification canceled"));
        } else {
            setupListener.onIabSetupFinished(new IabResult(IabHelper.BILLING_RESPONSE_RESULT_ERROR,
                    "Unknown error. Result code: " + resultCode));
        }
        return true;
    }
    if (requestCode != mRequestCode) {
        return false;
    }
    int errorCode = IabHelper.BILLING_RESPONSE_RESULT_ERROR;
    String errorMsg = "Unknown error";
    Purchase purchase = new Purchase(OpenIabHelper.NAME_SAMSUNG);
    if (data != null) {
        Bundle extras = data.getExtras();
        if (extras != null) {
            int statusCode = extras.getInt(KEY_NAME_STATUS_CODE);
            errorMsg = extras.getString(KEY_NAME_ERROR_STRING);
            String itemId = extras.getString(KEY_NAME_ITEM_ID);
            switch (resultCode) {
            case Activity.RESULT_OK:
                switch (statusCode) {
                case IAP_ERROR_NONE:
                    errorCode = IabHelper.BILLING_RESPONSE_RESULT_OK;
                    break;
                case IAP_ERROR_ALREADY_PURCHASED:
                    errorCode = IabHelper.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED;
                    break;
                case IAP_ERROR_PRODUCT_DOES_NOT_EXIST:
                    errorCode = IabHelper.BILLING_RESPONSE_RESULT_ITEM_UNAVAILABLE;
                    break;
                }
                break;
            case Activity.RESULT_CANCELED:
                errorCode = IabHelper.BILLING_RESPONSE_RESULT_USER_CANCELED;
                break;
            }
            String purchaseData = extras.getString(KEY_NAME_RESULT_OBJECT);
            try {
                JSONObject purchaseJson = new JSONObject(purchaseData);

                purchase.setOriginalJson(purchaseData);
                purchase.setOrderId(purchaseJson.getString(JSON_KEY_PAYMENT_ID));
                purchase.setPurchaseTime(Long.parseLong(purchaseJson.getString(JSON_KEY_PURCHASE_DATE)));
                purchase.setToken(purchaseJson.getString(JSON_KEY_PURCHASE_ID));
            } catch (JSONException e) {
                Log.e(TAG, "JSON parse error: " + e.getMessage());
            }

            purchase.setItemType(purchasingItemType);
            purchase.setSku(OpenIabHelper.getSku(OpenIabHelper.NAME_SAMSUNG, mItemGroupId + '/' + itemId));
            purchase.setPackageName(activity.getPackageName());
            purchase.setPurchaseState(0);
            purchase.setDeveloperPayload(mExtraData);
        }
    }
    if (isDebugLog())
        Log.d(TAG, "Samsung result code: " + errorCode + ", msg: " + errorMsg);
    mPurchaseListener.onIabPurchaseFinished(new IabResult(errorCode, errorMsg), purchase);
    return true;
}

From source file:de.eidottermihi.rpicheck.activity.NewRaspiAuthActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == REQUEST_LOAD) {
            final String filePath = data.getStringExtra(FileDialog.RESULT_PATH);
            LOGGER.debug("Path of selected keyfile: {}", filePath);
            this.keyfilePath = filePath;
            // set text to filename, not full path
            String fileName = getFilenameFromPath(filePath);
            buttonKeyfile.setText(fileName);
            buttonKeyfile.setError(null);
        }/* w  w w.ja  v  a2s  .  c  o  m*/
    } else if (resultCode == Activity.RESULT_CANCELED) {
        LOGGER.warn("No keyfile selected...");
    }
}

From source file:com.enstage.wibmo.sdk.inapp.InAppInitActivity.java

private void sendFailure(String resCode, String resDesc) {
    Intent resultData = new Intent();
    resultData.putExtra(InAppUtil.EXTRA_KEY_RES_CODE, resCode);
    resultData.putExtra(InAppUtil.EXTRA_KEY_RES_DESC, "sdk init - " + resDesc);

    setResult(Activity.RESULT_CANCELED, resultData);
    finish();//  w ww.j  a v a 2  s. c  o m
}

From source file:net.reichholf.dreamdroid.fragment.TimerEditFragment.java

/**
 * @param id/*from   w ww  .j a v  a 2s .  co  m*/
 */
protected boolean onItemSelected(int id) {
    Bundle args;
    boolean consumed = false;
    Calendar calendar = null;
    switch (id) {
    case Statics.ITEM_SAVE:
        saveTimer();
        consumed = true;
        break;

    case Statics.ITEM_CANCEL:
        finish(Activity.RESULT_CANCELED);
        consumed = true;
        break;

    case Statics.ITEM_PICK_SERVICE:
        pickService();
        consumed = true;
        break;

    case Statics.ITEM_PICK_BEGIN_DATE:
        calendar = getCalendar(mBegin);
        DatePickerDialog datePickerDialogBegin = DatePickerDialog
                .newInstance(new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePickerDialog datePickerDialog, int year, int month, int day) {
                        TimerEditFragment.this.onDateSet(true, year, month, day);
                    }
                }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
                        calendar.get(Calendar.DAY_OF_MONTH), true);
        getMultiPaneHandler().showDialogFragment(datePickerDialogBegin, "dialog_pick_begin_date");
        consumed = true;
        break;

    case Statics.ITEM_PICK_BEGIN_TIME:
        calendar = getCalendar(mBegin);
        TimePickerDialog timePickerDialogBegin = TimePickerDialog
                .newInstance(new TimePickerDialog.OnTimeSetListener() {
                    @Override
                    public void onTimeSet(RadialPickerLayout radialPickerLayout, int hour, int minute) {
                        TimerEditFragment.this.onTimeSet(true, hour, minute);
                    }
                }, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), true, true);
        getMultiPaneHandler().showDialogFragment(timePickerDialogBegin, "dialog_pick_begin_time");
        consumed = true;
        break;

    case Statics.ITEM_PICK_END_DATE:
        calendar = getCalendar(mEnd);
        DatePickerDialog datePickerDialogEnd = DatePickerDialog
                .newInstance(new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePickerDialog datePickerDialog, int year, int month, int day) {
                        TimerEditFragment.this.onDateSet(false, year, month, day);
                    }
                }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
                        calendar.get(Calendar.DAY_OF_MONTH), true);
        getMultiPaneHandler().showDialogFragment(datePickerDialogEnd, "dialog_pick_end_date");
        consumed = true;
        break;

    case Statics.ITEM_PICK_END_TIME:
        calendar = getCalendar(mEnd);
        TimePickerDialog timePickerDialogEnd = TimePickerDialog
                .newInstance(new TimePickerDialog.OnTimeSetListener() {
                    @Override
                    public void onTimeSet(RadialPickerLayout radialPickerLayout, int hour, int minute) {
                        TimerEditFragment.this.onTimeSet(false, hour, minute);
                    }
                }, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), true, true);
        getMultiPaneHandler().showDialogFragment(timePickerDialogEnd, "dialog_pick_end_time");
        consumed = true;
        break;

    case Statics.ITEM_PICK_REPEATED:
        pickRepeatings();
        consumed = true;
        break;

    case Statics.ITEM_PICK_TAGS:
        pickTags();
        consumed = true;
        break;

    default:
        consumed = super.onItemSelected(id);
        break;
    }

    return consumed;
}

From source file:org.opendatakit.survey.activities.MediaCaptureImageActivity.java

protected void returnResult() {
    File sourceMedia = (uriFragmentToMedia != null)
            ? ODKFileUtils.getRowpathFile(appName, tableId, instanceId, uriFragmentToMedia)
            : null;//w  ww . j  a va  2 s . c  o  m
    if (sourceMedia != null && sourceMedia.exists()) {
        Intent i = new Intent();
        i.putExtra(IntentConsts.INTENT_KEY_URI_FRAGMENT,
                ODKFileUtils.asRowpathUri(appName, tableId, instanceId, sourceMedia));
        String name = sourceMedia.getName();
        i.putExtra(IntentConsts.INTENT_KEY_CONTENT_TYPE,
                MEDIA_CLASS + name.substring(name.lastIndexOf(".") + 1));
        setResult(Activity.RESULT_OK, i);
        finish();
    } else {
        WebLogger.getLogger(appName).e(t, ERROR_NO_FILE
                + ((uriFragmentToMedia != null) ? sourceMedia.getAbsolutePath() : "null mediaPath"));
        Toast.makeText(this, R.string.media_save_failed, Toast.LENGTH_SHORT).show();
        setResult(Activity.RESULT_CANCELED);
        finish();
    }
}

From source file:com.prgpascal.qrdatatransfer.TransferActivity.java

/**
 * Method called when an irreversible error occured:
 * - The Client can't connect to the Server via Wifi Direct.
 * - The Server receives a wrong ACK from the Client.
 * - Server or Client disconnected before the transmission ended.
 *
 * This method will not stop the ServerReceiver neither will disconnect Wifi Direct,
 * because that will be done in onStop() method.
 *///from w w  w . jav a  2s  . c  o m
public void finishTransmissionWithError() {
    // Return to the calling Activity
    Intent returnIntent = new Intent();
    setResult(Activity.RESULT_CANCELED, returnIntent);
    finish();
}

From source file:org.fdroid.fdroid.installer.InstallIntoSystemDialogActivity.java

private void uninstall() {
    // hack to get holo design (which is not automatically applied due to activity's Theme.NoDisplay
    ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId());

    final boolean systemApp = Installer.hasSystemPermissions(this, this.getPackageManager());

    if (systemApp) {
        AlertDialog.Builder builder = new AlertDialog.Builder(theme).setTitle(R.string.system_uninstall)
                .setMessage(R.string.system_uninstall_message)
                .setPositiveButton(R.string.system_uninstall_button, new DialogInterface.OnClickListener() {
                    @Override//from w w w.  java2s .  c  om
                    public void onClick(DialogInterface dialogInterface, int i) {
                        checkRootTask.execute();
                    }
                }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        InstallIntoSystemDialogActivity.this.setResult(Activity.RESULT_CANCELED);
                        InstallIntoSystemDialogActivity.this.finish();
                    }
                });
        builder.create().show();
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(theme)
                .setTitle(R.string.system_permission_denied_title)
                .setMessage(getString(R.string.system_permission_denied_body))
                .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        InstallIntoSystemDialogActivity.this.setResult(Activity.RESULT_CANCELED);
                        InstallIntoSystemDialogActivity.this.finish();
                    }
                });
        builder.create().show();
    }
}

From source file:com.phonegap.Capture.java

/**
 * Called when the video view exits. // ww  w .  ja v a  2s.c  om
 * 
 * @param requestCode       The request code originally supplied to startActivityForResult(), 
 *                          allowing you to identify who this result came from.
 * @param resultCode        The integer result code returned by the child activity through its setResult().
 * @param intent            An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
 * @throws JSONException 
 */
public void onActivityResult(int requestCode, int resultCode, Intent intent) {

    // Result received okay
    if (resultCode == Activity.RESULT_OK) {
        // An audio clip was requested
        if (requestCode == CAPTURE_AUDIO) {
            // Get the uri of the audio clip
            Uri data = intent.getData();
            // create a file object from the uri
            results.put(createMediaFile(data));

            if (results.length() >= limit) {
                // Send Uri back to JavaScript for listening to audio
                this.success(new PluginResult(PluginResult.Status.OK, results,
                        "navigator.device.capture._castMediaFile"), this.callbackId);
            } else {
                // still need to capture more audio clips
                captureAudio();
            }
        } else if (requestCode == CAPTURE_IMAGE) {
            // For some reason if I try to do:
            // Uri data = intent.getData();
            // It crashes in the emulator and on my phone with a null pointer exception
            // To work around it I had to grab the code from CameraLauncher.java
            try {
                // Create an ExifHelper to save the exif data that is lost during compression
                ExifHelper exif = new ExifHelper();
                exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx) + "/Capture.jpg");
                exif.readExifData();

                // Read in bitmap of captured image
                Bitmap bitmap = android.provider.MediaStore.Images.Media
                        .getBitmap(this.ctx.getContentResolver(), imageUri);

                // Create entry in media store for image
                // (Don't use insertImage() because it uses default compression setting of 50 - no way to change it)
                ContentValues values = new ContentValues();
                values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, IMAGE_JPEG);
                Uri uri = null;
                try {
                    uri = this.ctx.getContentResolver()
                            .insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
                } catch (UnsupportedOperationException e) {
                    LOG.d(LOG_TAG, "Can't write to external media storage.");
                    try {
                        uri = this.ctx.getContentResolver()
                                .insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
                    } catch (UnsupportedOperationException ex) {
                        LOG.d(LOG_TAG, "Can't write to internal media storage.");
                        this.fail(createErrorObject(CAPTURE_INTERNAL_ERR,
                                "Error capturing image - no media storage found."));
                        return;
                    }
                }

                // Add compressed version of captured image to returned media store Uri
                OutputStream os = this.ctx.getContentResolver().openOutputStream(uri);
                bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);
                os.close();

                bitmap.recycle();
                bitmap = null;
                System.gc();

                // Restore exif data to file
                exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.ctx));
                exif.writeExifData();

                // Add image to results
                results.put(createMediaFile(uri));

                if (results.length() >= limit) {
                    // Send Uri back to JavaScript for viewing image
                    this.success(new PluginResult(PluginResult.Status.OK, results,
                            "navigator.device.capture._castMediaFile"), this.callbackId);
                } else {
                    // still need to capture more images
                    captureImage();
                }
            } catch (IOException e) {
                e.printStackTrace();
                this.fail(createErrorObject(CAPTURE_INTERNAL_ERR, "Error capturing image."));
            }
        } else if (requestCode == CAPTURE_VIDEO) {
            // Get the uri of the video clip
            Uri data = intent.getData();
            // create a file object from the uri
            results.put(createMediaFile(data));

            if (results.length() >= limit) {
                // Send Uri back to JavaScript for viewing video
                this.success(new PluginResult(PluginResult.Status.OK, results,
                        "navigator.device.capture._castMediaFile"), this.callbackId);
            } else {
                // still need to capture more video clips
                captureVideo(duration);
            }
        }
    }
    // If canceled
    else if (resultCode == Activity.RESULT_CANCELED) {
        // If we have partial results send them back to the user
        if (results.length() > 0) {
            this.success(new PluginResult(PluginResult.Status.OK, results,
                    "navigator.device.capture._castMediaFile"), this.callbackId);
        }
        // user canceled the action
        else {
            this.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Canceled."));
        }
    }
    // If something else
    else {
        // If we have partial results send them back to the user
        if (results.length() > 0) {
            this.success(new PluginResult(PluginResult.Status.OK, results,
                    "navigator.device.capture._castMediaFile"), this.callbackId);
        }
        // something bad happened
        else {
            this.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Did not complete!"));
        }
    }
}