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.mobileobservinglog.support.billing.DonationBillingHandler.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.//ww  w .  j a v a2s  . c  o  m
 */
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d("InAppPurchase", "Starting HandleActivityResult -- handler");
    BillingHandlerResult result;
    if (requestCode != this.requestCode)
        return false;

    try {
        checkSetupDone("handleActivityResult");
    } catch (IllegalStateException e) {
        Log.d("InAppPurchase", "Setup was not done -- handler");
        result = new BillingHandlerResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
                "Setup was not finished yet");
    }

    // end of async purchase operation
    flagEndAsync();

    if (data == null) {
        Log.d("InAppPurchase", "Data was null -- handler");
        result = new BillingHandlerResult(BILLINGHELPER_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) {
        Log.d("InAppPurchase", "Activity.Result was OK and Billing response result was ok -- handler");
        if (purchaseData == null || dataSignature == null) {
            Log.d("InAppPurchase", "But we had null data -- handler");
            result = new BillingHandlerResult(BILLINGHELPER_UNKNOWN_ERROR,
                    "IAB returned null purchaseData or dataSignature");
            if (purchaseListener != null)
                purchaseListener.onPurchaseFinished(result, null);
            return true;
        }

        Purchase purchase = null;
        try {
            Log.d("InAppPurchase", "Checking the purchase -- handler");
            purchase = new Purchase(purchaseData, dataSignature);
            String sku = purchase.getSku();

            // Verify signature
            if (!PurchaseSecurity.verifyPurchase(billingKey, purchaseData, dataSignature)) {
                Log.d("InAppPurchase", "Uh Oh, Verification failed on the purchase -- handler");
                result = new BillingHandlerResult(BILLINGHELPER_VERIFICATION_FAILED,
                        "Signature verification failed for sku " + sku);
                if (purchaseListener != null)
                    purchaseListener.onPurchaseFinished(result, purchase);
                return true;
            }
        } catch (JSONException e) {
            Log.d("InAppPurchase", "Caught a JSON exception -- handler");
            e.printStackTrace();
            result = new BillingHandlerResult(BILLINGHELPER_BAD_RESPONSE, "Failed to parse purchase data.");
            if (purchaseListener != null)
                purchaseListener.onPurchaseFinished(result, null);
            return true;
        }

        if (purchaseListener != null) {
            Log.d("InAppPurchase", "Setting the purchase listener to OK -- handler");
            purchaseListener.onPurchaseFinished(new BillingHandlerResult(BILLING_RESPONSE_RESULT_OK, "Success"),
                    purchase);
        }
    } else if (resultCode == Activity.RESULT_OK) {
        // result code was OK, but in-app billing response was not OK.
        if (purchaseListener != null) {
            Log.d("InAppPurchase", "Problem purchasing the item -- handler");
            result = new BillingHandlerResult(responseCode, "Problem purchashing item.");
            purchaseListener.onPurchaseFinished(result, null);
        }
    } else if (resultCode == Activity.RESULT_CANCELED) {
        Log.d("InAppPurchase", "Purchase was canceled -- handler");
        result = new BillingHandlerResult(BILLINGHELPER_USER_CANCELLED, "User canceled.");
        if (purchaseListener != null)
            purchaseListener.onPurchaseFinished(result, null);
    } else {
        Log.d("InAppPurchase", "this was an unknown purchase -- handler");
        result = new BillingHandlerResult(BILLINGHELPER_UNKNOWN_PURCHASE_RESPONSE,
                "Unknown purchase response.");
        if (purchaseListener != null)
            purchaseListener.onPurchaseFinished(result, null);
    }
    return true;
}

From source file:com.intel.xdk.contacts.Contacts.java

public void contactsEditActivityResult(int requestCode, int resultCode, Intent intent) {
    //Contact EDITED
    if (resultCode == Activity.RESULT_OK) {
        getAllContacts();/*from  ww w . jav a2  s . c o m*/
        String js = String.format(
                "var e = document.createEvent('Events');e.initEvent('intel.xdk.contacts.edit',true,true);e.success=true;e.contactid='%s';document.dispatchEvent(e);",
                contactBeingEdited);
        injectJS("javascript:" + js);
        busy = false;
    }
    //Contact not Added
    else {
        String js = String.format(
                "javascript: var e = document.createEvent('Events');e.initEvent('intel.xdk.contacts.edit',true,true);e.success=false;e.cancelled=true;e.contactid='%s';document.dispatchEvent(e);",
                contactBeingEdited);
        injectJS(js);
        busy = false;
    }
    contactBeingEdited = "";
}

