Example usage for android.app Activity RESULT_OK

List of usage examples for android.app Activity RESULT_OK

Introduction

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

Prototype

int RESULT_OK

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

Click Source Link

Document

Standard activity result: operation succeeded.

Usage

From source file:com.wishlist.Wishlist.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    /*//from   w w  w .  j  av a2 s  .c o m
     * if this is the activity result from authorization flow, do a call back to authorizeCallback
     * Source Tag: login_tag
     */
    case AUTHORIZE_ACTIVITY_RESULT_CODE: {
        Utility.mFacebook.authorizeCallback(requestCode, resultCode, data);
        break;
    }
    /*
     * if this is the result for a photo picker from the gallery, upload the image after scaling it.
     * You can use the Utility.scaleImage() function for scaling
     */
    case PICK_EXISTING_PHOTO_RESULT_CODE: {
        if (resultCode == Activity.RESULT_OK) {
            Uri imageUri = data.getData();
            ((BitmapDrawable) image.getDrawable()).getBitmap().recycle();
            System.gc();
            try {
                imageBytes = Utility.scaleImage(getApplicationContext(), imageUri);
                image.setImageBitmap(BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length));
                image.invalidate();
            } catch (IOException e) {
                showToast(getString(R.string.error_getting_image));
            }
        } else {
            showToast(getString(R.string.no_image_selected));
        }
        break;
    }
    }
}

From source file:com.tribalyte.plugin.myo.MyoApi.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    logd("onActivityResult. requestCode: " + requestCode + ", resultCode: " + resultCode);
    if (REQ_CODE_ENABLE_BT == requestCode) {
        if (mOpenBtConfigCbc != null) {
            mOpenBtConfigCbc.success((resultCode == Activity.RESULT_OK) ? 1 : 0);
            mOpenBtConfigCbc = null;/*from   w  w  w.  j av a 2 s .  c  o  m*/
        } else {
            loge("Received BT enable activity result but no callbacks were stored", null);
        }
    }
    super.onActivityResult(requestCode, resultCode, intent);
}

From source file:com.cbtec.eliademy.EliademyLms.java

/**
 * Called when an activity you launched exits, giving you the requestCode
 * you started it with, the resultCode it returned, and any additional data
 * from it.//from ww w  . j a v  a  2 s .c o 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 data
 *            An Intent, which can return result data to the caller (various
 *            data can be attached to Intent "extras").
 */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    switch (requestCode) {
    case submitFileCode:
        if (resultCode == Activity.RESULT_OK) {
            Uri uri = intent.getData();
            if (uri.getScheme().toString().compareTo("content") == 0) {
                Cursor cursor = cordova.getActivity().getApplicationContext().getContentResolver().query(uri,
                        null, null, null, null);
                if (cursor.moveToFirst()) {
                    int column_index = cursor.getColumnIndexOrThrow(MediaColumns.DATA);
                    uri = Uri.parse(cursor.getString(column_index));
                }
            }
            if (this.mCallbackContext != null) {
                this.mCallbackContext.success(uri.toString());
                return;
            } else {
                Log.i("HLMS", "callback context is null");
            }
        }
        break;
    }
    if (this.mCallbackContext != null) {
        this.mCallbackContext.error(resultCode);
    } else {
        Log.i("HLMS", "callback context is null");
    }
}

From source file:com.orange.ocara.ui.activity.ListAuditActivity.java

@OnActivityResult(ACTION_CREATE_NEW_DOCUMENT)
void onCreateDocument(int resultCode, Intent data) {

    if (resultCode == Activity.RESULT_OK) {
        Uri uri = data.getData();//  w  w  w.  j  a va  2 s .  com
        copyFile(exportFile, uri);
    }
}

