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.example.android.geofence.DGGeofencing.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    // Choose what to do based on the request code
    switch (requestCode) {

    // If the request code matches the code sent in onConnectionFailed
    case GeofenceUtils.CONNECTION_FAILURE_RESOLUTION_REQUEST:

        switch (resultCode) {
        // If Google Play services resolved the problem
        case Activity.RESULT_OK:

            // If the request was to add geofences
            if (GeofenceUtils.REQUEST_TYPE.ADD == mRequestType) {

                // Toggle the request flag and send a new request
                mGeofenceRequester.setInProgressFlag(false);

                // Restart the process of adding the current geofences
                mGeofenceRequester.addGeofences(mCurrentGeofences);

                // If the request was to remove geofences
            } else if (GeofenceUtils.REQUEST_TYPE.REMOVE == mRequestType) {

                // Toggle the removal flag and send a new removal request
                mGeofenceRemover.setInProgressFlag(false);

                // If the removal was by Intent
                if (GeofenceUtils.REMOVE_TYPE.INTENT == mRemoveType) {

                    // Restart the removal of all geofences for the PendingIntent
                    mGeofenceRemover.removeGeofencesByIntent(mGeofenceRequester.getRequestPendingIntent());

                    // If the removal was by a List of geofence IDs
                } else {

                    // Restart the removal of the geofence list
                    mGeofenceRemover.removeGeofencesById(mGeofenceIdsToRemove);
                }/*from w w  w.  jav  a2 s.c o  m*/
            }
            break;

        // If any other result was returned by Google Play services
        default:

            // Report that Google Play services was unable to resolve the problem.
        }

        // If any other request code was received
    default:
        // Report that this Activity received an unknown requestCode

        break;
    }
}

From source file:com.soomla.store.billing.nokia.NokiaIabHelper.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 av  a2s .  c o  m*/
 */
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
    IabResult result;
    if (requestCode != RC_REQUEST)
        return false;

    checkSetupDoneAndThrow("handleActivityResult");

    if (data == null) {
        SoomlaUtils.LogError(TAG, "Null data in IAB activity result.");
        result = new IabResult(IabResult.IABHELPER_BAD_RESPONSE, "Null data in IAB result");
        purchaseFailed(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 == IabResult.BILLING_RESPONSE_RESULT_OK) {
        SoomlaUtils.LogDebug(TAG, "Successful resultcode from purchase activity.");
        SoomlaUtils.LogDebug(TAG, "IabPurchase data: " + purchaseData);
        SoomlaUtils.LogDebug(TAG, "Extras: " + data.getExtras());
        SoomlaUtils.LogDebug(TAG, "Expected item type: " + mPurchasingItemType);

        if (purchaseData == null) {
            SoomlaUtils.LogError(TAG, "BUG: purchaseData is null.");
            SoomlaUtils.LogDebug(TAG, "Extras: " + data.getExtras().toString());
            result = new IabResult(IabResult.IABHELPER_UNKNOWN_ERROR, "IAB returned null purchaseData");
            purchaseFailed(result, null);
            return true;
        }

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

            SharedPreferences prefs = SoomlaApp.getAppContext().getSharedPreferences(SoomlaConfig.PREFS_NAME,
                    Context.MODE_PRIVATE);
            String publicKey = prefs.getString(NokiaStoreIabService.PUBLICKEY_KEY, "");

            // Verify signature
            if (!Security.verifyPurchase(publicKey, purchaseData)) {
                SoomlaUtils.LogError(TAG, "IabPurchase signature verification FAILED for sku " + sku);
                result = new IabResult(IabResult.IABHELPER_VERIFICATION_FAILED,
                        "Signature verification failed for sku " + sku);
                purchaseFailed(result, purchase);
                return true;
            }
            SoomlaUtils.LogDebug(TAG, "IabPurchase signature successfully verified.");
        } catch (JSONException e) {
            SoomlaUtils.LogError(TAG, "Failed to parse purchase data.");
            e.printStackTrace();
            result = new IabResult(IabResult.IABHELPER_BAD_RESPONSE, "Failed to parse purchase data.");
            purchaseFailed(result, null);
            return true;
        }

        purchaseSucceeded(purchase);
    } else if (resultCode == Activity.RESULT_OK) {
        // result code was OK, but in-app billing response was not OK.
        SoomlaUtils.LogDebug(TAG, "Result code was OK but in-app billing response was not OK: "
                + IabResult.getResponseDesc(responseCode));
        result = new IabResult(responseCode, "Problem purchashing item.");
        purchaseFailed(result, null);
    } else if (resultCode == Activity.RESULT_CANCELED) {
        SoomlaUtils.LogDebug(TAG, "IabPurchase canceled. Response: " + IabResult.getResponseDesc(responseCode));
        try {
            IabPurchase purchase = new IabPurchase(mPurchasingItemType,
                    "{\"productId\":" + mPurchasingItemSku + "}", "");
            result = new IabResult(IabResult.BILLING_RESPONSE_RESULT_USER_CANCELED, "User canceled.");
            purchaseFailed(result, purchase);
        } catch (JSONException e) {
            SoomlaUtils.LogError(TAG, "Failed to generate canceled purchase.");
            e.printStackTrace();
            result = new IabResult(IabResult.IABHELPER_BAD_RESPONSE, "Failed to generate canceled purchase.");
            purchaseFailed(result, null);
            return true;
        }
    } else {
        SoomlaUtils.LogError(TAG, "IabPurchase failed. Result code: " + Integer.toString(resultCode)
                + ". Response: " + IabResult.getResponseDesc(responseCode));
        result = new IabResult(IabResult.IABHELPER_UNKNOWN_PURCHASE_RESPONSE, "Unknown purchase response.");
        purchaseFailed(result, null);
    }
    return true;
}

