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.cdvdev.subscriptiondemo.helpers.IabHelper.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   w w  w . j  a va2 s . c  om
 */
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
    IabResult result;
    if (requestCode != mRequestCode)
        return false;

    checkNotDisposed();
    checkSetupDone("handleActivityResult");

    // end of async purchase operation that started on launchPurchaseFlow
    flagEndAsync();

    if (data == null) {
        logError("Null data in IAB activity result.");
        result = new IabResult(IABHELPER_BAD_RESPONSE, "Null data in IAB result");
        if (mPurchaseListener != null)
            mPurchaseListener.onIabPurchaseFinished(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 == BILLING_RESPONSE_RESULT_OK) {
        logDebug("Successful resultcode from purchase activity.");
        logDebug("Purchase data: " + purchaseData);
        logDebug("Data signature: " + dataSignature);
        logDebug("Extras: " + data.getExtras());
        logDebug("Expected item type: " + mPurchasingItemType);

        if (purchaseData == null || dataSignature == null) {
            logError("BUG: either purchaseData or dataSignature is null.");
            logDebug("Extras: " + data.getExtras().toString());
            result = new IabResult(IABHELPER_UNKNOWN_ERROR, "IAB returned null purchaseData or dataSignature");
            if (mPurchaseListener != null)
                mPurchaseListener.onIabPurchaseFinished(result, null);
            return true;
        }

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

            // Verify signature
            if (!Security.verifyPurchase(mLicenseKey, purchaseData, dataSignature)) {
                logError("Purchase signature verification FAILED for sku " + sku);
                result = new IabResult(IABHELPER_VERIFICATION_FAILED,
                        "Signature verification failed for sku " + sku);
                if (mPurchaseListener != null)
                    mPurchaseListener.onIabPurchaseFinished(result, purchase);
                return true;
            }
            logDebug("Purchase signature successfully verified.");
        } catch (JSONException e) {
            logError("Failed to parse purchase data.");
            e.printStackTrace();
            result = new IabResult(IABHELPER_BAD_RESPONSE, "Failed to parse purchase data.");
            if (mPurchaseListener != null)
                mPurchaseListener.onIabPurchaseFinished(result, null);
            return true;
        }

        if (mPurchaseListener != null) {
            mPurchaseListener.onIabPurchaseFinished(new IabResult(BILLING_RESPONSE_RESULT_OK, "Success"),
                    purchase);
        }
    } else if (resultCode == Activity.RESULT_OK) {
        // result code was OK, but in-app billing response was not OK.
        logDebug("Result code was OK but in-app billing response was not OK: " + getResponseDesc(responseCode));
        if (mPurchaseListener != null) {
            result = new IabResult(responseCode, "Problem purchashing item.");
            mPurchaseListener.onIabPurchaseFinished(result, null);
        }
    } else if (resultCode == Activity.RESULT_CANCELED) {
        logDebug("Purchase canceled - Response: " + getResponseDesc(responseCode));
        result = new IabResult(IABHELPER_USER_CANCELLED, "User canceled.");
        if (mPurchaseListener != null)
            mPurchaseListener.onIabPurchaseFinished(result, null);
    } else {
        logError("Purchase failed. Result code: " + Integer.toString(resultCode) + ". Response: "
                + getResponseDesc(responseCode));
        result = new IabResult(IABHELPER_UNKNOWN_PURCHASE_RESPONSE, "Unknown purchase response.");
        if (mPurchaseListener != null)
            mPurchaseListener.onIabPurchaseFinished(result, null);
    }
    return true;
}

From source file:bucci.dev.freestyle.TimerActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQ_CODE_CHOOSE_SONG && resultCode == Activity.RESULT_OK) {
        if ((data != null) && (data.getData() != null)) {
            Uri songUri = data.getData();

            String songPath = MediaUtils.getPath(getApplicationContext(), songUri);

            if (timerType != TimerType.ROUTINE) {
                if (MediaUtils.isSongLongEnough(songPath, timerType)) {
                    saveSongPath(songPath);
                } else {
                    makeChooseLongerSongToast();
                    chooseSong();//from  www . j  av a2  s .  c  o m
                }
            } else {
                saveSongPath(songPath);

                long duration = MediaUtils
                        .getSongDuration(settings.getString(SAVED_SONG_PATH_PARAM, SONG_PATH_EMPTY_VALUE));
                routine_duration = duration;
                startTime = duration;
                timerTextView.setText(formatLongToTimerText(startTime));
            }
        }
    }
}

From source file:com.github.chenxiaolong.dualbootpatcher.settings.RomSettingsFragment.java

