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.zxing.qrcode.decoding.CaptureActivityHandler.java

@Override
public void handleMessage(Message message) {
    switch (message.what) {
    case R.id.auto_focus:
        // Log.d(TAG, "Got auto-focus message");
        // When one auto focus pass finishes, start another. This is the
        // closest thing to
        // continuous AF. It does seem to hunt a bit, but I'm not sure what
        // else to do.
        if (state == State.PREVIEW) {
            CameraManager.get().requestAutoFocus(this, R.id.auto_focus);
        }//ww  w. j a  va 2s. c  om
        break;
    case R.id.restart_preview:
        Log.d(TAG, "Got restart preview message");
        restartPreviewAndDecode();
        break;
    case R.id.decode_succeeded:
        Log.d(TAG, "Got decode succeeded message");
        state = State.SUCCESS;
        Bundle bundle = message.getData();
        Bitmap barcode = bundle == null ? null : (Bitmap) bundle.getParcelable(DecodeThread.BARCODE_BITMAP);
        final String str_result = ((Result) message.obj).getText();
        System.out.println("====str_result====" + str_result);
        String match = "^[0-9]{13}";
        boolean b = str_result.matches(match);
        // Toast.makeText(activity, ""+b, 1).show();
        // activity.handleDecode((Result) message.obj, barcode);
        if (b) {
            String url = RequestUrls.TIAOXING_CODE_URL.replace("[code]", str_result);
            FinalHttp fh = new FinalHttp();
            fh.get(url, new AjaxCallBack<Object>() {
                @Override
                public void onSuccess(Object t) {
                    // TODO Auto-generated method stub
                    super.onSuccess(t);
                    try {

                        System.out.println("===TIAOXING_CODE_URL====" + new JSONObject(t.toString()));
                        Intent tagIntent = new Intent(activity, TagdetialActivity.class);
                        tagIntent.putExtra("jsonStr", t.toString());
                        tagIntent.putExtra("barcodes", str_result);
                        tagIntent.putExtra("eid", eid);
                        tagIntent.putExtra("tag_ids", tag_ids);
                        activity.startActivity(tagIntent);
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }

                @Override
                public void onFailure(Throwable t, String strMsg) {
                    // TODO Auto-generated method stub
                    super.onFailure(t, strMsg);
                }
            });
        } else {
            try {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                // //// intent.setPackage("com.tencent.mm");//
                intent.putExtra(Intent.EXTRA_SUBJECT, "share");
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                // // 
                // intent.setData(Uri.parse("http://weixin.qq.com/r/o3w_sRvEMSVOhwrSnyCH"));
                intent.setData(Uri.parse(str_result));
                activity.startActivity(intent);
            } catch (Exception e) {
                Toast.makeText(activity, R.string.no_wechat_rem, Toast.LENGTH_SHORT).show();
            }
        }

        break;
    case R.id.decode_failed:
        // We're decoding as fast as possible, so when one decode fails,
        // start another.
        state = State.PREVIEW;
        CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode);
        break;
    case R.id.return_scan_result:
        Log.d(TAG, "Got return scan result message");
        activity.setResult(Activity.RESULT_OK, (Intent) message.obj);
        activity.finish();
        break;
    }
}

From source file:com.easibeacon.examples.shop.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_BLUETOOTH_ENABLE) {
        if (resultCode == Activity.RESULT_OK) {
            scanBeacons();/*from   ww  w  . j  a v  a 2  s.  c o m*/
        }
    }
}

From source file:de.dfki.iui.mmir.plugins.speech.android.AndroidSpeechRecognizer.java

private void getSupportedLanguages(CallbackContext callbackContext) {

    if (languageDetailsChecker == null) {
        languageDetailsChecker = new LanguageDetailsReceiver(callbackContext);
    } else {//from   w  w  w .  j  a va 2  s.  co m
        languageDetailsChecker.setCallbackContext(callbackContext);
    }

    // Create and launch get languages intent
    Intent detailsIntent = new Intent(RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS);
    cordova.getActivity().sendOrderedBroadcast(detailsIntent, null, languageDetailsChecker, null,
            Activity.RESULT_OK, null, null);
}