From source file:com.wenwen.chatuidemo.activity.AddContactActivity.java

/**
 * contact/*from   www. j  a  v a  2  s .c  o m*/
 * 
 * @param view
 */
public void addContact(View view) {
    if (DemoApplication.getInstance().getUserName().equals(nameText.getText().toString())) {
        startActivity(new Intent(this, AlertDialog.class).putExtra("msg", "?"));
        return;
    }
    final ProgressDialog pd = new ProgressDialog(AddContactActivity.this);
    pd.setMessage("...");
    RequestParams params = new RequestParams();
    DebugLog.i(TAG, "uid" + DemoApplication.getInstance().getUserUid());
    params.put("fromuid", DemoApplication.getInstance().getUserUid());
    params.put("touid", myUser.getAccount_id());
    params.put("flag", "1");
    HttpClientRequest.post(Urls.FRIENDSSET, params, 3000, new AsyncHttpResponseHandler() {
        @Override
        public void onStart() {
            // TODO Auto-generated method stub
            super.onStart();
            pd.show();
        }

        @Override
        public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
            // TODO Auto-generated method stub
            try {
                String res = new String(arg2);
                DebugLog.i(TAG, "" + res);
                JSONObject result = new JSONObject(res);
                switch (Integer.valueOf(result.getString("ret"))) {
                case 0:
                    Toast.makeText(AddContactActivity.this, "", Toast.LENGTH_SHORT).show();
                    break;
                case 1:
                    Toast.makeText(AddContactActivity.this, "?", Toast.LENGTH_SHORT).show();
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("myuser", myUser);
                    Intent data = new Intent();
                    data.putExtras(bundle);
                    setResult(Activity.RESULT_OK, data); // ???
                    finish();
                    break;
                case -2:
                    Toast.makeText(AddContactActivity.this, "??", Toast.LENGTH_SHORT).show();
                    break;
                default:
                    break;

                }
            } catch (NumberFormatException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

        @Override
        public void onFinish() {
            // TODO Auto-generated method stub
            super.onFinish();
            pd.dismiss();
        }

        @Override
        public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
            // TODO Auto-generated method stub

        }
    });
}

From source file:org.anhonesteffort.flock.SubscriptionGoogleFragment.java

protected void handlePurchaseIntentResult(int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        if (data.getIntExtra("RESPONSE_CODE", 0) == 0)
            handleItemPurchased(data);/*from  w  w w  .j a v a2 s .  c  o  m*/
        else
            handleItemPurchaseFailed(data);
    } else
        handleItemPurchaseCanceled();

    subscriptionActivity.handleClearActivityResult();
}

From source file:com.irontec.mintzatu.EzarpenakDetailActivity.java

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

    if (requestCode == TWITTER_AUTH) {
        if (resultCode == Activity.RESULT_OK) {
            final String oauthVerifier = (String) data.getExtras().get("oauth_verifier");
            if (oauthVerifier != null && oauthVerifier != "") {
                new Thread(new Runnable() {
                    AccessToken accessToken = null;

                    public void run() {
                        try {
                            accessToken = twitter.getOAuthAccessToken(requestToken, oauthVerifier);
                            Editor e = TwitterHelper.getTwitterPrerefencesEditor(mContext);
                            e.putString(TwitterHelper.PREF_KEY_TOKEN, accessToken.getToken());
                            e.putString(TwitterHelper.PREF_KEY_SECRET, accessToken.getTokenSecret());
                            e.commit();//from  w  ww  .j av a2  s .co m
                        } catch (TwitterException e) {
                            e.printStackTrace();
                        }
                    }
                }).start();
            }
        }
    }
}

From source file:com.insthub.O2OMobile.Activity.D3_OrderCommentActivity.java

@Override
public void OnMessageResponse(String url, JSONObject jo, AjaxStatus status) throws JSONException {
    if (url.endsWith(ApiInterface.COMMENT_SEND)) {
        ToastView toast = new ToastView(this, getString(R.string.evaluate_success));
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();/*w w  w.ja  va  2 s  .  c  o  m*/
        Intent intentResult = new Intent();
        intentResult.putExtra(O2OMobileAppConst.ORDERINFO, mCommentModel.publicOrder);
        setResult(Activity.RESULT_OK, intentResult);
        finish();
        Intent intent = new Intent(this, D3_OrderCommentCompleteActivity.class);
        intent.putExtra("order_id", mOrder_info.id);
        startActivity(intent);
    }
}

