List of usage examples for android.app Activity RESULT_OK
int RESULT_OK
To view the source code for android.app Activity RESULT_OK.
Click Source Link
From source file:com.fuse.billing.android.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.//www . ja v a 2s .c om */ 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 (!verifyPurchase(sku, 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:ee.ioc.phon.android.speak.RecognizerIntentActivity.java
/** * Sets the RESULT_OK intent. Adds the recorded audio data if the caller has requested it * and the requested format is supported or unset. *//* w w w .ja va 2 s. c o m*/ private void setResultIntent(final Handler handler, ArrayList<String> matches) { Intent intent = new Intent(); if (mExtras.getBoolean(Extras.GET_AUDIO)) { String audioFormat = mExtras.getString(Extras.GET_AUDIO_FORMAT); if (audioFormat == null) { audioFormat = Constants.DEFAULT_AUDIO_FORMAT; } if (Constants.SUPPORTED_AUDIO_FORMATS.contains(audioFormat)) { try { FileOutputStream fos = openFileOutput(Constants.AUDIO_FILENAME, Context.MODE_PRIVATE); fos.write(mService.getCompleteRecordingAsWav()); fos.close(); Uri uri = Uri .parse("content://" + FileContentProvider.AUTHORITY + "/" + Constants.AUDIO_FILENAME); // TODO: not sure about the type (or if it's needed) intent.setDataAndType(uri, audioFormat); } catch (FileNotFoundException e) { Log.e(LOG_TAG, "FileNotFoundException: " + e.getMessage()); } catch (IOException e) { Log.e(LOG_TAG, "IOException: " + e.getMessage()); } } else { if (Log.DEBUG) { handler.sendMessage(createMessage(MSG_TOAST, String.format(getString(R.string.toastRequestedAudioFormatNotSupported), audioFormat))); } } } intent.putStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS, matches); setResult(Activity.RESULT_OK, intent); }
From source file:com.segma.trim.InAppBillingUtilities.InAppBillingHelper.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 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 ww .j a v a 2 s . c om*/ */ public boolean handleActivityResult(int requestCode, int resultCode, Intent data) { InAppBillingResult 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 InAppBillingResult(IABHELPER_BAD_RESPONSE, "Null data in IAB result"); if (mPurchaseListener != null) mPurchaseListener.onInAppBillingPurchaseFinished(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 InAppBillingResult(IABHELPER_UNKNOWN_ERROR, "IAB returned null purchaseData or dataSignature"); if (mPurchaseListener != null) mPurchaseListener.onInAppBillingPurchaseFinished(result, null); return true; } Purchase purchase = null; try { purchase = new Purchase(mPurchasingItemType, purchaseData, dataSignature); String sku = purchase.getStockKeepingUnit(); // Verify signature if (!Security.verifyPurchase(mSignatureBase64, purchaseData, dataSignature)) { logError("Purchase signature verification FAILED for sku " + sku); result = new InAppBillingResult(IABHELPER_VERIFICATION_FAILED, "Signature verification failed for sku " + sku); if (mPurchaseListener != null) mPurchaseListener.onInAppBillingPurchaseFinished(result, purchase); return true; } logDebug("Purchase signature successfully verified."); } catch (JSONException e) { logError("Failed to parse purchase data."); e.printStackTrace(); result = new InAppBillingResult(IABHELPER_BAD_RESPONSE, "Failed to parse purchase data."); if (mPurchaseListener != null) mPurchaseListener.onInAppBillingPurchaseFinished(result, null); return true; } if (mPurchaseListener != null) { mPurchaseListener.onInAppBillingPurchaseFinished( new InAppBillingResult(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 InAppBillingResult(responseCode, "Problem purchashing item."); mPurchaseListener.onInAppBillingPurchaseFinished(result, null); } } else if (resultCode == Activity.RESULT_CANCELED) { logDebug("Purchase canceled - Response: " + getResponseDesc(responseCode)); result = new InAppBillingResult(IABHELPER_USER_CANCELLED, "User canceled."); if (mPurchaseListener != null) mPurchaseListener.onInAppBillingPurchaseFinished(result, null); } else { logError("Purchase failed. Result code: " + Integer.toString(resultCode) + ". Response: " + getResponseDesc(responseCode)); result = new InAppBillingResult(IABHELPER_UNKNOWN_PURCHASE_RESPONSE, "Unknown purchase response."); if (mPurchaseListener != null) mPurchaseListener.onInAppBillingPurchaseFinished(result, null); } return true; }
From source file:com.nonstop.android.SoC.BluetoothChat.BluetoothChat.java
public void onActivityResult(int requestCode, int resultCode, Intent data) { if (D)// w w w .j a va 2s .c om Log.d(TAG, "onActivityResult " + resultCode); switch (requestCode) { case REQUEST_CONNECT_DEVICE_SECURE: // When DeviceListActivity returns with a device to connect if (resultCode == Activity.RESULT_OK) { connectDevice(data, true); } break; case REQUEST_CONNECT_DEVICE_INSECURE: // When DeviceListActivity returns with a device to connect if (resultCode == Activity.RESULT_OK) { connectDevice(data, false); } break; case REQUEST_ENABLE_BT: // When the request to enable Bluetooth returns if (resultCode == Activity.RESULT_OK) { // Bluetooth is now enabled, so set up a chat session setupChat(); } else { // User did not enable Bluetooth or an error occured Log.d(TAG, "BT not enabled"); Toast.makeText(this, R.string.bt_not_enabled_leaving, Toast.LENGTH_SHORT).show(); finish(); } /* * 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:flex.android.magiccube.activity.ActivityBattleMode.java
public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_CONNECT_DEVICE: // When DeviceListActivity returns with a device to connect if (resultCode == Activity.RESULT_OK) { // Get the device MAC address String address = data.getExtras().getString(ActivityClient.EXTRA_DEVICE_ADDRESS); // Get the BLuetoothDevice object BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address); // Attempt to connect to the device mChatService.connect(device); }/*from ww w.j a va 2 s .c o m*/ break; case REQUEST_ENABLE_BT: // When the request to enable Bluetooth returns if (resultCode == Activity.RESULT_OK) { // Bluetooth is now enabled, so set up a chat session setupChat(); Intent intent = new Intent(this, ActivityTab.class); startActivityForResult(intent, REQUEST_SETTING); } else { // User did not enable Bluetooth or an error occured Toast.makeText(this, R.string.bt_not_enabled_leaving, Toast.LENGTH_SHORT).show(); finish(); } break; case REQUEST_SETTING: if (resultCode == Activity.RESULT_OK) { // Log.e("ok","ok"); if (MagiccubePreference.GetPreference(MagiccubePreference.ServerOrClient, this) == 1) { /* * if (!mBluetoothAdapter.isEnabled()) { Intent enableIntent * = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); * startActivityForResult(enableIntent, REQUEST_ENABLE_BT); * // Otherwise, setup the chat session } else { if * (mChatService == null) setupChat(); } */ if (mBluetoothAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) { ensureDiscoverable(); } else { this.showWait("..."); } } else if (MagiccubePreference.GetPreference(MagiccubePreference.ServerOrClient, this) == 0) { String address = this .getSharedPreferences(MagiccubePreference.SHAREDPREFERENCES_NAME, Context.MODE_PRIVATE) .getString(MagiccubePreference.ServerAddress, ""); // Get the BLuetoothDevice object BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address); // Attempt to connect to the device mChatService.connect(device); } else { finish(); } } break; case REQUEST_DISCOVERABLE: // Log.e("resultCode", resultCode+""); if (resultCode > 0) { this.showWait("..."); } else { mHandler.sendEmptyMessage(NOT_ENABLE_DISCOVERY); } break; } }
From source file:com.safecell.HomeScreenActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if (requestCode == 1) { if (resultCode == Activity.RESULT_OK) { Uri selectedImage = data.getData(); // Log.v("Safecell :" + "selectedImage", "imagePath = " // + selectedImage); profileImageView.setImageBitmap(getImageFromURI(selectedImage)); }/* www.j a va 2s .c o m*/ } // //End Request code = 1 if (requestCode == 2 && resultCode == RESULT_OK) { Bitmap photo = (Bitmap) data.getExtras().get("data"); profileImageView.setImageBitmap(photo); } /* * if (requestCode == 2) { if (resultCode == -1) { * * if (outputFileUri == null) { //outputFileUri = (Uri) * data.getExtras().get(MediaStore.EXTRA_OUTPUT); * * Uri selectedImage = data.getData(); // Log.v("Safecell :" + * "selectedImage", "imagePath = " // + selectedImage); profileImageView * .setImageBitmap(getImageFromURI(selectedImage)); * * UIUtils.OkDialog(HomeScreenActivity.this, * "Capture image not available. outputuri: "+outputFileUri); * * } else { Uri selectedImage = Uri.parse(outputFileUri.getPath()); // * Log.v("Safecell :" + "selectedImage", "imagePath = " // + * selectedImage); profileImageView * .setImageBitmap(getImageFromURI(selectedImage)); } * * } } */ }
From source file:com.cordova.photo.CameraLauncher.java
/** * Called when the camera view exits.//from w ww . j ava 2 s .co 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"). */ 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 crop if (requestCode == CROP_CAMERA) { if (resultCode == Activity.RESULT_OK) { // // Send Uri back to JavaScript for viewing image this.callbackContext.success(croppedUri.toString()); croppedUri = null; } // If cancelled else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Camera cancelled."); } // If something else else { this.failPicture("Did not complete!"); } } // If CAMERA if (srcType == CAMERA) { // If image available if (resultCode == Activity.RESULT_OK) { try { this.processResultFromCamera(destType, intent); } 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 && intent != null) { this.processResultFromGallery(destType, intent); } else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Selection cancelled."); } else { this.failPicture("Selection did not complete!"); } } }
From source file:com.remobile.camera.CameraLauncher.java
/** * Called when the camera view exits./*from w w w . ja va 2 s . co 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"). */ public void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode >= cordova.IMAGE_PICKER_RESULT) { return; } // Get src and dest types from request code for a Camera Activity int srcType = (requestCode / 16) - 1; int destType = (requestCode % 16) - 1; // If Camera Crop if (requestCode >= CROP_CAMERA) { if (resultCode == Activity.RESULT_OK) { // Because of the inability to pass through multiple intents, this hack will allow us // to pass arcane codes back. destType = requestCode - CROP_CAMERA; try { processResultFromCamera(destType, intent); } catch (IOException e) { e.printStackTrace(); FLog.e(LOG_TAG, "Unable to write to file"); } } // If cancelled else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Camera cancelled."); } // If something else else { this.failPicture("Did not complete!"); } } // If CAMERA else if (srcType == CAMERA) { // If image available if (resultCode == Activity.RESULT_OK) { try { if (this.allowEdit) { Uri tmpFile = Uri.fromFile(new File(getTempDirectoryPath(), ".Pic.jpg")); performCrop(tmpFile, destType, intent); } else { this.processResultFromCamera(destType, intent); } } 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 && intent != null) { this.processResultFromGallery(destType, intent); } else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Selection cancelled."); } else { this.failPicture("Selection did not complete!"); } } }
From source file:br.com.brolam.cloudvision.ui.NoteVisionActivity.java
/** * Validar e salvar um NoteVision/*from w w w. j a va2 s . co m*/ */ private void saveNoteVision(Boolean finish) { String title = editTextTitle.getText().toString(); Date dateNow = new Date(); String content = editTextContent.getText().toString(); this.editTextTitle.setError(null); this.editTextContent.setError(null); if (!NoteVisionItem.checkContent(content)) { this.editTextContent.setError(getString(R.string.note_vision_validate_content_empty)); if (this.isCameraPlay()) { Toast.makeText(this, getString(R.string.note_vision_validate_content_empty), Toast.LENGTH_SHORT) .show(); } else { this.editTextContent.requestFocus(); } return; } else if (!NoteVision.checkTitle(title)) { this.editTextTitle.setError(getString(R.string.note_vision_validate_title_empty)); this.editTextTitle.requestFocus(); return; } boolean newNoteVision = this.noteVisionKey == null; //Salvar o Note Vision / Item e tambm atualizar a chave do Note Vision, //para que as prximas incluses dos itens sejam no mesmo Note Vision. HashMap<String, String> keys = this.cloudVisionProvider.setNoteVision(this.noteVisionKey, title, this.noteVisionItemKey, content, dateNow); this.noteVisionKey = keys.get(NOTE_VISION_KEY); this.noteVisionItemKey = keys.get(NOTE_VISION_ITEM_KEY); if (newNoteVision) this.appAnalyticsHelper.logNoteVisionAdded(TAG); //Solicitar a atualizao do Widget. NoteVisionSummaryWidget.notifyWidgetUpdate(this); //Retornar com a chave do NoteVision e item confirmado e encerrar a incluso. if (finish) { Intent intent = new Intent(); intent.putExtra(NOTE_VISION_KEY, this.noteVisionKey); intent.putExtra(NOTE_VISION_ITEM_KEY, this.noteVisionItemKey); setResult(Activity.RESULT_OK, intent); this.setLockScreenOrientation(false); this.finish(); } else { //Limpar a tela para a incluso de novos itens. newNoteVisionContent(); } }
From source file:com.devwang.logcabin.LogCabinMainActivity.java
public void onActivityResult(int requestCode, int resultCode, Intent data) { if (D)//from w w w.j a va 2 s. c om Log.d(TAG, "onActivityResult " + resultCode); switch (requestCode) { case REQUEST_CONNECT_DEVICE_SECURE: // When DeviceListActivity returns with a device to connect if (resultCode == Activity.RESULT_OK) { connectDevice(data, true); } break; case REQUEST_CONNECT_DEVICE_INSECURE: // When DeviceListActivity returns with a device to connect if (resultCode == Activity.RESULT_OK) { connectDevice(data, false); } break; case REQUEST_ENABLE_BT: // When the request to enable Bluetooth returns if (resultCode == Activity.RESULT_OK) { // Bluetooth is now enabled, so set up a chat session setupChat(); } else { // User did not enable Bluetooth or an error occured Log.d(TAG, "BT not enabled"); Toast.makeText(this, R.string.bt_not_enabled_leaving, Toast.LENGTH_SHORT).show(); finish(); } } }