From source file:com.raspi.chatapp.ui.chatting.SendImageFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // if the user chose a image to be sent to the current buddy
    if (requestCode == ADD_PHOTO_CLICKED && resultCode == Activity.RESULT_OK) {
        if (data.getData() != null) {
            // one image was selected
            Message msg = new Message(data.getData());
            images.add(msg);//w w w  .j a v  a 2 s. c o m
            current = images.size() - 1;
        } else if (data.getClipData() != null) {
            // multiple images were selected
            ClipData clipData = data.getClipData();
            for (int i = 0; i < clipData.getItemCount(); i++)
                images.add(new Message(clipData.getItemAt(i).getUri()));
            current = images.size() - 1;
        }
    }
}

From source file:com.zion.htf.ui.DonateActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (Activity.RESULT_OK == resultCode) {
        PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
        if (null != confirm) {
            try {
                if (BuildConfig.DEBUG)
                    Log.i(DonateActivity.TAG, confirm.toJSONObject().toString(4));

                // TODO: send 'confirm' to your server for verification.
                // see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
                // for more details.
            } catch (JSONException e) {
                Log.e(DonateActivity.TAG, "an extremely unlikely failure occurred: ", e);
            }/*from w w w .ja  v  a2s  . c o  m*/
        }
    } else if (Activity.RESULT_CANCELED == resultCode) {
        if (BuildConfig.DEBUG)
            Log.i(DonateActivity.TAG, "The user canceled.");
    } else if (PaymentActivity.RESULT_PAYMENT_INVALID == resultCode) {
        Log.e(DonateActivity.TAG, "An invalid payment was submitted. Please see the docs.");
    }
}

From source file:com.snipme.record.Record.java

/**
 * Called when the video view exits.//from w w w  .j  a  v a 2 s  . c  o  m
 *
 * @param requestCode       The 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 intent            An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
 * @throws JSONException
 */
public void onActivityResult(int requestCode, int resultCode, final Intent intent) {
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == CAPTURE_VIDEO) {
            Log.i(TAG, "onActivityResult: Video Capture success");
            final Record that = this;
            Runnable captureVideo = new Runnable() {

                @Override
                public void run() {

                    Uri data = null;

                    if (intent != null) {
                        // Get the uri of the video clip
                        data = intent.getData();
                        Log.i(TAG, "onActivityResult: Uri: " + data);
                        Log.i(TAG, "Uri of the video file recorded");
                    }

                    if (data == null) {
                        File movie = new File(getTempDirectoryPath(), "Capture.avi");
                        data = Uri.fromFile(movie);
                    }

                    // create a file object from the uri
                    if (data == null) {
                        that.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Error: data is null"));
                    } else {
                        results.put(createMediaFile(data));

                        if (results.length() >= 1) {
                            // Send Uri back to JavaScript for viewing video
                            that.callbackContext
                                    .sendPluginResult(new PluginResult(PluginResult.Status.OK, results));
                        } else {
                            // still need to capture more video clips
                            //captureVideo(duration);
                        }
                    }
                }
            };
            this.cordova.getThreadPool().execute(captureVideo);
        }
    } else if (resultCode == Activity.RESULT_CANCELED) {

    }

}

From source file:bizapps.com.healthforusPatient.activity.RegisterActivity.java

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

    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == SELECT_FILE) {
            Bitmap photo;//from w w  w.  j a v  a  2 s  .c  o m
            try {
                photo = (Bitmap) MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(),
                        data.getData());
                Uri tempUri = getImageUri(getApplicationContext(), photo);
                imageUrls = (getRealPathFromURI(tempUri));
                tv_pic.setText(imageUrls);
            } catch (IOException e) {
                e.printStackTrace();
            }
            //                onSelectFromGalleryResult(data);
        } else if (requestCode == REQUEST_CAMERA) {
            //                onCaptureImageResult(data);
            Bitmap photo;

            photo = (Bitmap) data.getExtras().get("data");
            Uri tempUri = getImageUri(getApplicationContext(), photo);
            imageUrls = (getRealPathFromURI(tempUri));

        }
    }

    /*if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
    Bitmap photo = (Bitmap) data.getExtras().get("data");
    //imageView.setImageBitmap(photo);
    //knop.setVisibility(Button.VISIBLE);
            
            
    // CALL THIS METHOD TO GET THE URI FROM THE BITMAP
    Uri tempUri = getImageUri(getApplicationContext(), photo);
    m1 = getRealPathFromURI(tempUri);
            
    mStore.setCompoundDrawablesWithIntrinsicBounds(0,0,R.drawable.ok_filled,0);
    // CALL THIS METHOD TO GET THE ACTUAL PATH
    //file1 = new File(getRealPathFromURI(tempUri));
            
    //System.out.println(mImageCaptureUri);
    } else if (requestCode == CAMERA_REQUEST1 && resultCode == RESULT_OK) {
    Bitmap photo = (Bitmap) data.getExtras().get("data");
    //imageView.setImageBitmap(photo);
    //knop.setVisibility(Button.VISIBLE);
            
            
    // CALL THIS METHOD TO GET THE URI FROM THE BITMAP
    Uri tempUri = getImageUri(getApplicationContext(), photo);
    m2 = getRealPathFromURI(tempUri);
    mDoc.setCompoundDrawablesWithIntrinsicBounds(0,0,R.drawable.ok_filled,0);
    // CALL THIS METHOD TO GET THE ACTUAL PATH
    // file2 = new File(getRealPathFromURI(tempUri));
            
    //System.out.println(mImageCaptureUri);
    }*/
}

