Example usage for android.content Intent getExtras

List of usage examples for android.content Intent getExtras

Introduction

In this page you can find the example usage for android.content Intent getExtras.

Prototype

public @Nullable Bundle getExtras() 

Source Link

Document

Retrieves a map of extended data from the intent.

Usage

From source file:com.msopentech.applicationgateway.EnterpriseBrowserActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    try {//from ww w.j  av  a  2 s. c om
        super.onActivityResult(requestCode, resultCode, data);

        // The data argument can be null if the user simply exited the
        // activity by clicking back or cancel.
        if (data == null) {
            return;
        }

        Bundle extras = data.getExtras();

        if (extras == null) {
            return;
        }

        switch (requestCode) {
        case ACTIVITY_SIGN_IN: {
            if (resultCode != RESULT_CANCELED) {
                mCustomTabHost.clearAllHistory();

                mTraits = (ConnectionTraits) data
                        .getSerializableExtra(EnterpriseBrowserActivity.EXTRAS_TRAITS_KEY);

                if (mTraits.sessionID == null && mTraits.token == null && mTraits.agent.getAgentId() == null) {
                    // Authentication failed. Have to make user make another attempt while informing of error reason.
                    showSignIn(null, true);
                } else {
                    mStatusButtonView.setImageResource(R.drawable.connection_green);

                    if (mIsSigninRequired) {
                        mIsSigninRequired = false;
                    }
                    // Switch to agent specific stored data.
                    PersistenceManager.initialize(mTraits.agent.getAgentId());
                }
            } else {
                if (mTraits == null || mTraits.isError()) {
                    // Will get here if error was received on signIn screen and user pressed 'cancel' there.
                    mIsSigninRequired = true;
                    if (mTraits != null) {
                        mTraits.sessionID = null;
                        mTraits.token = null;
                    }
                }
            }
            break;
        }

        case ACTIVITY_ADVANCED_ROUTER_SETTINGS: {
            String url = data.getStringExtra(CLOUD_CONNECTION_HOST_PREFIX);
            Boolean useSmartBrowser = data.getBooleanExtra(EXTRAS_SMART_BROWSER_ON, false);

            if (!CLOUD_CONNECTION_HOST_PREFIX.contentEquals(url) || mUseSmartBrowser != useSmartBrowser) {
                CLOUD_CONNECTION_HOST_PREFIX = url;
                CLOUD_BROWSER_URL = CLOUD_CONNECTION_HOST_PREFIX;

                mUseSmartBrowser = useSmartBrowser;
                AuthPreferences.storeUseSmartBrowser(mUseSmartBrowser);

                if (useSmartBrowser) {
                    CLOUD_BROWSER_URL = CLOUD_BROWSER_URL + CLOUD_CONNECTION_HOST_SMARTBROWSER_POSTFIX;
                } else {
                    CLOUD_BROWSER_URL = CLOUD_BROWSER_URL + CLOUD_CONNECTION_HOST_BROWSER_POSTFIX;
                }

                AuthPreferences.storePreferredRouter(url);
                mStatusButtonView.setImageResource(R.drawable.connection_red);
                mCustomTabHost.clearAllHistory();
                showSignIn(null, false);
            }

            Boolean clearCookies = data.getBooleanExtra(EXTRAS_CLEAR_COOKIES_ON, false);
            if (clearCookies) {
                CookieManager.getInstance().removeAllCookie();
            }

            break;
        }

        case ACTIVITY_BOOKMARKS_AND_HISTORY: {
            String url = data.getStringExtra(EXTRAS_URL_KEY);
            if (!TextUtils.isEmpty(url)) {
                goToUrl(url);
            }
            break;
        }

        case ACTIVITY_AGENTS: {
            // Since the agent has changed, we can no longer use the old
            // history in WebViewClient with the old SessionID.
            mCustomTabHost.clearAllHistory();
            mReloadButtonView.setEnabled(false);

            ConnectionTraits traits = (ConnectionTraits) data.getSerializableExtra(EXTRAS_TRAITS_KEY);

            if (traits != null && traits.sessionID != null) {
                mTraits.sessionID = traits.sessionID;
                mStatusButtonView.setImageResource(R.drawable.connection_green);
                // Should never be null
                if (traits.agent != null) {
                    if (traits.agent.getAgentId() != null) {
                        mTraits.agent.setAgentId(traits.agent.getAgentId());
                        // Switch to agent specific stored data.
                        PersistenceManager.dropContent(PersistenceManager.ContentType.HISTORY);
                        PersistenceManager.initialize(mTraits.agent.getAgentId());
                    }
                    if (traits.agent.getDisplayName() != null) {
                        mTraits.agent.setDisplayName(traits.agent.getDisplayName());
                    }
                }
            }
            break;
        }

        case ACTIVITY_CLIENT_STATUS_AND_DIAGNOSTICS: {
            String browse = data.getStringExtra(EXTRAS_BROWSE_TO_ROUTER_SYSTEM_PAGE_KEY);
            if (!(browse == null || browse.isEmpty()))
                mActiveWebView.loadUrl(CLOUD_CONNECTION_HOST_PREFIX + "system");

            break;
        }
        }
    } catch (Exception e) {
        Utility.showAlertDialog(EnterpriseBrowserActivity.class.getSimpleName()
                + ".onActivityResult(): Failed. " + e.toString(), EnterpriseBrowserActivity.this);
    }
}