From source file:com.doplgangr.secrecy.settings.SettingsFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case REQUEST_CODE_SET_VAULT_ROOT:
        // If the file selection was successful
        if (resultCode == Activity.RESULT_OK) {
            if (data != null) {
                // Get the URI of the selected file
                final Uri uri = data.getData();
                try {
                    // Get the file path from the URI
                    final String path = FileUtils.getPath(context, uri);
                    Storage.setRoot(path);
                    Preference vault_root = findPreference(Config.VAULT_ROOT);
                    vault_root.setSummary(Storage.getRoot().getAbsolutePath());
                } catch (Exception e) {
                    Log.e("SettingsFragment", "File select error", e);
                }//from w  w  w .  ja  v  a2s  . c  o m
            }
        }
        break;
    case REQUEST_CODE_MOVE_VAULT:
        if (resultCode == Activity.RESULT_OK) {
            if (data != null) {
                // Get the URI of the selected file
                final Uri uri = data.getData();
                try {
                    // Get the file path from the URI
                    final String path = FileUtils.getPath(context, uri);
                    if (path.contains(Storage.getRoot().getAbsolutePath())) {
                        Util.alert(context, getString(R.string.Settings__cannot_move_vault),
                                getString(R.string.Settings__cannot_move_vault_message),
                                Util.emptyClickListener, null);
                        break;
                    }
                    Util.alert(context, getString(R.string.Settings__move_vault),
                            String.format(getString(R.string.move_message), Storage.getRoot().getAbsolutePath(),
                                    path),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    String[] children = new File(path).list();
                                    if (children.length == 0) {
                                        final ProgressDialog progressDialog = ProgressDialog.show(context, null,
                                                context.getString(R.string.Settings__moving_vault), true);
                                        new Thread(new Runnable() {
                                            public void run() {
                                                moveStorageRoot(path, progressDialog);
                                            }
                                        }).start();
                                    } else
                                        Util.alert(context, getString(R.string.Error__files_exist),
                                                getString(R.string.Error__files_exist_message),
                                                Util.emptyClickListener, null);
                                }
                            }, Util.emptyClickListener);
                } catch (Exception e) {
                    Log.e("SettingsFragment", "File select error", e);
                }
            }
        }
        break;
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:fr.bde_eseo.eseomega.events.tickets.PresalesActivity.java

/**
 * Called when called Activities (child) finished
 *///from ww w.j  a  v  a  2  s  .c  o  m
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    // From Lydia-Activity
    if (requestCode == Constants.RESULT_LYDIA_KEY) {

        if (LydiaActivity.LAST_STATUS() == 2) {
            new MaterialDialog.Builder(context).title("Flicitations !").content(
                    "Votre rservation a t paye.\nEntrez ci-dessous votre email afin de recevoir votre place au format PDF.\n\nNote : vous pouvez galement accder  cette fentre depuis l'historique des rservations)")
                    .cancelable(false).inputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS)
                    .input("sterling@archer.fr", "", new MaterialDialog.InputCallback() {
                        @Override
                        public void onInput(MaterialDialog dialog, CharSequence input) {
                            AsyncEventEmail asyncEmail = new AsyncEventEmail(context, "" + input,
                                    PresalesActivity.this, userProfile, idcmd); // convert charSequence into String object
                            asyncEmail.execute();
                        }
                    }).show();
        } else {
            new MaterialDialog.Builder(context).title("chec de la rservation").content(
                    "Le paiement n'a pas abouti.\nImpossible de valider la transaction.\n\nRessayez plus tard ou contactez un membre du BDE.")
                    .cancelable(false).negativeText(R.string.dialog_close)
                    .callback(new MaterialDialog.ButtonCallback() {
                        @Override
                        public void onNegative(MaterialDialog dialog) {
                            super.onNegative(dialog);
                            PresalesActivity.this.finish();
                        }
                    }).show();
        }

        // From Shuttle-Activity
    } else if (requestCode == Constants.RESULT_SHUTTLES_KEY && resultCode == Activity.RESULT_OK) {

        // Get shuttle ID
        final String shuttleID = String.valueOf(data.getExtras().getInt(Constants.RESULT_SHUTTLES_VALUE));
        final String shuttleName = data.getExtras().getString(Constants.RESULT_SHUTTLES_NAME);

        // Ask for user confirmation
        new MaterialDialog.Builder(context).title("Confirmer l'achat").content(eventName + "\n" + ticketName
                + "\n" + shuttleName + "\n\n"
                + "Les places seront nominatives.\nVotre carte tudiante vous sera demande  l'entre.\nLes CGV s'appliquent.")
                .positiveText(R.string.dialog_pay).negativeText(R.string.dialog_cancel)
                .callback(new MaterialDialog.ButtonCallback() {
                    @Override
                    public void onPositive(MaterialDialog dialog) {
                        super.onPositive(dialog);

                        // Send network request
                        AsyncSendTicket asyncSendTicket = new AsyncSendTicket(context);
                        asyncSendTicket.execute(eventID, shuttleID);
                    }
                }).show();
    }
}

