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:org.deviceconnect.android.deviceplugin.host.camera.CameraOverlay.java

/**
 * ??????.//from   w w  w .  jav a  2 s.  c o  m
 * @param resultReceiver ????
 */
@TargetApi(23)
private void checkOverlayDrawingCapability(@NonNull final ResultReceiver resultReceiver) {
    if (Settings.canDrawOverlays(mContext)) {
        resultReceiver.send(Activity.RESULT_OK, null);
    } else {
        Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                Uri.parse("package:" + mContext.getPackageName()));
        IntentHandlerActivity.startActivityForResult(mContext, intent, new ResultReceiver(mHandler) {
            @Override
            protected void onReceiveResult(int resultCode, Bundle resultData) {
                if (Settings.canDrawOverlays(mContext)) {
                    resultReceiver.send(Activity.RESULT_OK, null);
                } else {
                    resultReceiver.send(Activity.RESULT_CANCELED, null);
                }
            }
        });
    }
}

From source file:com.android.managedprovisioning.ProfileOwnerPreProvisioningActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ENCRYPT_DEVICE_REQUEST_CODE) {
        if (resultCode == RESULT_CANCELED) {
            ProvisionLogger.loge("User canceled device encryption.");
            setResult(Activity.RESULT_CANCELED);
            finish();//from ww w  .  java2 s .  co  m
        }
    } else if (requestCode == CHANGE_LAUNCHER_REQUEST_CODE) {
        if (resultCode == RESULT_CANCELED) {
            showCurrentLauncherInvalid();
        } else if (resultCode == RESULT_OK) {
            startProfileOwnerProvisioning();
        }
    }
    if (requestCode == PROVISIONING_REQUEST_CODE) {
        setResult(resultCode);
        finish();
    }
}

From source file:com.flurry.samples.analytics.PhotoFeedActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case REQUEST_CHECK_SETTINGS:
        switch (resultCode) {
        case Activity.RESULT_OK:
            if (googleApiClient != null && !googleApiClient.isConnected()) {
                googleApiClient.connect();
            }//www  . j  a  v  a  2s  . co  m
            startLocationUpdates();
            break;

        case Activity.RESULT_CANCELED:
            Toast.makeText(getApplicationContext(),
                    "Location services not enabled. To use this app, enable location services.",
                    Toast.LENGTH_LONG).show();
            finish();
            break;

        default:
            break;
        }
        break;
    }
}

From source file:biz.incomsystems.fwknop2.ConfigDetailFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { // This handles the qrcode results
    if (requestCode == 0) {
        if (resultCode == Activity.RESULT_OK) {
            String contents = data.getStringExtra("SCAN_RESULT");
            for (String stanzas : contents.split(" ")) {
                String[] tmp = stanzas.split(":");
                if (tmp[0].equalsIgnoreCase("KEY_BASE64")) {
                    txt_KEY.setText(tmp[1]);
                    chkb64key.setChecked(true);
                } else if (tmp[0].equalsIgnoreCase("KEY")) {
                    txt_KEY.setText(tmp[1]);
                    chkb64key.setChecked(false);
                } else if (tmp[0].equalsIgnoreCase("HMAC_KEY_BASE64")) {
                    txt_HMAC.setText(tmp[1]);
                    chkb64hmac.setChecked(true);
                } else if (tmp[0].equalsIgnoreCase("HMAC_KEY")) {
                    txt_HMAC.setText(tmp[1]);
                    chkb64hmac.setChecked(false);
                }//from  w  w w  . j  a  v a 2 s . co  m
            } // end for loop
        }
        if (resultCode == Activity.RESULT_CANCELED) {
            //handle cancel
            Context context = getActivity();
            CharSequence text = " QR Code Canceled";
            int duration = Toast.LENGTH_LONG;
            Toast toast = Toast.makeText(context, text, duration);
            toast.setGravity(Gravity.CENTER, 0, 0);
            LinearLayout toastLayout = (LinearLayout) toast.getView();
            TextView toastTV = (TextView) toastLayout.getChildAt(0);
            toastTV.setTextSize(30);
            toast.show();
        }
    }
}

From source file:org.apache.cordova.Capture.java