From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    topLayoutOnMixView.mainArView.setVisibility(View.VISIBLE);

    if (requestCode == TopLayoutOnMixView.WRITE_REVIEW) {

    }/*w  w w.j  a  va  2  s  . co  m*/

    else if (resultCode == RESULT_OK && requestCode == TopLayoutOnMixView.SEARCH_LIST) {
        double lat = data.getExtras().getDouble("lat");
        double lon = data.getExtras().getDouble("lon");

        //?  ?  
        if (navigator != null)
            navigator.run(lat, lon);
        else
            Toast.makeText(this, "? ?   .", Toast.LENGTH_LONG)
                    .show();
    } else if (resultCode == RESULT_OK && requestCode == MixView.SHOW_TRACE) {

    }
}

From source file:rpassmore.app.fillthathole.ViewHazardActivity.java

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

    switch (requestCode) {
    case PICK_PHOTO_ACTIVITY: {
        if (resultCode == RESULT_OK) {
            Bitmap bitmap;/*from  w  ww . j a  va2  s  . c  om*/
            try {
                bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(data.getData()));
                storeNewPhoto(bitmap, data.getData().toString());
            } catch (FileNotFoundException ex) {
                Log.e(getPackageName(), "Error loading image file", ex);
            }
        }
        break;
    }
    case PICTURE_ACTIVITY: {
        if (resultCode == RESULT_OK) {

            String[] projection = { MediaStore.Images.Media.DATA };
            Cursor cursor = managedQuery(capturedImageURI, projection, null, null, null);
            int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            String capturedImageFilePath = cursor.getString(column_index_data);

            Bitmap bitmap = BitmapFactory.decodeFile(capturedImageFilePath);

            storeNewPhoto(bitmap, capturedImageFilePath);
        }
        break;
    }
    case LOCATION_MAP_ACTIVITY: {
        if (resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            if (extras != null) {
                hazard.setLattitude(extras.getLong(LocationActivity.LOCATION_LAT) / 1.0E6);
                hazard.setLongitude(extras.getLong(LocationActivity.LOCATION_LONG) / 1.0E6);
                if (extras.getString("Address") != null) {
                    hazard.setAddress(extras.getString(LocationActivity.LOCATION_ADDRESS));
                }
            }
        }
        break;
    }
    }
}

From source file:com.parse.CN1ParsePushBroadcastReceiver.java

