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.gelecekonline.android.uploadornek.MainActivity.java

/**
 * Secilen resim bu methoda gelir/*w ww .  j  av a2  s  .  c  om*/
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        Uri selectedImageUri = data.getData();
        String filePath = null;

        try {
            String fileManagerString = selectedImageUri.getPath();

            String selectedImagePath = getPath(selectedImageUri);

            if (selectedImagePath != null) {
                filePath = selectedImagePath;
            } else if (fileManagerString != null) {
                filePath = fileManagerString;
            } else {
                Toast.makeText(getApplicationContext(), getString(R.string.unknown_path), Toast.LENGTH_LONG)
                        .show();
            }

            if (filePath != null) {
                decodeFile(filePath);
                dosyaAdi = FilenameUtils.getName(filePath);
            } else {
                bitmap = null;
            }
        } catch (Exception e) {
            Toast.makeText(getApplicationContext(), getString(R.string.internal_error), Toast.LENGTH_LONG)
                    .show();
            Log.e(e.getClass().getName(), e.getMessage(), e);
        }
    }
}

From source file:codepath.watsiapp.activities.BaseFragmentActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
        if (confirm != null) {
            try {
                showThankYouNote();/*from  www  . j a v  a  2 s.c  o m*/
                ParseObject confirmation = new ParseObject("PaymentConfirmatons");
                confirmation.put("donorName", getUserFullName());
                confirmation.put("donorEmail", getUserEmail());
                confirmation.put("patient", Patient.createWithoutData(Patient.class, getPatientId()));
                confirmation.put("amount", getDonationAmount());
                confirmation.put("confirmation", confirm.toJSONObject().toString(4));
                confirmation.put("isAnonymous", isAnonymousDonation());
                confirmation.saveInBackground();

                prefs.clear();

            } catch (JSONException e) {
                Log.e(TAG_PAYPAL, "an extremely unlikely failure occurred: ", e);
            }
        }
    } else if (resultCode == Activity.RESULT_CANCELED) {
        Log.i(TAG_PAYPAL, "The user canceled.");
    } else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
        Log.i(TAG_PAYPAL, "An invalid Payment or PayPalConfiguration was submitted. Please see the docs.");
    }
}

From source file:com.google.zxing.client.android.history.HistoryActivity.java

@Override
protected void onListItemClick(ListView l, View v, final int positionItemList, long id) {
    progDialog = new ProgressDialog(this);

    if (adapter.getItem(positionItemList).getResult() != null) {
        Intent intent = new Intent(this, CaptureActivity.class);
        intent.putExtra(Intents.History.ITEM_NUMBER, positionItemList);
        setResult(Activity.RESULT_OK, intent);

        AlertDialog.Builder builder2 = new AlertDialog.Builder(this, 3);
        builder2.setMessage(getBaseContext().getResources().getString(R.string.alerta_enviar_dado));
        builder2.setCancelable(true);/*from   www .  jav a2 s . c  o m*/
        builder2.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int i2) {

                /*
                 * mandando somente um dado para o servidor
                 */
                boolean conectado = verificaConexao();
                if (conectado) {
                    try {
                        progDialog.setTitle(
                                getBaseContext().getResources().getString(R.string.alerta_enviando_dado));
                        progDialog.setMessage(
                                getBaseContext().getResources().getString(R.string.alerta_dado_sendo_enviado));
                        progDialog.setIcon(android.R.drawable.ic_menu_upload);
                        progDialog.show();

                        String dado = adapter.getItem(positionItemList).getDisplay();
                        enviarItemHistorico(dado);

                    } catch (Exception ex) {
                        // TODO: handle exception
                        ex.printStackTrace();
                    }
                }
                dialog.dismiss();
                reloadHistoryItems();
            }
        });
        builder2.setNegativeButton(R.string.button_cancel, null);
        builder2.show();

    }

}

From source file:info.rynkowski.hamsterclient.ui.view.activity.FactFormActivity.java