@Override
public void onActivityResult(int request, int result, Intent data) {
    switch (request) {
    case REQUEST_BACKUP_DIRECTORY:
        if (data != null && result == Activity.RESULT_OK) {
            Uri treeDocumentUri = FileUtils.getDocumentUriFromTreeUri(data.getData());
            if (treeDocumentUri != null) {
                new SetBackupPathTask().execute(treeDocumentUri);
            }//from  www .ja  v a 2  s  .  c o  m
        }
        break;
    default:
        super.onActivityResult(request, result, data);
        break;
    }
}

From source file:com.example.google.playservices.placepicker.PlacePickerFragment.java

/**
 * Extracts data from PlacePicker result.
 * This method is called when an Intent has been started by calling
 * {@link #startActivityForResult(android.content.Intent, int)}. The Intent for the
 * {@link com.google.android.gms.location.places.ui.PlacePicker} is started with
 * {@link #REQUEST_PLACE_PICKER} request code. When a result with this request code is received
 * in this method, its data is extracted by converting the Intent data to a {@link Place}
 * through the/* ww w. j  a  va 2  s  .co m*/
 * {@link com.google.android.gms.location.places.ui.PlacePicker#getPlace(android.content.Intent,
 * android.content.Context)} call.
 *
 * @param requestCode
 * @param resultCode
 * @param data
 */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    // BEGIN_INCLUDE(activity_result)
    if (requestCode == REQUEST_PLACE_PICKER) {
        // This result is from the PlacePicker dialog.

        // Enable the picker option
        showPickAction(true);

        if (resultCode == Activity.RESULT_OK) {
            /* User has picked a place, extract data.
               Data is extracted from the returned intent by retrieving a Place object from
               the PlacePicker.
             */
            final Place place = PlacePicker.getPlace(data, getActivity());
            if (place.getPlaceTypes().contains(place.TYPE_RESTAURANT)) {
                HttpPost httppost = new HttpPost("http://powergrid.xyz/quickq/restaurantget.php");
                httppost.setHeader("Content-type", "application/x-www-form-urlencoded");
                List<NameValuePair> nameValuePairs = new ArrayList<>(1);
                nameValuePairs.add(new BasicNameValuePair("placeid", place.getId()));
                try {
                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                } catch (UnsupportedEncodingException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                powergridServerRestaurants task = new powergridServerRestaurants();
                task.execute(httppost, place);
            } else {
                Toast.makeText(context, "You must select a restaurant.", Toast.LENGTH_SHORT).show();
                getCardStream().hideCard(CARD_DETAIL);
            }

        } else {
            // User has not selected a place, hide the card.
            getCardStream().hideCard(CARD_DETAIL);
        }

    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
    // END_INCLUDE(activity_result)
}

From source file:com.ichi2.anki2.CardBrowser.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        Log.i(AnkiDroidApp.TAG, "CardBrowser - onBackPressed()");
        if (mSearchEditText.getText().length() == 0) {
            closeCardBrowser(Activity.RESULT_OK);
        } else {/* w  ww.  j av a  2s .  c  o  m*/
            mSearchEditText.setText("");
            mSearchEditText.setHint(R.string.downloaddeck_search);
            mSelectedTags.clear();
        }
        return true;
    }

    return super.onKeyDown(keyCode, event);
}

From source file:ca.mimic.apphangar.Settings.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Tools.HangarLog("ResultCode: " + resultCode + "RequestCode: " + requestCode + "Intent: " + data);
    if (requestCode == 1001) {
        int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
        String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");

        if (responseCode == 0) {
            try {
                JSONObject jo = new JSONObject(purchaseData);
                String sku = jo.getString("productId");
                Tools.HangarLog("It werked! productId: " + sku);
                launchThanks(THANK_YOU_GOOGLE);
            } catch (JSONException e) {
                e.printStackTrace();/*from   w ww .ja  v a  2  s. c  om*/
            }
        } else {
            if (responseCode > 1) {
                Tools.HangarLog("Not user's fault, tried to purchase but bailed.");
                Toast.makeText(mContext, getResources().getString(R.string.donate_try_paypal),
                        Toast.LENGTH_LONG).show();
            }
            launchDonate();
        }
    } else if (requestCode == 1) {
        // Icon chooser
        if (resultCode == Activity.RESULT_OK) {
            try {
                Bitmap bitmap = data.getParcelableExtra("icon");
                ComponentName componentTask = ComponentName
                        .unflattenFromString(mIconTask.getPackageName() + "/" + mIconTask.getClassName());
                IconCacheHelper.preloadComponent(mContext, componentTask, bitmap,
                        Tools.dpToPx(mContext, CACHED_ICON_SIZE));
                myService.execute(SERVICE_CREATE_NOTIFICATIONS);
                completeRedraw = true;
                Tools.updateWidget(mContext);
            } catch (Exception e) {
                Tools.HangarLog("Icon result exception: " + e);
            }
        }
    } else if (requestCode == 2) {
        // Icon chooser
        if (resultCode == Activity.RESULT_OK) {
            try {
                Bitmap bitmap = data.getParcelableExtra("icon");
                IconCacheHelper.preloadIcon(mContext, Settings.MORE_APPS_PACKAGE, bitmap,
                        Tools.dpToPx(mContext, CACHED_ICON_SIZE));
                myService.execute(SERVICE_CREATE_NOTIFICATIONS);
                completeRedraw = true;
                Tools.updateWidget(mContext);
                updateMoreAppsIcon(mContext);
            } catch (Exception e) {
                Tools.HangarLog("Icon result exception: " + e);
            }
        }
    }
}