@Override
protected void onPushReceive(Context context, Intent intent) {
    /*/*from  w ww. j a v  a2 s . co  m*/
     Adapted from ParsePushBroadcastReceiver.onPushReceived(). Main changes:
     1. Implemented callbacks to ParsePush with the push payload based on
    app state
     */

    JSONObject pushData = null;
    try {
        pushData = new JSONObject(intent.getStringExtra(ParsePushBroadcastReceiver.KEY_PUSH_DATA));
    } catch (JSONException e) {
        writeErrorLog("Unexpected JSONException when parsing received push data:\n" + e);
    }
    writeDebugLog("Push received: " + (pushData == null ? "<no payload>" : pushData.toString()));

    boolean handled = false;
    if (pushData != null && CN1AndroidApplication.isAppRunning()) {
        if (CN1AndroidApplication.isAppInForeground()) {
            writeDebugLog("App in foreground; will allow app to directly handle push message, if desired");
            handled = ParsePush.handlePushReceivedForeground(pushData.toString());
        } else if (CN1AndroidApplication.isAppInBackground()) {
            writeDebugLog("App in background; will allow app to directly handle push message, if desired");
            handled = ParsePush.handlePushReceivedBackground(pushData.toString());
        }
    }

    if (!handled) {
        // If the push data includes an action string, that broadcast intent is fired.
        String action = null;
        if (pushData != null) {
            action = pushData.optString("action", null);
        }
        if (action != null) {
            writeDebugLog("Firing broadcast for action " + action);
            Bundle extras = intent.getExtras();
            Intent broadcastIntent = new Intent();
            broadcastIntent.putExtras(extras);
            broadcastIntent.setAction(action);
            broadcastIntent.setPackage(context.getPackageName());
            context.sendBroadcast(broadcastIntent);
        }

        Notification notification = getNotification(context, intent);

        if (notification != null) {
            writeDebugLog("Scheduling notification for push message since it was not handled by app");
            ParseNotificationManager.getInstance().showNotification(context, notification);
        } else {
            // If, for any reason, creating the notification fails (typically because
            // the push is a 'hidden' push with no alert/title fields),
            // store it for later processing.
            if (pushData != null) {
                writeDebugLog("Requesting ParsePush to handle unprocessed (hidden?) push message");
                ParsePush.handleUnprocessedPushReceived(pushData.toString());
            }
        }
    } else {
        writeDebugLog("Push already handled by app so not scheduling any notification");
    }
}

From source file:com.halseyburgund.rwframework.core.RWService.java

private void getSettingsFromIntent(Intent intent) {
    if ((intent != null) && (intent.getExtras() != null)) {
        // get device id from intent
        String deviceId = intent.getExtras().getString(RW.EXTRA_DEVICE_ID);
        if (deviceId != null) {
            configuration.setDeviceId(deviceId);
        }//from w  w  w  . j  a  v  a 2s .  c o  m

        // get project id from intent
        String projectId = intent.getExtras().getString(RW.EXTRA_PROJECT_ID);
        if (projectId != null) {
            configuration.setProjectId(projectId);
        }

        // server url override (can be null)
        String serverUrlOverride = intent.getExtras().getString(RW.EXTRA_SERVER_URL_OVERRIDE);
        if ((serverUrlOverride != null) && (serverUrlOverride.length() > 0)) {
            mServerUrl = serverUrlOverride;
        }

        // notification icon and handling class
        mNotificationTitle = intent.getExtras().getString(RW.EXTRA_NOTIFICATION_TITLE);
        if (mNotificationTitle == null) {
            mNotificationTitle = "Roundware";
        }
        mNotificationDefaultText = intent.getExtras().getString(RW.EXTRA_NOTIFICATION_DEFAULT_TEXT);
        if (mNotificationDefaultText == null) {
            mNotificationDefaultText = "Return to app";
        }
        mNotificationIconId = intent.getExtras().getInt(RW.EXTRA_NOTIFICATION_ICON_ID, R.drawable.status_icon);
        String className = intent.getExtras().getString(RW.EXTRA_NOTIFICATION_ACTIVITY_CLASS_NAME);
        try {
            if (className != null) {
                mNotificationActivity = Class.forName(className);
            }
        } catch (Exception e) {
            Log.e(TAG, "Unknown class specificied for handling " + "notification: " + className);
            mNotificationActivity = null;
        }
    }
}

