List of usage examples for android.app Activity RESULT_CANCELED
int RESULT_CANCELED
To view the source code for android.app Activity RESULT_CANCELED.
Click Source Link
From source file:com.microchip.pcs.DeviceScanActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_ENABLE_BT && resultCode == Activity.RESULT_CANCELED) { //User chose not to enable Bluetooth. finish(); //Destroy the activity - end the application return;//from www . j a v a 2s . c om } super.onActivityResult(requestCode, resultCode, data); //Pass the activity result up to the parent method }
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 w w w .j a va 2 s. co 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:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.MyHealthHubWithFragments.java
public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == MANAGE_XML_FILES) { switch (resultCode) { case Activity.RESULT_OK: if (data != null) { if (data.getBooleanExtra(ManageXMLFiles.MAPPING_CHANGED, true)) { if (D) Log.d(TAG, "Mapping file was changed."); // TODO rovingModule.reloadMACMapping(); }/* ww w .jav a 2s . co m*/ if (data.getBooleanExtra(ManageXMLFiles.SENSING_RULES_CHANGED, true)) { if (D) Log.d(TAG, "Sensing rules were changed."); // TODO mEnvSensingBinder.reloadXMLRules(); } } break; case Activity.RESULT_CANCELED: break; } } }
From source file:org.opendatakit.survey.android.activities.MediaCaptureAudioActivity.java
private void returnResult() { File sourceMedia = (uriFragmentToMedia != null) ? ODKFileUtils.getAsFile(appName, uriFragmentToMedia) : null;/*from w ww.j a va 2 s .co m*/ if (sourceMedia != null && sourceMedia.exists()) { Intent i = new Intent(); i.putExtra(URI_FRAGMENT, ODKFileUtils.asUriFragment(appName, sourceMedia)); String name = sourceMedia.getName(); i.putExtra(CONTENT_TYPE, MEDIA_CLASS + name.substring(name.lastIndexOf(".") + 1)); setResult(Activity.RESULT_OK, i); finish(); } else { WebLogger.getLogger(appName).e(t, ERROR_NO_FILE + ((uriFragmentToMedia != null) ? sourceMedia.getAbsolutePath() : "null mediaPath")); Toast.makeText(this, R.string.media_save_failed, Toast.LENGTH_SHORT).show(); setResult(Activity.RESULT_CANCELED); finish(); } }
From source file:com.vantiv.android.gms.samples.wallet.CheckoutActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // retrieve the error code, if available int errorCode = -1; if (data != null) { errorCode = data.getIntExtra(WalletConstants.EXTRA_ERROR_CODE, -1); }//from ww w .j a v a 2 s. com switch (requestCode) { case REQUEST_CODE_MASKED_WALLET: switch (resultCode) { case Activity.RESULT_OK: if (data != null) { MaskedWallet maskedWallet = data.getParcelableExtra(WalletConstants.EXTRA_MASKED_WALLET); launchConfirmationPage(maskedWallet); } break; case Activity.RESULT_CANCELED: break; default: handleError(errorCode); break; } break; case WalletConstants.RESULT_ERROR: handleError(errorCode); break; case LOAD_PAYMENT_DATA_REQUEST_CODE: switch (resultCode) { case Activity.RESULT_OK: PaymentData paymentData = PaymentData.getFromIntent(data); String token = paymentData.getPaymentMethodToken().getToken(); break; case Activity.RESULT_CANCELED: break; case AutoResolveHelper.RESULT_ERROR: Status status = AutoResolveHelper.getStatusFromIntent(data); // Log the status for debugging. // Generally, there is no need to show an error to // the user as the Google Payment API will do that. break; default: // Do nothing. } break; default: super.onActivityResult(requestCode, resultCode, data); break; } }
From source file:org.akvo.caddisfly.sensor.colorimetry.liquid.ColorimetryLiquidActivity.java
/** * Show an error message dialog./* w w w . ja v a2s. c o m*/ * * @param message the message to be displayed * @param bitmap any bitmap image to displayed along with error message */ private void showError(String message, final Bitmap bitmap) { releaseResources(); sound.playShortResource(R.raw.err); alertDialogToBeDestroyed = AlertUtil.showError(this, R.string.error, message, bitmap, R.string.retry, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { initializeTest(); } }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); releaseResources(); setResult(Activity.RESULT_CANCELED); finish(); } }, null); }
From source file:com.google.sample.beaconservice.MainActivityFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == Constants.REQUEST_CODE_PICK_ACCOUNT) { // Receiving a result from the AccountPicker if (resultCode == Activity.RESULT_OK) { String name = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); accountNameView.setText(name); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("accountName", name); editor.apply();/* ww w. j a va2s .com*/ } else if (resultCode == Activity.RESULT_CANCELED) { // The account picker dialog closed without selecting an account. // Notify users that they must pick an account to proceed. Toast.makeText(getActivity(), "Please pick an account", Toast.LENGTH_SHORT).show(); } } else if (requestCode == Constants.REQUEST_CODE_ENABLE_BLE) { if (resultCode == Activity.RESULT_OK) { createScanner(); } else if (resultCode == Activity.RESULT_CANCELED) { Toast.makeText(getActivity(), "Please enable Bluetooth", Toast.LENGTH_SHORT).show(); } } }
From source file:com.cloudstudio.camera.ForegroundCameraLauncher.java
/** * Called when the camera view exits.//from w w w. ja v a 2s . 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) { // If image available if (resultCode == Activity.RESULT_OK) { try { // Create an ExifHelper to save the exif data that is lost // during compression ExifHelper exif = new ExifHelper(); exif.createInFile( getTempDirectoryPath(this.cordova.getActivity().getApplicationContext()) + "/Pic.jpg"); exif.readExifData(); // Read in bitmap of captured image Bitmap bitmap; try { bitmap = android.provider.MediaStore.Images.Media .getBitmap(this.cordova.getActivity().getContentResolver(), imageUri); } catch (FileNotFoundException e) { Uri uri = intent.getData(); android.content.ContentResolver resolver = this.cordova.getActivity().getContentResolver(); bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri)); } bitmap = scaleBitmap(bitmap); // 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 { Log.d("camera", "external_content_uri:" + android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); uri = this.cordova.getActivity().getContentResolver() .insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); } catch (UnsupportedOperationException e) { LOG.d(LOG_TAG, "Can't write to external media storage."); try { uri = this.cordova.getActivity().getContentResolver() .insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values); } catch (UnsupportedOperationException ex) { LOG.d(LOG_TAG, "Can't write to internal media storage."); this.failPicture("Error capturing image - no media storage found."); return; } } Log.d("camera", "uri:" + uri.toString()); // Add compressed version of captured image to returned media // store Uri OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); // Restore exif data to file exif.createOutFile(getRealPathFromURI(uri, this.cordova)); exif.writeExifData(); // Send Uri back to JavaScript for viewing image this.callbackContext.success(getRealPathFromURI(uri, this.cordova)); bitmap.recycle(); bitmap = null; System.gc(); checkForDuplicateImage(); } 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!"); } }
From source file:com.ternup.caddisfly.activity.SurveyActivity.java
public void cancelSurvey() { if (isFormEmpty()) { setResult(Activity.RESULT_CANCELED); isCancelled = true;/*from w w w .j a v a 2 s .co m*/ finish(); } else { AlertUtils.askQuestion(this, R.string.closeSurvey, R.string.closeLocationSurvey, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { setResult(Activity.RESULT_CANCELED); finish(); } }, null); } }
From source file:org.gluu.super_gluu.app.MainActivityFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Toast.makeText(getActivity(), R.string.process_qr_code, Toast.LENGTH_SHORT).show(); switch (requestCode) { case IntentIntegrator.REQUEST_CODE: if (resultCode == Activity.RESULT_OK) { // showToastWithText(context.getString(R.string.process_qr_code)); // Parsing bar code reader result IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); if (BuildConfig.DEBUG) Log.d(TAG, "Parsing QR code result: " + result.toString()); OxPush2Request oxPush2Request = null; try { oxPush2Request = new Gson().fromJson(result.getContents(), OxPush2Request.class); } catch (Exception ex) { //skip exception there }/*from w w w.ja v a 2 s . c o m*/ onQrRequest(oxPush2Request); } if (resultCode == Activity.RESULT_CANCELED) { showToastWithText(context.getString(R.string.canceled_process_qr_code)); } break; } }