From source file:au.gov.ga.worldwind.androidremote.client.Remote.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case REQUEST_DEVICES:
        // When DeviceListActivity returns with a device to connect
        devicesShowing = false;/*from w  w w .  ja  va  2  s  .co  m*/
        if (resultCode == Activity.RESULT_OK) {
            // Get the device MAC address
            String address = data.getExtras().getString(Devices.EXTRA_DEVICE_ADDRESS);
            // Get the BLuetoothDevice object
            BluetoothDevice device = bluetoothAdapter.getRemoteDevice(address);
            // Attempt to connect to the device
            communicator.connect(device);
        }
        break;
    case REQUEST_ENABLE_BT:
        // When the request to enable Bluetooth returns
        if (resultCode == Activity.RESULT_OK) {
            // Bluetooth is now enabled
        } else {
            // User did not enable Bluetooth or an error occured
            Toast.makeText(this, R.string.bluetooth_disabled, Toast.LENGTH_LONG).show();
            finish();
        }
    }
}

From source file:com.groundupworks.wings.facebook.FacebookEndpoint.java

/**
 * Finishes a {@link com.groundupworks.wings.facebook.FacebookEndpoint#startSettingsRequest(android.app.Activity, android.support.v4.app.Fragment)}.
 *
 * @param requestCode the integer request code originally supplied to startActivityForResult(), allowing you to identify who
 *                    this result came from.
 * @param resultCode  the integer result code returned by the child activity through its setResult().
 * @param data        an Intent, which can return result data to the caller (various data can be attached to Intent
 *                    "extras")./* ww w.j av a 2 s  . c  om*/
 * @return the settings; or null if failed.
 */
private FacebookSettings finishSettingsRequest(int requestCode, int resultCode, Intent data) {
    FacebookSettings settings = null;

    if (requestCode == SETTINGS_REQUEST_CODE && resultCode == Activity.RESULT_OK && data != null) {
        // Construct settings from the extras bundle.
        settings = FacebookSettings.newInstance(data.getExtras());
    }
    return settings;
}