From source file:ca.rmen.android.scrumchatter.main.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    Log.v(TAG, "onActivityResult: requestCode = " + requestCode + ", resultCode = " + resultCode + ", intent = "
            + intent);/*from  ww  w  . ja v  a  2s.  c o  m*/
    // The user chose a DB file to import.
    if (requestCode == ACTIVITY_REQUEST_CODE_IMPORT && resultCode == Activity.RESULT_OK) {
        if (intent == null || intent.getData() == null) {
            Snackbar.make(mBinding.getRoot(), R.string.import_result_no_file, Snackbar.LENGTH_SHORT).show();
            return;
        }
        final String filePath = intent.getData().getPath();
        if (TextUtils.isEmpty(filePath)) {
            Snackbar.make(mBinding.getRoot(), R.string.import_result_no_file, Snackbar.LENGTH_SHORT).show();
            return;
        }
        // Save the uri of the file.  We will import it in onResumeFragments.
        getIntent().putExtra(EXTRA_IMPORT_URI, intent.getData());
    } else {
        super.onActivityResult(requestCode, resultCode, intent);
    }
}

From source file:br.org.funcate.dynamicforms.FragmentDetailActivity.java

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == GPictureView.PICTURE_VIEW_RESULT) {
        FragmentDetail detailFragment = (FragmentDetail) getSupportFragmentManager()
                .findFragmentById(R.id.detailFragment);
        if (detailFragment != null) {
            detailFragment.onActivityResult(requestCode, Activity.RESULT_OK, data);
        }//from   www.  ja v a2  s .  co  m
    }
}

From source file:com.envyserve.githubreference.billing.BillingProcessor.java

public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode != PURCHASE_FLOW_REQUEST_CODE)
        return false;
    if (data == null) {
        Log.e(LOG_TAG, "handleActivityResult: data is null!");
        return false;
    }/*from ww w .j  a v a 2  s .  c  o  m*/
    int responseCode = data.getIntExtra(Constants.RESPONSE_CODE, Constants.BILLING_RESPONSE_RESULT_OK);
    Log.d(LOG_TAG, String.format("resultCode = %d, responseCode = %d", resultCode, responseCode));
    String purchasePayload = getPurchasePayload();
    if (resultCode == Activity.RESULT_OK && responseCode == Constants.BILLING_RESPONSE_RESULT_OK
            && !TextUtils.isEmpty(purchasePayload)) {
        String purchaseData = data.getStringExtra(Constants.INAPP_PURCHASE_DATA);
        String dataSignature = data.getStringExtra(Constants.RESPONSE_INAPP_SIGNATURE);
        try {
            JSONObject purchase = new JSONObject(purchaseData);
            String productId = purchase.getString(Constants.RESPONSE_PRODUCT_ID);
            String developerPayload = purchase.getString(Constants.RESPONSE_PAYLOAD);
            if (developerPayload == null)
                developerPayload = "";
            boolean purchasedSubscription = purchasePayload.startsWith(Constants.PRODUCT_TYPE_SUBSCRIPTION);
            if (purchasePayload.equals(developerPayload)) {
                if (verifyPurchaseSignature(productId, purchaseData, dataSignature)) {
                    BillingCache cache = purchasedSubscription ? cachedSubscriptions : cachedProducts;
                    cache.put(productId, purchaseData, dataSignature);
                    if (eventHandler != null)
                        eventHandler.onProductPurchased(productId,
                                new TransactionDetails(new PurchaseInfo(purchaseData, dataSignature)));
                } else {
                    Log.e(LOG_TAG, "Public key signature doesn't match!");
                    if (eventHandler != null)
                        eventHandler.onBillingError(Constants.BILLING_ERROR_INVALID_SIGNATURE, null);
                }
            } else {
                Log.e(LOG_TAG, String.format("Payload mismatch: %s != %s", purchasePayload, developerPayload));
                if (eventHandler != null)
                    eventHandler.onBillingError(Constants.BILLING_ERROR_INVALID_SIGNATURE, null);
            }
        } catch (Exception e) {
            Log.e(LOG_TAG, e.toString());
            if (eventHandler != null)
                eventHandler.onBillingError(Constants.BILLING_ERROR_OTHER_ERROR, null);
        }
    } else {
        if (eventHandler != null)
            eventHandler.onBillingError(responseCode, null);
    }
    return true;
}

From source file:ch.uzh.supersede.feedbacklibrary.FeedbackActivity.java