/**
 * Called when the video view exits./*ww w .  ja va 2  s.co  m*/
 *
 * @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.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, results));
            } 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 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.cordova.getActivity().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.cordova.getActivity().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;
                    }
                }
                FileInputStream fis = new FileInputStream(
                        DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/Capture.jpg");
                OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri);
                byte[] buffer = new byte[4096];
                int len;
                while ((len = fis.read(buffer)) != -1) {
                    os.write(buffer, 0, len);
                }
                os.flush();
                os.close();
                fis.close();

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

                checkForDuplicateImage();

                if (results.length() >= limit) {
                    // Send Uri back to JavaScript for viewing image
                    this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, results));
                } 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
            if (data == null) {
                this.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Error: data is null"));
            } else {
                results.put(createMediaFile(data));
                if (results.length() >= limit) {
                    // Send Uri back to JavaScript for viewing video
                    this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, results));
                } 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.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, results));
        }
        // 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.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, results));
        }
        // something bad happened
        else {
            this.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Did not complete!"));
        }
    }
}

From source file:com.ct.speech.HintReceiver.java

/**
 * Handle the results from the recognition activity.
 *//*from   w  w  w  .  j  a  v a2 s  .c o  m*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        // Fill the list view with the strings the recognizer thought it
        // could have heard
        ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        speechResults(requestCode, matches);

    } else if (resultCode == Activity.RESULT_CANCELED) {
        // cancelled by user
        speechFailure("Cancelled");
    } else {
        speechFailure("Unknown error");
    }

    super.onActivityResult(requestCode, resultCode, data);
}

From source file:org.apache.cordova.core.Capture.java

/**
 * Called when the video view exits./*from  w w w. j a va  2  s. co m*/
 *
 * @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.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, results));
            } 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 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.cordova.getActivity().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.cordova.getActivity().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;
                    }
                }
                FileInputStream fis = new FileInputStream(
                        DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/Capture.jpg");
                OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri);
                byte[] buffer = new byte[4096];
                int len;
                while ((len = fis.read(buffer)) != -1) {
                    os.write(buffer, 0, len);
                }
                os.flush();
                os.close();
                fis.close();

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

                checkForDuplicateImage();

                if (results.length() >= limit) {
                    // Send Uri back to JavaScript for viewing image
                    this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, results));
                } 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
            if (data == null) {
                this.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Error: data is null"));
            } else {
                results.put(createMediaFile(data));

                if (results.length() >= limit) {
                    // Send Uri back to JavaScript for viewing video
                    this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, results));
                } 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.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, results));
        }
        // 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.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, results));
        }
        // something bad happened
        else {
            this.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Did not complete!"));
        }
    }
}

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

private void sendFailure(W2faInitResponse w2faInitResponse) {
    Intent resultData = new Intent();
    resultData.putExtra(InAppUtil.EXTRA_KEY_RES_CODE, w2faInitResponse.getResCode());
    resultData.putExtra(InAppUtil.EXTRA_KEY_RES_DESC, "sdk init - " + w2faInitResponse.getResDesc());
    if (w2faInitResponse.getWibmoTxnId() != 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());
        }/*from   w ww.j  av a  2  s. co  m*/
    }
    setResult(Activity.RESULT_CANCELED, resultData);
    finish();
}

From source file:it.polimi.spf.app.fragments.profile.ProfileFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case ACTIVITY_EDIT_PROFILE_CODE:
        // Profile may have changed, reload it
        if (resultCode == Activity.RESULT_CANCELED) {
            Log.d(TAG, "Edit finished but no data was modified");
        }/*ww w . j a  v a2  s. c o  m*/

        onProfileDataSaved();
        startLoader(LOAD_PROFILE_LOADER_ID);
        break;
    case ACTIVITY_EDIT_PROFILE_PICTURE_CODE:
        if (resultCode != Activity.RESULT_OK) {
            return;
        }

        if (data != null && data.getExtras() != null) {
            Bitmap photo = data.getExtras().getParcelable("data");
            mContainer.setFieldValue(ProfileField.PHOTO, photo);
            showPicture(photo);
        }
    }

    super.onActivityResult(requestCode, resultCode, data);
}

From source file:io.imoji.sdk.editor.fragment.TagImojiFragment.java

private void notifyFailure() {
    //notify of failure
    getActivity().setResult(Activity.RESULT_CANCELED);
    getActivity().finish();
}