From source file:fm.smart.r1.activity.ItemActivity.java

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // this should be called once image has been chosen by user
    // using requestCode to pass item id - haven't worked out any other way
    // to do it//from   w ww . j  av a2s  .com
    // if (requestCode == SELECT_IMAGE)
    if (resultCode == Activity.RESULT_OK) {
        // TODO check if user is logged in
        if (Main.isNotLoggedIn(this)) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setClassName(this, LoginActivity.class.getName());
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            // avoid navigation back to this?
            LoginActivity.return_to = ItemActivity.class.getName();
            LoginActivity.params = new HashMap<String, String>();
            LoginActivity.params.put("item_id", (String) item.item_node.atts.get("id"));
            startActivity(intent);
            // TODO in this case forcing the user to rechoose the image
            // seems a little
            // rude - should probably auto-submit here ...
        } else {
            // Bundle extras = data.getExtras();
            // String sentence_id = (String) extras.get("sentence_id");
            final ProgressDialog myOtherProgressDialog = new ProgressDialog(this);
            myOtherProgressDialog.setTitle("Please Wait ...");
            myOtherProgressDialog.setMessage("Uploading image ...");
            myOtherProgressDialog.setIndeterminate(true);
            myOtherProgressDialog.setCancelable(true);

            final Thread add_image = new Thread() {
                public void run() {
                    // TODO needs to check for interruptibility

                    String sentence_id = Integer.toString(requestCode);
                    Uri selectedImage = data.getData();
                    // Bitmap bitmap = Media.getBitmap(getContentResolver(),
                    // selectedImage);
                    // ByteArrayOutputStream bytes = new
                    // ByteArrayOutputStream();
                    // bitmap.compress(Bitmap.CompressFormat.JPEG, 40,
                    // bytes);
                    // ByteArrayInputStream fileInputStream = new
                    // ByteArrayInputStream(
                    // bytes.toByteArray());

                    // TODO Might have to save to file system first to get
                    // this
                    // to work,
                    // argh!
                    // could think of it as saving to cache ...

                    // add image to sentence
                    FileInputStream is = null;
                    FileOutputStream os = null;
                    File file = null;
                    ContentResolver resolver = getContentResolver();
                    try {
                        Bitmap bitmap = Media.getBitmap(getContentResolver(), selectedImage);
                        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                        bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
                        // ByteArrayInputStream bais = new
                        // ByteArrayInputStream(bytes.toByteArray());

                        // FileDescriptor fd =
                        // resolver.openFileDescriptor(selectedImage,
                        // "r").getFileDescriptor();
                        // is = new FileInputStream(fd);

                        String filename = "test.jpg";
                        File dir = ItemActivity.this.getDir("images", MODE_WORLD_READABLE);
                        file = new File(dir, filename);
                        os = new FileOutputStream(file);

                        // while (bais.available() > 0) {
                        // / os.write(bais.read());
                        // }
                        os.write(bytes.toByteArray());

                        os.close();

                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } finally {
                        if (os != null) {
                            try {
                                os.close();
                            } catch (IOException e) {
                            }
                        }
                        if (is != null) {
                            try {
                                is.close();
                            } catch (IOException e) {
                            }
                        }
                    }

                    // File file = new
                    // File(Uri.decode(selectedImage.toString()));

                    // ensure item is in users default list

                    ItemActivity.add_item_result = addItemToList(Main.default_study_list_id,
                            (String) item.item_node.atts.get("id"), ItemActivity.this);
                    Result result = ItemActivity.add_item_result;

                    if (ItemActivity.add_item_result.success()
                            || ItemActivity.add_item_result.alreadyInList()) {

                        // ensure sentence is in users default list

                        ItemActivity.add_sentence_list_result = addSentenceToList(sentence_id,
                                (String) item.item_node.atts.get("id"), Main.default_study_list_id,
                                ItemActivity.this);
                        result = ItemActivity.add_sentence_list_result;
                        if (ItemActivity.add_sentence_list_result.success()) {

                            String media_entity = "http://test.com/test.jpg";
                            String author = "tansaku";
                            String author_url = "http://smart.fm/users/tansaku";
                            Log.d("DEBUG-IMAGE-URI", selectedImage.toString());
                            ItemActivity.add_image_result = addImage(file, media_entity, author, author_url,
                                    "1", sentence_id, (String) item.item_node.atts.get("id"),
                                    Main.default_study_list_id);
                            result = ItemActivity.add_image_result;
                        }
                    }
                    final Result display = result;
                    myOtherProgressDialog.dismiss();
                    ItemActivity.this.runOnUiThread(new Thread() {
                        public void run() {
                            final AlertDialog dialog = new AlertDialog.Builder(ItemActivity.this).create();
                            dialog.setTitle(display.getTitle());
                            dialog.setMessage(display.getMessage());
                            dialog.setButton("OK", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    if (ItemActivity.add_image_result != null
                                            && ItemActivity.add_image_result.success()) {
                                        ItemListActivity.loadItem(ItemActivity.this,
                                                item.item_node.atts.get("id").toString());
                                    }
                                }
                            });

                            dialog.show();
                        }
                    });

                }

            };

            myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    add_image.interrupt();
                }
            });
            OnCancelListener ocl = new OnCancelListener() {
                public void onCancel(DialogInterface arg0) {
                    add_image.interrupt();
                }
            };
            myOtherProgressDialog.setOnCancelListener(ocl);
            closeMenu();
            myOtherProgressDialog.show();
            add_image.start();

        }
    }
}

From source file:com.arantius.tivocommander.ShowList.java

protected void setRefreshResult() {
    Intent resultIntent = new Intent();
    resultIntent.putExtra("refresh", true);
    setResult(Activity.RESULT_OK, resultIntent);
}

From source file:com.abcvoipsip.ui.account.AccountsEditListFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK && data != null && data.getExtras() != null) {

        if (requestCode == CHOOSE_WIZARD) {
            // Wizard has been choosen, now create an account
            String wizardId = data.getStringExtra(WizardUtils.ID);
            if (wizardId != null) {
                showDetails(SipProfile.INVALID_ID, wizardId);
            }//from w ww.j a va  2  s . c  om
        } else if (requestCode == CHANGE_WIZARD) {
            // Change wizard done for this account.
            String wizardId = data.getStringExtra(WizardUtils.ID);
            long accountId = data.getLongExtra(Intent.EXTRA_UID, SipProfile.INVALID_ID);

            if (wizardId != null && accountId != SipProfile.INVALID_ID) {
                ContentValues cv = new ContentValues();
                cv.put(SipProfile.FIELD_WIZARD, wizardId);
                getActivity().getContentResolver().update(
                        ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, accountId), cv, null, null);

            }

        }
    }

}

From source file:com.jaspersoft.android.jaspermobile.activities.profile.ServerProfileActivity.java

private void setOkResult() {
    Intent resultIntent = new Intent();
    resultIntent.putExtra(ServersFragment.EXTRA_SERVER_PROFILE_ID, profileId);
    setResult(Activity.RESULT_OK, resultIntent);
}