From source file:cm.aptoide.com.facebook.android.Facebook.java

/**
 * IMPORTANT: This method must be invoked at the top of the calling
 * activity's onActivityResult() function or Facebook authentication will
 * not function properly!/*w w w  .ja va 2s  .c  o m*/
 *
 * If your calling activity does not currently implement onActivityResult(),
 * you must implement it and include a call to this method if you intend to
 * use the authorize() method in this SDK.
 *
 * For more information, see
 * http://developer.android.com/reference/android/app/
 *   Activity.html#onActivityResult(int, int, android.content.Intent)
 */
public void authorizeCallback(int requestCode, int resultCode, Intent data) {
    if (requestCode == mAuthActivityCode) {

        // Successfully redirected.
        if (resultCode == Activity.RESULT_OK) {

            // Check OAuth 2.0/2.10 error code.
            String error = data.getStringExtra("error");
            if (error == null) {
                error = data.getStringExtra("error_type");
            }

            // A Facebook error occurred.
            if (error != null) {
                if (error.equals(SINGLE_SIGN_ON_DISABLED) || error.equals("AndroidAuthKillSwitchException")) {
                    Util.logd("Facebook-authorize",
                            "Hosted auth currently " + "disabled. Retrying dialog auth...");
                    startDialogAuth(mAuthActivity, mAuthPermissions);
                } else if (error.equals("access_denied") || error.equals("OAuthAccessDeniedException")) {
                    Util.logd("Facebook-authorize", "Login canceled by user.");
                    mAuthDialogListener.onCancel();
                } else {
                    String description = data.getStringExtra("error_description");
                    if (description != null) {
                        error = error + ":" + description;
                    }
                    Util.logd("Facebook-authorize", "Login failed: " + error);
                    mAuthDialogListener.onFacebookError(new FacebookError(error));
                }

                // No errors.
            } else {
                setAccessToken(data.getStringExtra(TOKEN));
                setAccessExpiresIn(data.getStringExtra(EXPIRES));
                if (isSessionValid()) {
                    Util.logd("Facebook-authorize", "Login Success! access_token=" + getAccessToken()
                            + " expires=" + getAccessExpires());
                    mAuthDialogListener.onComplete(data.getExtras());
                } else {
                    mAuthDialogListener.onFacebookError(new FacebookError("Failed to receive access token."));
                }
            }

            // An error occurred before we could be redirected.
        } else if (resultCode == Activity.RESULT_CANCELED) {

            // An Android error occured.
            if (data != null) {
                Util.logd("Facebook-authorize", "Login failed: " + data.getStringExtra("error"));
                mAuthDialogListener.onError(new DialogError(data.getStringExtra("error"),
                        data.getIntExtra("error_code", -1), data.getStringExtra("failing_url")));

                // User pressed the 'back' button.
            } else {
                Util.logd("Facebook-authorize", "Login canceled by user.");
                mAuthDialogListener.onCancel();
            }
        }
    }
}

From source file:com.cm.android.beercellar.ui.ImageGridFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case REQUEST_TAKE_PHOTO:
        if (resultCode == Activity.RESULT_OK) {
            String imageFileName = getActivity()
                    .getSharedPreferences(Utils.SHARED_PREF_NAME, Context.MODE_PRIVATE)
                    .getString("IMAGE_NAME", null);
            String imageAbsolutePath = Utils.getExternalImageStorageDir(getActivity()).getAbsolutePath()
                    + File.separator + imageFileName;
            String thumbnailAbsolutePath = Utils.getExternalThumbnailStorageDir(getActivity()).getAbsolutePath()
                    + File.separator + imageFileName;
            Bitmap thumbnailBitmap = Utils.createThumbnail(getActivity(), imageAbsolutePath,
                    thumbnailAbsolutePath, Utils.THUMBNAIL_SIZE, Utils.THUMBNAIL_SIZE);
            mAdapter.notifyDataSetChanged();

            //Call Google Vision API
            uploadImage(thumbnailAbsolutePath, thumbnailBitmap);
        }//w  w w .j a v a  2 s .  c om
    }
}