@Override
@SuppressWarnings("unchecked")
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == REQUEST_PHOTO) {
            onSelectFromGalleryResult(data);
        } else if (requestCode == REQUEST_CAMERA) {
        } else if (requestCode == REQUEST_ANNOTATE && data != null) {
            // If mechanismViewId == -1, an error occurred
            int mechanismViewId = data.getIntExtra(Utils.EXTRA_KEY_MECHANISM_VIEW_ID, -1);
            if (mechanismViewId != -1) {
                ScreenshotMechanismView screenshotMechanismView = (ScreenshotMechanismView) allMechanismViews
                        .get(mechanismViewId);

                // Sticker annotations
                if (data.getBooleanExtra(Utils.EXTRA_KEY_HAS_STICKER_ANNOTATIONS, false)) {
                    screenshotMechanismView.setAllStickerAnnotations((HashMap<Integer, String>) data
                            .getSerializableExtra(Utils.EXTRA_KEY_ALL_STICKER_ANNOTATIONS));
                }//from w  ww . j a v  a2  s .co  m
                // Text annotations
                if (data.getBooleanExtra(Utils.EXTRA_KEY_HAS_TEXT_ANNOTATIONS, false)) {
                    screenshotMechanismView.setAllTextAnnotations((HashMap<Integer, String>) data
                            .getSerializableExtra(Utils.EXTRA_KEY_ALL_TEXT_ANNOTATIONS));
                }

                // Annotated image with stickers
                String tempPathWithStickers = data
                        .getStringExtra(Utils.EXTRA_KEY_ANNOTATED_IMAGE_PATH_WITH_STICKERS) + "/"
                        + mechanismViewId + ANNOTATED_IMAGE_NAME_WITH_STICKERS;
                screenshotMechanismView.setAnnotatedImagePath(tempPathWithStickers);
                screenshotMechanismView.setPicturePath(tempPathWithStickers);
                Bitmap annotatedBitmap = Utils.loadImageFromStorage(tempPathWithStickers);
                if (annotatedBitmap != null) {
                    screenshotMechanismView.setPictureBitmap(annotatedBitmap);
                    screenshotMechanismView.getScreenShotPreviewImageView().setImageBitmap(annotatedBitmap);
                }

                // Annotated image without stickers
                if (data.getStringExtra(Utils.EXTRA_KEY_ANNOTATED_IMAGE_PATH_WITHOUT_STICKERS) == null) {
                    screenshotMechanismView.setPicturePathWithoutStickers(null);
                } else {
                    String tempPathWithoutStickers = data
                            .getStringExtra(Utils.EXTRA_KEY_ANNOTATED_IMAGE_PATH_WITHOUT_STICKERS) + "/"
                            + mechanismViewId + ANNOTATED_IMAGE_NAME_WITHOUT_STICKERS;
                    screenshotMechanismView.setPicturePathWithoutStickers(tempPathWithoutStickers);
                }
            } else {
                Log.e(TAG, "Failed to annotate the image. No mechanismViewID provided");
            }
        }
    }
}

From source file:io.strider.camera.CameraLauncher.java

/**
 * Called when the camera view exits./* w w w . ja va  2  s  .  c  o 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").
 */
