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.alexdisler.inapppurchases.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   ww w  .j a  v  a2s .co  m*/
 */
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();
            // Only allow purchase verification to be skipped if we are debuggable
            boolean skipPurchaseVerification = (this.mSkipPurchaseVerification
                    && ((mContext.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0));
            // Verify signature
            if (!skipPurchaseVerification) {
                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.android.vending.util.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 Activity
    * @onActivityResult} method. This method MUST be called from the UI thread
    * of the Activity.//from w ww  .ja v a  2  s.com
    *
    * @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.
    */
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(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:eu.power_switch.google_play_services.playstore.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./* w w  w.ja  va 2s.  c o  m*/
 */
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(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:eu.se_bastiaan.popcorntimeremote.iab.utils.IabHelper.java

/**
 * Handles an activity result that's part of the purchase flow in in-app com.android.vending.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.// ww  w  .  ja v  a2s .com
 */
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;
        }

        @SuppressWarnings("UnusedAssignment")
        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 com.android.vending.billing response was not OK.
        logDebug("Result code was OK but in-app com.android.vending.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.inductivebiblestudyapp.billing.util.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.//www  .jav  a  2s .  com
 */
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(mSignatureBase64, purchaseData, dataSignature) && !mIsTestingMode) {
                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.todoroo.astrid.activity.TaskListActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if ((requestCode == FilterListFragment.REQUEST_NEW_LIST
            || requestCode == TaskListFragment.ACTIVITY_REQUEST_NEW_FILTER)
            && resultCode == Activity.RESULT_OK) {
        if (data == null)
            return;

        Filter newList = data.getParcelableExtra(TagSettingsActivity.TOKEN_NEW_FILTER);
        if (newList != null) {
            getIntent().putExtra(TOKEN_SWITCH_TO_FILTER, newList); // Handle in onPostResume()
            FilterListFragment fla = getFilterListFragment();
            if (fla != null && !swipeIsEnabled())
                fla.clear();/*from   w  w w  . ja  v  a2s.  co m*/
        }
    } else if (requestCode == TaskListFragment.ACTIVITY_EDIT_TASK && resultCode != Activity.RESULT_CANCELED) {
        // Handle switch to assigned filter when it comes from TaskEditActivity finishing
        // For cases when we're in a multi-frame layout, the TaskEditFragment will notify us here directly
        TaskListFragment tlf = getTaskListFragment();
        if (tlf != null) {
            if (data != null) {
                if (data.getBooleanExtra(TaskEditFragment.TOKEN_TASK_WAS_ASSIGNED, false)) {
                    String assignedTo = data.getStringExtra(TaskEditFragment.TOKEN_ASSIGNED_TO_DISPLAY);
                    String assignedEmail = data.getStringExtra(TaskEditFragment.TOKEN_ASSIGNED_TO_EMAIL);
                    String assignedId = data.getStringExtra(TaskEditFragment.TOKEN_ASSIGNED_TO_ID);
                    taskAssignedTo(assignedTo, assignedEmail, assignedId);
                } else if (data.getParcelableExtra(TaskEditFragment.TOKEN_NEW_REPEATING_TASK) != null) {
                    Task repeating = data.getParcelableExtra(TaskEditFragment.TOKEN_NEW_REPEATING_TASK);
                    DateChangedAlerts.showRepeatChangedDialog(this, repeating);
                }
                if (data.getBooleanExtra(TaskEditFragment.TOKEN_TAGS_CHANGED, false))
                    tagsChanged(true);
            }
            tlf.refresh();
        }
    } else if (requestCode == FilterListFragment.REQUEST_CUSTOM_INTENT && resultCode == RESULT_OK
            && data != null) {
        // Tag renamed or deleted
        String action = data.getAction();
        String uuid = data.getStringExtra(TagViewFragment.EXTRA_TAG_UUID);

        if (AstridApiConstants.BROADCAST_EVENT_TAG_DELETED.equals(action)) {
            TaskListFragment tlf = getTaskListFragment();
            FilterListFragment fl = getFilterListFragment();
            if (tlf != null) {
                TagData tagData = tlf.getActiveTagData();
                String activeUuid = RemoteModel.NO_UUID;
                if (tagData != null)
                    activeUuid = tagData.getUuid();

                if (activeUuid.equals(uuid)) {
                    getIntent().putExtra(TOKEN_SWITCH_TO_FILTER,
                            CoreFilterExposer.buildInboxFilter(getResources())); // Handle in onPostResume()
                    fl.clear(); // Should auto refresh
                } else {
                    tlf.refresh();
                }
            }

            if (fl != null)
                fl.refresh();
        } else if (AstridApiConstants.BROADCAST_EVENT_TAG_RENAMED.equals(action)) {
            TaskListFragment tlf = getTaskListFragment();
            if (tlf != null) {
                TagData td = tlf.getActiveTagData();
                if (td != null && td.getUuid().equals(uuid)) {
                    td = PluginServices.getTagDataDao().fetch(uuid, TagData.PROPERTIES);
                    if (td != null) {
                        Filter filter = TagFilterExposer.filterFromTagData(this, td);
                        getIntent().putExtra(TOKEN_SWITCH_TO_FILTER, filter);
                    }
                } else {
                    tlf.refresh();
                }
            }

            FilterListFragment flf = getFilterListFragment();
            if (flf != null)
                flf.refresh();
        }
    }

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

From source file:com.mohamnag.inappbilling.InAppBillingPlugin.java

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

    if (pendingPurchaseCallbacks.containsKey(requestCode)) {
        jsLog("Got response of a purchase");

        // going to handle response of a purchase
        CallbackContext callbackContext = pendingPurchaseCallbacks.get(requestCode);
        int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
        String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
        String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");

        if (resultCode == Activity.RESULT_OK && responseCode == BILLING_RESPONSE_RESULT_OK) {
            if (purchaseData == null || dataSignature == null) {
                callbackContext/*from  w w w  . jav  a  2s.c o  m*/
                        .error(new Error(ERR_PURCHASE_FAILED, "Empty purchase data or empty signature returned")
                                .toJavaScriptJSON());
            } else {

                try {
                    Purchase purchase = new Purchase(purchaseData, dataSignature);

                    if (base64EncodedPublicKey != null
                            && !Security.verifyPurchase(base64EncodedPublicKey, purchaseData, dataSignature)) {

                        callbackContext.error(new Error(ERR_PAYMENT_INVALID, "Signature verification failed")
                                .toJavaScriptJSON());
                    } else {
                        jsLog("Purchase successful.");

                        // add the purchase to the inventory
                        myInventory.addPurchase(purchase);

                        callbackContext.success(purchase.toJavaScriptJson());
                    }
                } catch (JSONException e) {
                    callbackContext
                            .error(new Error(ERR_JSON_CONVERSION_FAILED, e.getMessage()).toJavaScriptJSON());
                }
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {
            callbackContext
                    .error(new Error(ERR_PAYMENT_CANCELLED, "Purchase cancelled by user.").toJavaScriptJSON());
        } else {
            // unknown result, interpret as error
            callbackContext
                    .error(new Error(ERR_PURCHASE_FAILED, "Unknown result code from activity. ResultCode: "
                            + resultCode + " ResponseCode: " + responseCode).toJavaScriptJSON());
        }
    }
}

From source file:de.geithonline.abattlwp.billinghelper.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.//w w  w  .  j  a v a 2  s.c o m
    * 
    * @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.
    */
public boolean handleActivityResult(final int requestCode, final int resultCode, final 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;
    }

    final int responseCode = getResponseCodeFromIntent(data);
    final String purchaseData = data.getStringExtra(RESPONSE_INAPP_PURCHASE_DATA);
    final 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);
            final 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 (final 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:edu.stanford.mobisocial.dungbeetle.NearbyActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_ACTIVITY_CALLOUT) {
        mCurrentCallout.handleResult(resultCode, data);
        return;/*from  www .j a v  a2 s  .  c o m*/
    }

    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
    if (result != null && result.getContents() != null) {
        try {
            Uri uri = Uri.parse(result.getContents());
            Intent i = new Intent(Intent.ACTION_VIEW, uri);
            i.setPackage(getPackageName());
            startActivity(i);
            finish();
        } catch (IllegalArgumentException e) {
        }
        return;
    }
    if (requestCode == RESULT_BT_ENABLE) {
        if (resultCode == Activity.RESULT_CANCELED) {
            finish();
        } else {
            findBluetooth();
        }
    }
}

From source file:com.abplus.surroundcalc.billing.BillingHelper.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 v  a2s .co  m*/
 */
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
    Result result;
    if (requestCode != this.requestCode)
        return false;

    checkSetupDone("handleActivityResult");

    asyncFlag.end();

    if (data == null) {
        result = new Result(HELPER_BAD_RESPONSE, "Null data in IAB result");
        if (purchaseListener != null) {
            purchaseListener.onPurchaseFinished(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) {

        if (purchaseData == null || dataSignature == null) {
            result = new Result(HELPER_UNKNOWN_ERROR, "IAB returned null purchaseData or dataSignature");
            if (purchaseListener != null) {
                purchaseListener.onPurchaseFinished(result, null);
            }
            return true;
        }

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

            if (!security.verifyPurchase(purchaseData, dataSignature)) {
                result = new Result(HELPER_VERIFICATION_FAILED, "Signature verification failed for sku " + sku);
                if (purchaseListener != null) {
                    purchaseListener.onPurchaseFinished(result, purchase);
                }
                return true;
            }
        } catch (JSONException e) {
            e.printStackTrace();
            result = new Result(HELPER_BAD_RESPONSE, "Failed to parse purchase data.");
            if (purchaseListener != null) {
                purchaseListener.onPurchaseFinished(result, null);
            }
            return true;
        }

        if (purchaseListener != null) {
            purchaseListener.onPurchaseFinished(new Result(BILLING_RESPONSE_RESULT_OK, "Success"), purchase);
        }
    } else if (resultCode == Activity.RESULT_OK) {
        if (purchaseListener != null) {
            result = new Result(responseCode, "Problem purchashing item.");
            purchaseListener.onPurchaseFinished(result, null);
        }
    } else if (resultCode == Activity.RESULT_CANCELED) {
        result = new Result(HELPER_USER_CANCELLED, "User canceled.");
        if (purchaseListener != null) {
            purchaseListener.onPurchaseFinished(result, null);
        }
    } else {
        result = new Result(HELPER_UNKNOWN_PURCHASE_RESPONSE, "Unknown purchase response.");
        if (purchaseListener != null)
            purchaseListener.onPurchaseFinished(result, null);
    }
    return true;
}