From source file:com.coloreight.plugin.socialAuth.SocialAuth.java

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

    fbCallbackManager.onActivityResult(requestCode, resultCode, intent);

    if (requestCode == SocialAuth.TWITTER_OAUTH_REQUEST) {
        if (resultCode == Activity.RESULT_OK) {
            Log.v(TAG, "On activity result with authtoken: " + intent.getExtras().keySet());

            for (String key : intent.getExtras().keySet()) {
                Object value = intent.getExtras().get(key);
                try {
                    String valueStr = value.toString();

                    Log.v("AUTH", String.format("%s %s (%s)", key, valueStr, value.getClass().getName()));
                } catch (NullPointerException e) {
                    Log.v(TAG, e.getMessage());
                }/*from  w ww .  j av  a 2  s  . c o  m*/
            }

            this.getTwitterSystemAccount(this.requestedTwitterAccountName, callbackContext);
        } else if (resultCode == Activity.RESULT_CANCELED) {
            callbackContext.error("Twitter auth activity canceled");
        }
    }
}

From source file:com.turbulenz.turbulenz.googlepayment.java

public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
    _log("handleActivityResult: requestCode: " + requestCode + " resultCode: " + resultCode);

    if (0 == mPurchaseContext) {
        _error("handleActivityResult: no purchase context registered");
        return true;
    }/*from   ww w .j a v  a2 s. c o  m*/

    if (Activity.RESULT_CANCELED == resultCode) {
        _log("handleActivityResult: cancelled");
        sendPurchaseFailure(mPurchaseContext, null);
        mPurchaseContext = 0;
        return true;
    }

    if (Activity.RESULT_OK != resultCode) {
        _log("onActivityResult: unknown result code");
        sendPurchaseFailure(mPurchaseContext, "Unknown GooglePlay failure");
        mPurchaseContext = 0;
        return true;
    }

    _log("handleActivityResult: resultCode was OK");

    int purchaseResponse = getResponseCodeFromIntent(data);
    if (BILLING_RESPONSE_RESULT_OK != purchaseResponse) {
        _log("onActivityResult: bad purchaseResponse: " + purchaseResponse);
        sendPurchaseFailure(mPurchaseContext, "Purchase did not complete");
        mPurchaseContext = 0;
        return true;
    }

    String purchaseData = data.getStringExtra(RESPONSE_INAPP_PURCHASE_DATA);
    String purchaseSig = data.getStringExtra(RESPONSE_INAPP_SIGNATURE);
    String purchaseGoogleToken;
    String purchaseDevPayload;

    _log("onActivityResult: purchaseResponse: OK" + ", purchaseData: " + purchaseData + ", purchaseSig: "
            + purchaseSig);

    if (null == purchaseData || null == purchaseSig) {
        _log("onActivityResult: bad purchase data");
        sendPurchaseFailure(mPurchaseContext, "bad purchase data");
        mPurchaseContext = 0;
        return true;
    }

    if (!verifyPurchase(purchaseData, purchaseSig)) {
        _log("onActivityResult: invalid signature");
        sendPurchaseFailure(mPurchaseContext, "invalid signature");
        mPurchaseContext = 0;
        return true;
    }

    // Extract the sku name from the purchase data

    String sku;
    String googleToken;
    String devPayload;
    try {
        JSONObject o = new JSONObject(purchaseData);
        sku = o.optString("productId");
        googleToken = o.optString("token", o.optString("purchaseToken"));
        devPayload = o.optString("developerPayload");
    } catch (JSONException e) {
        sendPurchaseFailure(mPurchaseContext, "no sku data in GooglePlaye response");
        mPurchaseContext = 0;
        return true;
    }

    if (TextUtils.isEmpty(sku)) {
        sendPurchaseFailure(mPurchaseContext, "sku name was empty");
        mPurchaseContext = 0;
        return true;
    }

    _log("onActivityResult: purchase succeeded");
    sendPurchaseResult(mPurchaseContext, sku, purchaseData, googleToken, devPayload, purchaseSig);
    mPurchaseContext = 0;
    return true;
}

From source file:com.intel.xdk.camera.Camera.java

void cameraActivityResult(int resultCode, Intent intent) {
    if (resultCode == Activity.RESULT_OK) {
        //get info from shared prefs
        SharedPreferences prefs = activity.getSharedPreferences(cameraPrefsKey, 0);
        String outputFile = prefs.getString(cameraPrefsFileName, "");
        boolean isPNG = prefs.getBoolean(cameraPrefsIsPNG, false);
        int quality = prefs.getInt(cameraPrefsQuality, 100);
        savePicture(outputFile, quality, isPNG);
    } else {//  www.j a  v a2 s .  c o m
        pictureCancelled();
    }
}