public void onActivityResult(int requestCode, int resultCode, Intent intent) {

    // Get src and dest types from request code
    int srcType = (requestCode / 16) - 1;
    int destType = (requestCode % 16) - 1;
    int rotate = 0;

    // If CAMERA
    if (srcType == CAMERA) {
        // If image available
        if (resultCode == Activity.RESULT_OK) {
            try {
                // Create an ExifHelper to save the exif data that is lost during compression
                ExifHelper exif = new ExifHelper();
                try {
                    if (this.encodingType == JPEG) {
                        exif.createInFile(getTempDirectoryPath() + "/.Pic.jpg");
                        exif.readExifData();
                        rotate = exif.getOrientation();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }

                Bitmap bitmap = null;
                Uri uri = null;

                // If sending base64 image back
                if (destType == DATA_URL) {
                    bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString()));
                    if (bitmap == null) {
                        // Try to get the bitmap from intent.
                        bitmap = (Bitmap) intent.getExtras().get("data");
                    }

                    // Double-check the bitmap.
                    if (bitmap == null) {
                        Log.d(LOG_TAG, "I either have a null image path or bitmap");
                        this.failPicture("Unable to create bitmap!");
                        return;
                    }

                    if (rotate != 0 && this.correctOrientation) {
                        bitmap = getRotatedBitmap(rotate, bitmap, exif);
                    }

                    this.processPicture(bitmap);
                    checkForDuplicateImage(DATA_URL);
                }

                // If sending filename back
                else if (destType == FILE_URI || destType == NATIVE_URI) {
                    if (this.saveToPhotoAlbum) {
                        Uri inputUri = getUriFromMediaStore();
                        //Just because we have a media URI doesn't mean we have a real file, we need to make it
                        uri = Uri.fromFile(new File(FileHelper.getRealPath(inputUri, this.cordova)));
                    } else {
                        uri = Uri.fromFile(
                                new File(getTempDirectoryPath(), System.currentTimeMillis() + ".jpg"));
                    }

                    if (uri == null) {
                        this.failPicture("Error capturing image - no media storage found.");
                    }

                    // If all this is true we shouldn't compress the image.
                    if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100
                            && !this.correctOrientation) {
                        writeUncompressedImage(uri);

                        this.callbackContext.success(uri.toString());
                    } else {
                        bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString()));

                        if (rotate != 0 && this.correctOrientation) {
                            bitmap = getRotatedBitmap(rotate, bitmap, exif);
                        }

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

                        // Restore exif data to file
                        if (this.encodingType == JPEG) {
                            String exifPath;
                            if (this.saveToPhotoAlbum) {
                                exifPath = FileHelper.getRealPath(uri, this.cordova);
                            } else {
                                exifPath = uri.getPath();
                            }
                            exif.createOutFile(exifPath);
                            exif.writeExifData();
                        }

                    }
                    // Send Uri back to JavaScript for viewing image
                    this.callbackContext.success(uri.toString());
                }

                this.cleanup(FILE_URI, this.imageUri, uri, bitmap);
                bitmap = null;

            } catch (IOException e) {
                e.printStackTrace();
                this.failPicture("Error capturing image.");
            }
        }

        // If cancelled
        else if (resultCode == Activity.RESULT_CANCELED) {
            this.failPicture("Camera cancelled.");
        }

        // If something else
        else {
            this.failPicture("Did not complete!");
        }
    }

    //      // If retrieving photo from library
    //      else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
    //         if (resultCode == Activity.RESULT_OK) {
    //            Uri uri = intent.getData();
    //
    //            // If you ask for video or all media type you will automatically get back a file URI
    //            // and there will be no attempt to resize any returned data
    //            if (this.mediaType != PICTURE) {
    //               this.callbackContext.success(uri.toString());
    //            }
    //            else {
    //               // This is a special case to just return the path as no scaling,
    //               // rotating, nor compressing needs to be done
    //               if (this.targetHeight == -1 && this.targetWidth == -1 &&
    //                     (destType == FILE_URI || destType == NATIVE_URI) && !this.correctOrientation) {
    //                  this.callbackContext.success(uri.toString());
    //               } else {
    //                  String uriString = uri.toString();
    //                  // Get the path to the image. Makes loading so much easier.
    //                  String mimeType = FileHelper.getMimeType(uriString, this.cordova);
    //                  // If we don't have a valid image so quit.
    //                  if (!("image/jpeg".equalsIgnoreCase(mimeType) || "image/png".equalsIgnoreCase(mimeType))) {
    //                     Log.d(LOG_TAG, "I either have a null image path or bitmap");
    //                     this.failPicture("Unable to retrieve path to picture!");
    //                     return;
    //                  }
    //                  Bitmap bitmap = null;
    //                  try {
    //                     bitmap = getScaledBitmap(uriString);
    //                  } catch (IOException e) {
    //                     e.printStackTrace();
    //                  }
    //                  if (bitmap == null) {
    //                     Log.d(LOG_TAG, "I either have a null image path or bitmap");
    //                     this.failPicture("Unable to create bitmap!");
    //                     return;
    //                  }
    //
    //                  if (this.correctOrientation) {
    //                     rotate = getImageOrientation(uri);
    //                     if (rotate != 0) {
    //                        Matrix matrix = new Matrix();
    //                        matrix.setRotate(rotate);
    //                        bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    //                     }
    //                  }
    //
    //                  // If sending base64 image back
    //                  if (destType == DATA_URL) {
    //                     this.processPicture(bitmap);
    //                  }
    //
    //                  // If sending filename back
    //                  else if (destType == FILE_URI || destType == NATIVE_URI) {
    //                     // Do we need to scale the returned file
    //                     if (this.targetHeight > 0 && this.targetWidth > 0) {
    //                        try {
    //                           // Create an ExifHelper to save the exif data that is lost during compression
    //                           String resizePath = getTempDirectoryPath() + "/resize.jpg";
    //                           // Some content: URIs do not map to file paths (e.g. picasa).
    //                           String realPath = FileHelper.getRealPath(uri, this.cordova);
    //                           ExifHelper exif = new ExifHelper();
    //                           if (realPath != null && this.encodingType == JPEG) {
    //                              try {
    //                                 exif.createInFile(realPath);
    //                                 exif.readExifData();
    //                                 rotate = exif.getOrientation();
    //                              } catch (IOException e) {
    //                                 e.printStackTrace();
    //                              }
    //                           }
    //
    //                           OutputStream os = new FileOutputStream(resizePath);
    //                           bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
    //                           os.close();
    //
    //                           // Restore exif data to file
    //                           if (realPath != null && this.encodingType == JPEG) {
    //                              exif.createOutFile(resizePath);
    //                              exif.writeExifData();
    //                           }
    //
    //                           // The resized image is cached by the app in order to get around this and not have to delete you
    //                           // application cache I'm adding the current system time to the end of the file url.
    //                           this.callbackContext.success("file://" + resizePath + "?" + System.currentTimeMillis());
    //                        } catch (Exception e) {
    //                           e.printStackTrace();
    //                           this.failPicture("Error retrieving image.");
    //                        }
    //                     }
    //                     else {
    //                        this.callbackContext.success(uri.toString());
    //                     }
    //                  }
    //                  if (bitmap != null) {
    //                     bitmap.recycle();
    //                     bitmap = null;
    //                  }
    //                  System.gc();
    //               }
    //            }
    //         }
    //         else if (resultCode == Activity.RESULT_CANCELED) {
    //            this.failPicture("Selection cancelled.");
    //         }
    //         else {
    //            this.failPicture("Selection did not complete!");
    //         }
    //      }
}