From source file:com.hexypixel.hexyplugin.IabHelper.java

public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
    IabResult result;//from   w  w  w  . ja va  2  s  .  c  om
    if (requestCode != mRequestCode)
        return false;

    checkNotDisposed();
    checkSetupDone("handleActivityResult");

    // end of async purchase operation that started on launchPurchaseFlow
    flagEndAsync();

    if (data == null) {
        logError("Null data in IAB activity result.");
        result = new IabResult(IABHELPER_BAD_RESPONSE, "Null data in IAB result");
        if (mPurchaseListener != null)
            mPurchaseListener.onIabPurchaseFinished(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 == BILLING_RESPONSE_RESULT_OK) {
        logDebug("Successful resultcode from purchase activity.");
        logDebug("Purchase data: " + purchaseData);
        logDebug("Data signature: " + dataSignature);
        logDebug("Extras: " + data.getExtras());
        logDebug("Expected item type: " + mPurchasingItemType);

        if (purchaseData == null || dataSignature == null) {
            logError("BUG: either purchaseData or dataSignature is null.");
            logDebug("Extras: " + data.getExtras().toString());
            result = new IabResult(IABHELPER_UNKNOWN_ERROR, "IAB returned null purchaseData or dataSignature");
            if (mPurchaseListener != null)
                mPurchaseListener.onIabPurchaseFinished(result, null);
            return true;
        }

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

            // Verify signature
            if (!Security.verifyPurchase(mSignatureBase64, purchaseData, dataSignature)) {
                logError("Purchase signature verification FAILED for sku " + sku);
                result = new IabResult(IABHELPER_VERIFICATION_FAILED,
                        "Signature verification failed for sku " + sku);
                if (mPurchaseListener != null)
                    mPurchaseListener.onIabPurchaseFinished(result, purchase);
                return true;
            }
            logDebug("Purchase signature successfully verified.");
        } catch (JSONException e) {
            logError("Failed to parse purchase data.");
            e.printStackTrace();
            result = new IabResult(IABHELPER_BAD_RESPONSE, "Failed to parse purchase data.");
            if (mPurchaseListener != null)
                mPurchaseListener.onIabPurchaseFinished(result, null);
            return true;
        }

        if (mPurchaseListener != null) {
            mPurchaseListener.onIabPurchaseFinished(new IabResult(BILLING_RESPONSE_RESULT_OK, "Success"),
                    purchase);
        }
    } else if (resultCode == Activity.RESULT_OK) {
        // result code was OK, but in-app billing response was not OK.
        logDebug("Result code was OK but in-app billing response was not OK: " + getResponseDesc(responseCode));
        if (mPurchaseListener != null) {
            result = new IabResult(responseCode, "Problem purchashing item.");
            mPurchaseListener.onIabPurchaseFinished(result, null);
        }
    } else if (resultCode == Activity.RESULT_CANCELED) {
        logDebug("Purchase canceled - Response: " + getResponseDesc(responseCode));
        result = new IabResult(IABHELPER_USER_CANCELLED, "User canceled.");
        if (mPurchaseListener != null)
            mPurchaseListener.onIabPurchaseFinished(result, null);
    } else {
        logError("Purchase failed. Result code: " + Integer.toString(resultCode) + ". Response: "
                + getResponseDesc(responseCode));
        result = new IabResult(IABHELPER_UNKNOWN_PURCHASE_RESPONSE, "Unknown purchase response.");
        if (mPurchaseListener != null)
            mPurchaseListener.onIabPurchaseFinished(result, null);
    }
    return true;
}

From source file:com.hichinaschool.flashcards.anki.CardBrowser.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        // Log.i(AnkiDroidApp.TAG, "CardBrowser - onBackPressed()");
        if (mSearchEditText.getText().length() == 0) {
            closeCardBrowser(Activity.RESULT_OK);
        } else {//from  w  w  w.  ja  va  2s .co  m
            mSearchEditText.setText("");
            mSearchEditText.setHint(R.string.downloaddeck_search);
            mSelectedTags.clear();
        }
        return true;
    }

    return super.onKeyDown(keyCode, event);
}