@OnClick(R.id.btn_apply)
public void onApplyClicked(View view) {
    UiFact readFact = readFact();/*from w w  w  .  j av  a2s  .co  m*/
    Intent intent = FactFormActivity.this.getIntent();
    intent.putExtra(OUTPUT_EXTRAS_KEY_FACT, readFact);
    setResult(Activity.RESULT_OK, intent);
    finish();
}

From source file:com.google.android.gcm.demo.app.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
    ctx = context;/*from w  w  w .  j a  v a  2s.c o  m*/
    String messageType = gcm.getMessageType(intent);
    if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
        sendNotification("Send error: " + intent.getExtras().toString());
    } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
        sendNotification("Deleted messages on server: " + intent.getExtras().toString());
    } else {
        sendNotification("Received: " + intent.getExtras().toString());
        // "urn":"soundcloud:sounds:125","finished_at":"0001-01-01T00:00:00Z","last_played_at":"0001-01-01T00:00:00Z","progress":0}

        LLQueue queue = LLQueue.get();
        if (queue == null)
            return;

        //queue.loadListenLaterQueue();

        if (intent.hasExtra("set")) {
            String set = intent.getStringExtra("set");
            try {
                JSONObject obj = new JSONObject(set);
                String urn = obj.optString("urn");
                Log.d(TAG, "GCM set with urn:" + urn);

                if (!TextUtils.isEmpty(urn)) {
                    queue.addUrn(urn);
                }
            } catch (JSONException e) {
                Log.w(TAG, e);
            }

        } else if (intent.hasExtra("delete")) {
            String delete = intent.getStringExtra("delete");
            try {
                JSONObject obj = new JSONObject(delete);
                String urn = obj.optString("urn");
                Log.d(TAG, "GCM set with urn:" + urn);

                if (!TextUtils.isEmpty(urn)) {
                    queue.removeUrn(urn);
                }

            } catch (JSONException e) {
                Log.w(TAG, e);
            }
        } else if (intent.hasExtra("play")) {

            String play = intent.getStringExtra("play");
            try {
                JSONObject obj = new JSONObject(play);
                String urn = obj.optString("urn");
                String toggleAt = obj.optString("toggle_at");
                long progress = obj.optInt("progress", 0);

                Log.d(TAG, "GCM play with urn:" + urn + " ,togglet_at:" + toggleAt);

                Intent playIntent = new Intent();

                queue.playUrn(urn, progress);

                if (!TextUtils.isEmpty(toggleAt)) {
                    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'");//spec for RFC3339 (with fractional seconds)
                    try {
                        Date date = format.parse(toggleAt);

                        Log.d(TAG, "parsed date:" + date);

                        //                            AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
                        //                            alarmManager.set(AlarmManager.RTC_WAKEUP, date.getTime(), PendingIntent.getActivity(context, 0, playIntent, 0));
                    } catch (ParseException e) {
                        Log.w(TAG, e);
                    }
                } else {

                }

            } catch (JSONException e) {
                Log.w(TAG, e);
            }

        }
    }
    setResultCode(Activity.RESULT_OK);
}

From source file:fr.cph.stock.android.activity.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
    switch (resultCode) {
    case 100://from   w w w. j a  v  a 2s.c  om
        finish();
        break;
    case Activity.RESULT_OK:
        Bundle b = data.getExtras();
        portfolio = b.getParcelable("portfolio");
        ada.update(portfolio);
        break;
    }
}