From source file:in.shick.diode.threads.ThreadsListActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    switch (requestCode) {
    //add constant to specify search
    case Constants.ACTIVITY_PICK_SUBREDDIT:
        if (resultCode == Activity.RESULT_OK) {
            Matcher redditContextMatcher = REDDIT_PATH_PATTERN.matcher(intent.getData().getPath());
            if (redditContextMatcher.matches()) {
                mObjectStates.mCurrentDownloadThreadsTask = new MyDownloadThreadsTask(
                        redditContextMatcher.group(1));
                mObjectStates.mCurrentDownloadThreadsTask.execute();
            }/*from   ww  w  .  j a va 2s.c o  m*/
        }
        break;
    case Constants.ACTIVITY_SEARCH_REDDIT:
        if (resultCode == Activity.RESULT_OK) {
            //changed it so each piece of data is passed separately as extras in the intent
            //rather than having to use regex to split apart a string
            //could probably do away with the "subreddit" field since we're
            //using a modified constructor anyways
            mObjectStates.mCurrentDownloadThreadsTask = new MyDownloadThreadsTask(
                    intent.getExtras().getString("searchurl"), intent.getExtras().getString("query"),
                    intent.getExtras().getString("sort"));
            mObjectStates.mCurrentDownloadThreadsTask.execute();
        }
        break;
    default:
        break;
    }
}