From source file:org.csp.everyaware.offline.Map.java

/********************** INVOKED WHEN TwitterLogin RETURNS **********************************************************/

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

    if (requestCode == 0) {
        if (resultCode == RESULT_OK) {
            Log.d("Map", "Twitter auth RESULT OK");

            String oauthVerifier = intent.getExtras().getString(Constants.IEXTRA_OAUTH_VERIFIER);
            final boolean result = mTwitterManager.authoriseNewUser(oauthVerifier);

            new Handler().postDelayed(new Runnable() {
                @Override//from  w w w  .j  a v  a2  s .c  o  m
                public void run() {
                    if (result) {
                        mValidTwSession = true;
                        mButtons[1].setText(getResources().getString(R.string.logout_twitter_text));
                        Utils.setValidTwSession(true, getApplicationContext());
                    } else {
                        mValidTwSession = false;
                        mButtons[1].setText(getResources().getString(R.string.login_twitter_text));
                    }
                }

            }, 500);
        } else if (resultCode == RESULT_CANCELED) {
            mValidTwSession = false;
            mButtons[1].setText(getResources().getString(R.string.login_twitter_text));
            Utils.setValidTwSession(false, getApplicationContext());
            Log.d("Map", "Twitter auth canceled.");
        }

    }
}

From source file:com.evolup.test.IAPTest01.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./*from w  w w  .j  a  v a 2s  .c  om*/
 */
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
    IabResult result;
    if (requestCode != mRequestCode)
        return false;

    checkSetupDone("handleActivityResult");

    // end of async purchase operation
    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());

        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(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.parse.CN1ParsePushBroadcastReceiver.java

@Override
protected void onPushOpen(Context context, Intent intent) {
    /*//from   ww w.j a v a  2 s. c  o m
     Adapted from ParsePushBroadcastReceiver. Main changes:
     1. Adapted code for starting app activity since it caused problems (see 
    comments towards the end of the method starting from line 'Original code'
     2. Implemented necessary ParsePush callback to set push data in advance
    so that it will be available when the app activity is started/resumed
     */
    // Send a Parse Analytics "push opened" event
    ParseAnalytics.trackAppOpenedInBackground(intent);

    JSONObject pushData = null;
    String uriString = null;
    try {
        pushData = new JSONObject(intent.getStringExtra(ParsePushBroadcastReceiver.KEY_PUSH_DATA));
        uriString = pushData.optString("uri", null);
    } catch (JSONException e) {
        writeErrorLog("Unexpected JSONException when parsing " + "push data from opened notification: " + e);
    }

    writeDebugLog("Push opened: " + (pushData == null ? "<no payload>" : pushData.toString()));

    if (pushData != null) {
        // Forward payload so that it is available when app is opened via the push message
        ParsePush.handlePushOpen(pushData.toString(), CN1AndroidApplication.isAppInForeground());
        writeDebugLog("Notified ParsePush of opened push notification");
    }

    Class<? extends Activity> cls = getActivity(context, intent);

    Intent activityIntent;
    if (uriString != null) {
        writeDebugLog("Creating an intent to view URI: " + uriString);
        activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uriString));
    } else {
        activityIntent = new Intent(context, cls);
    }

    activityIntent.putExtras(intent.getExtras());
    activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    activityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    // Original code
    //        /*
    //         In order to remove dependency on android-support-library-v4
    //         The reason why we differentiate between versions instead of just using context.startActivity
    //         for all devices is because in API 11 the recommended conventions for app navigation using
    //         the back key changed.
    //         */
    //        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
    //            TaskStackBuilderHelper.startActivities(context, cls, activityIntent);
    //        } else {
    //            context.startActivity(activityIntent);
    //        }

    // The task stack builder approach causes only the title and a white (blank) screen 
    // to be shown when the app is in the foreground and the push notification is 
    // opened (see also problem report to CN1 support forum: https://groups.google.com/d/msg/codenameone-discussions/Z3F924j_BG4/7rn7v7oABwAJ)
    // As a result, the context.startActivity() approach is currently taken always.
    // Not sure yet if it has any undesirable side effects for sdk version 
    // before JELLY_BEAN (actually HONEYCOMB (v3.0) according to TaskStackBuilder documentation 
    // at: http://developer.android.com/reference/android/support/v4/app/TaskStackBuilder.html.
    context.startActivity(activityIntent);
}