From source file:com.nonstop.android.SoC.Facebook.Hackbook.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    /*//from   w w  w .  jav a  2 s.c om
     * if this is the activity result from authorization flow, do a call
     * back to authorizeCallback Source Tag: login_tag
     */
    case AUTHORIZE_ACTIVITY_RESULT_CODE: {
        Utility.mFacebook.authorizeCallback(requestCode, resultCode, data);
        break;
    }
    /*
     * if this is the result for a photo picker from the gallery, upload
     * the image after scaling it. You can use the Utility.scaleImage()
     * function for scaling
     */
    case PICK_EXISTING_PHOTO_RESULT_CODE: {
        if (resultCode == Activity.RESULT_OK) {
            Uri photoUri = data.getData();
            if (photoUri != null) {
                Bundle params = new Bundle();
                try {
                    params.putByteArray("photo", Utility.scaleImage(getApplicationContext(), photoUri));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                params.putString("caption", "NonstopSoC");
                Utility.mAsyncRunner.request("me/photos", params, "POST", new PhotoUploadListener(), null);
            } else {
                Toast.makeText(getApplicationContext(), "Error selecting image from the gallery.",
                        Toast.LENGTH_SHORT).show();
            }
        } else {
            Toast.makeText(getApplicationContext(), "No image selected for upload.", Toast.LENGTH_SHORT).show();
        }
        break;

    }
    }

}

From source file:cn.tycoon.lighttrans.fileManager.AbstractFilePickerActivity.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override//from   w ww  .j a  v  a2  s .c o  m
public void onFilesPicked(final List<Uri> files) {
    Intent i = new Intent();
    i.putExtra(EXTRA_ALLOW_MULTIPLE, true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        ClipData clip = null;
        for (Uri file : files) {
            if (clip == null) {
                clip = new ClipData("Paths", new String[] {}, new ClipData.Item(file));
            } else {
                clip.addItem(new ClipData.Item(file));
            }
        }
        i.setClipData(clip);
    } else {
        ArrayList<String> paths = new ArrayList<>();
        for (Uri file : files) {
            paths.add(file.toString());
        }
        i.putStringArrayListExtra(EXTRA_PATHS, paths);
    }

    setResult(Activity.RESULT_OK, i);
    finish();
}

From source file:jp.alessandro.android.iab.PurchaseFlowLauncher.java

private Purchase getPurchase(int resultCode, int responseCode, String purchaseData, String signature)
        throws BillingException {
    // Check the Billing response
    if (resultCode == Activity.RESULT_OK && responseCode == Constants.BILLING_RESPONSE_RESULT_OK) {
        return getPurchaseFromIntent(purchaseData, signature);
    }//from   w  ww . j a va  2  s.  c o m
    // Something happened while trying to purchase the item
    switch (resultCode) {
    case Activity.RESULT_OK:
        throw new BillingException(responseCode, Constants.ERROR_MSG_RESULT_OK);

    case Activity.RESULT_CANCELED:
        throw new BillingException(responseCode, Constants.ERROR_MSG_RESULT_CANCELED);

    default:
        throw new BillingException(resultCode,
                String.format(Locale.US, Constants.ERROR_MSG_RESULT_UNKNOWN, resultCode));
    }
}

From source file:com.facebook.android.Hackbook.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    /*/*from w  ww .  ja va  2  s.c om*/
     * if this is the activity result from authorization flow, do a call
     * back to authorizeCallback Source Tag: login_tag
     */
    case AUTHORIZE_ACTIVITY_RESULT_CODE: {
        Utility.mFacebook.authorizeCallback(requestCode, resultCode, data);
        break;
    }
    /*
     * if this is the result for a photo picker from the gallery, upload
     * the image after scaling it. You can use the Utility.scaleImage()
     * function for scaling
     */
    case PICK_EXISTING_PHOTO_RESULT_CODE: {
        if (resultCode == Activity.RESULT_OK) {
            Uri photoUri = data.getData();
            if (photoUri != null) {
                Bundle params = new Bundle();
                try {
                    params.putByteArray("photo", Utility.scaleImage(getApplicationContext(), photoUri));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                params.putString("caption", "FbAPIs Sample App photo upload");
                Utility.mAsyncRunner.request("me/photos", params, "POST", new PhotoUploadListener(), null);
            } else {
                Toast.makeText(getApplicationContext(), "Error selecting image from the gallery.",
                        Toast.LENGTH_SHORT).show();
            }
        } else {
            Toast.makeText(getApplicationContext(), "No image selected for upload.", Toast.LENGTH_SHORT).show();
        }
        break;
    }
    }
}