From source file:com.arquitetaweb.restaurantes.fragment.CardapioFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (Activity.RESULT_OK == resultCode) {
        carregarDadosJson(this.getView());
    }//www.j a v  a2  s  . c om
}

From source file:com.tdispatch.passenger.fragment.SearchAddressFragment.java

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

    if ((requestCode == Const.RequestCode.VOICE_RECOGNITION) && (resultCode == Activity.RESULT_OK)) {
        ArrayList<String> matches = intent.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        WebnetLog.d("size: " + matches.size());
        if (matches.size() > 0) {
            WebnetLog.d("1st: " + matches.get(0));
            EditText et = (EditText) mFragmentView.findViewById(R.id.address);
            et.setText(matches.get(0));/*from   w w w  . jav a 2 s.  c om*/
        }
    }
}

From source file:com.phonegap.CameraLauncher.java

/**
 * Called when the camera view exits. /*from  ww  w . ja v  a 2  s.  c  om*/
 * 
 * @param requestCode      The 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 intent         An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
 */
public void onActivityResult(int requestCode, int resultCode, Intent intent) {

    // Get src and dest types from request code
    int srcType = (requestCode / 16) - 1;
    int destType = (requestCode % 16) - 1;

    // If CAMERA
    if (srcType == CAMERA) {

        // If image available
        if (resultCode == Activity.RESULT_OK) {
            try {
                // Read in bitmap of captured image
                Bitmap bitmap = android.provider.MediaStore.Images.Media
                        .getBitmap(this.ctx.getContentResolver(), imageUri);

                // If sending base64 image back
                if (destType == DATA_URL) {
                    this.processPicture(bitmap);
                }

                // If sending filename back
                else if (destType == FILE_URI) {
                    // Create entry in media store for image
                    // (Don't use insertImage() because it uses default compression setting of 50 - no way to change it)
                    ContentValues values = new ContentValues();
                    values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
                    Uri uri = null;
                    try {
                        uri = this.ctx.getContentResolver()
                                .insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
                    } catch (UnsupportedOperationException e) {
                        System.out.println("Can't write to external media storage.");
                        try {
                            uri = this.ctx.getContentResolver().insert(
                                    android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
                        } catch (UnsupportedOperationException ex) {
                            System.out.println("Can't write to internal media storage.");
                            this.failPicture("Error capturing image - no media storage found.");
                            return;
                        }
                    }

                    // Add compressed version of captured image to returned media store Uri
                    OutputStream os = this.ctx.getContentResolver().openOutputStream(uri);
                    bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
                    os.close();

                    // Send Uri back to JavaScript for viewing image
                    this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId);
                }
                bitmap.recycle();
                bitmap = null;
                System.gc();
            } catch (IOException e) {
                e.printStackTrace();
                this.failPicture("Error capturing image.");
            }
        }

        // If cancelled
        else if (resultCode == Activity.RESULT_CANCELED) {
            this.failPicture("Camera cancelled.");
        }

        // If something else
        else {
            this.failPicture("Did not complete!");
        }
    }

    // If retrieving photo from library
    else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
        if (resultCode == Activity.RESULT_OK) {
            Uri uri = intent.getData();
            android.content.ContentResolver resolver = this.ctx.getContentResolver();
            // If sending base64 image back
            if (destType == DATA_URL) {
                try {
                    Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
                    this.processPicture(bitmap);
                    bitmap.recycle();
                    bitmap = null;
                    System.gc();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                    this.failPicture("Error retrieving image.");
                }
            }

            // If sending filename back
            else if (destType == FILE_URI) {
                this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId);
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {
            this.failPicture("Selection cancelled.");
        } else {
            this.failPicture("Selection did not complete!");
        }
    }
}