From source file:io.teak.sdk.Teak.java

@Override
public void onReceive(Context inContext, Intent intent) {
    final Context context = inContext.getApplicationContext();

    if (!Teak.isEnabled()) {
        Log.e(LOG_TAG, "Teak is disabled, ignoring onReceive().");
        return;//w w w .j ava  2s .  c o  m
    }

    String action = intent.getAction();

    if (GCM_RECEIVE_INTENT_ACTION.equals(action)) {
        final TeakNotification notif = TeakNotification.remoteNotificationFromIntent(context, intent);
        if (notif == null) {
            return;
        }

        // Send Notification Received Metric
        Session.whenUserIdIsReadyRun(new Session.SessionRunnable() {
            @Override
            public void run(Session session) {
                HashMap<String, Object> payload = new HashMap<>();
                payload.put("app_id", session.appConfiguration.appId);
                payload.put("user_id", session.userId());
                payload.put("platform_id", notif.teakNotifId);

                new Request("/notification_received", payload, session).run();
            }
        });
    } else if (action.endsWith(TeakNotification.TEAK_NOTIFICATION_OPENED_INTENT_ACTION_SUFFIX)) {
        Bundle bundle = intent.getExtras();

        // Cancel any updates pending
        TeakNotification.cancel(context, bundle.getInt("platformId"));

        // Launch the app
        if (!bundle.getBoolean("noAutolaunch")) {
            if (Teak.isDebug) {
                Log.d(LOG_TAG,
                        "Notification (" + bundle.getString("teakNotifId") + ") opened, auto-launching app.");
            }
            Intent launchIntent = context.getPackageManager()
                    .getLaunchIntentForPackage(context.getPackageName());
            launchIntent.addCategory("android.intent.category.LAUNCHER");
            launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            launchIntent.putExtras(bundle);
            if (bundle.getString("deepLink") != null) {
                launchIntent.setData(Uri.parse(bundle.getString("deepLink")));
            }
            context.startActivity(launchIntent);
        } else {
            if (Teak.isDebug) {
                Log.d(LOG_TAG, "Notification (" + bundle.getString("teakNotifId")
                        + ") opened, NOT auto-launching app (noAutoLaunch flag present, and set to true).");
            }
        }

        // Send broadcast
        if (Teak.localBroadcastManager != null) {
            Intent broadcastEvent = new Intent(TeakNotification.LAUNCHED_FROM_NOTIFICATION_INTENT);
            broadcastEvent.putExtras(bundle);
            Teak.localBroadcastManager.sendBroadcast(broadcastEvent);
        }
    } else if (action.endsWith(TeakNotification.TEAK_NOTIFICATION_CLEARED_INTENT_ACTION_SUFFIX)) {
        Bundle bundle = intent.getExtras();
        TeakNotification.cancel(context, bundle.getInt("platformId"));
    }

}

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./*  w w  w. j  a  va2  s. 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(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;
}