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.sdspikes.fireworks.FireworksActivity.java
private void handleSelectPlayersResult(int response, Intent data) { if (response != Activity.RESULT_OK) { Log.w(TAG, "*** select players UI cancelled, " + response); switchToMainScreen();/*from w w w . j ava2 s. c o m*/ return; } Log.d(TAG, "Select players UI succeeded."); // get the invitee list final ArrayList<String> invitees = data.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS); Log.d(TAG, "Invitee count: " + invitees.size()); // get the automatch criteria Bundle autoMatchCriteria = null; int minAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, 0); int maxAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MAX_AUTOMATCH_PLAYERS, 0); if (minAutoMatchPlayers > 0 || maxAutoMatchPlayers > 0) { autoMatchCriteria = RoomConfig.createAutoMatchCriteria(minAutoMatchPlayers, maxAutoMatchPlayers, 0); Log.d(TAG, "Automatch criteria: " + autoMatchCriteria); } // create the room Log.d(TAG, "Creating room..."); RoomConfig.Builder rtmConfigBuilder = RoomConfig.builder(this); rtmConfigBuilder.addPlayersToInvite(invitees); rtmConfigBuilder.setMessageReceivedListener(this); rtmConfigBuilder.setRoomStatusUpdateListener(this); if (autoMatchCriteria != null) { rtmConfigBuilder.setAutoMatchCriteria(autoMatchCriteria); } switchToScreen(R.id.screen_wait); keepScreenOn(); resetGameVars(); Games.RealTimeMultiplayer.create(mGoogleApiClient, rtmConfigBuilder.build()); Log.d(TAG, "Room created, waiting for it to be ready..."); }
From source file:app.wz.MainActivity.java
public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == BluetoothState.REQUEST_CONNECT_DEVICE) { if (resultCode == Activity.RESULT_OK) { commStatus.setText("Status : Connecting ... "); prefs.edit().putString("lastBT", data.getExtras().getString(BluetoothState.EXTRA_DEVICE_ADDRESS)) .commit();//from www. jav a 2 s. co m bt.connect(data); String adr = prefs.getString("lastBT", null); // // if(adr != null) { // bt.connect(adr); // } } } else if (requestCode == BluetoothState.REQUEST_ENABLE_BT) { if (resultCode == Activity.RESULT_OK) { bt.setupService(); bt.startService(BluetoothState.DEVICE_ANDROID); setup(); } else { Toast.makeText(getApplicationContext(), "Bluetooth was not enabled.", Toast.LENGTH_SHORT).show(); finish(); } } }
From source file:com.layer.atlas.messenger.AtlasMessagesScreen.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (debug)//ww w. j a va 2s .c o m Log.w(TAG, "onActivityResult() requestCode: " + requestCode + ", resultCode: " + resultCode + ", uri: " + (data == null ? "" : data.getData()) + ", data: " + (data == null ? "" : MessengerApp.toString(data.getExtras()))); if (resultCode != Activity.RESULT_OK) return; final LayerClient layerClient = ((MessengerApp) getApplication()).getLayerClient(); switch (requestCode) { case REQUEST_CODE_CAMERA: if (photoFile == null) { if (debug) Log.w(TAG, "onActivityResult() taking photo, but output is undefined... "); return; } if (!photoFile.exists()) { if (debug) Log.w(TAG, "onActivityResult() taking photo, but photo file doesn't exist: " + photoFile.getPath()); return; } if (photoFile.length() == 0) { if (debug) Log.w(TAG, "onActivityResult() taking photo, but photo file is empty: " + photoFile.getPath()); return; } try { // prepare original final File originalFile = photoFile; FileInputStream fisOriginal = new FileInputStream(originalFile) { public void close() throws IOException { super.close(); boolean deleted = originalFile.delete(); if (debug) Log.w(TAG, "close() original file is" + (!deleted ? " not" : "") + " removed: " + originalFile.getName()); photoFile = null; } }; final MessagePart originalPart = layerClient.newMessagePart(Atlas.MIME_TYPE_IMAGE_JPEG, fisOriginal, originalFile.length()); File tempDir = getCacheDir(); MessagePart[] previewAndSize = Atlas.buildPreviewAndSize(originalFile, layerClient, tempDir); if (previewAndSize == null) { Log.e(TAG, "onActivityResult() cannot build preview, cancel send..."); return; } Message msg = layerClient.newMessage(originalPart, previewAndSize[0], previewAndSize[1]); if (debug) Log.w(TAG, "onActivityResult() sending photo... "); preparePushMetadata(msg); conv.send(msg); } catch (Exception e) { Log.e(TAG, "onActivityResult() cannot insert photo" + e); } break; case REQUEST_CODE_GALLERY: if (data == null) { if (debug) Log.w(TAG, "onActivityResult() insert from gallery: no data... :( "); return; } // first check media gallery Uri selectedImageUri = data.getData(); // TODO: Mi4 requires READ_EXTERNAL_STORAGE permission for such operation String selectedImagePath = getGalleryImagePath(selectedImageUri); String resultFileName = selectedImagePath; if (selectedImagePath != null) { if (debug) Log.w(TAG, "onActivityResult() image from gallery selected: " + selectedImagePath); } else if (selectedImageUri.getPath() != null) { if (debug) Log.w(TAG, "onActivityResult() image from file picker appears... " + selectedImageUri.getPath()); resultFileName = selectedImageUri.getPath(); } if (resultFileName != null) { String mimeType = Atlas.MIME_TYPE_IMAGE_JPEG; if (resultFileName.endsWith(".png")) mimeType = Atlas.MIME_TYPE_IMAGE_PNG; if (resultFileName.endsWith(".gif")) mimeType = Atlas.MIME_TYPE_IMAGE_GIF; // test file copy locally try { // create message and upload content InputStream fis = null; File fileToUpload = new File(resultFileName); if (fileToUpload.exists()) { fis = new FileInputStream(fileToUpload); } else { if (debug) Log.w(TAG, "onActivityResult() file to upload doesn't exist, path: " + resultFileName + ", trying ContentResolver"); fis = getContentResolver().openInputStream(data.getData()); if (fis == null) { if (debug) Log.w(TAG, "onActivityResult() cannot open stream with ContentResolver, uri: " + data.getData()); } } String fileName = "galleryFile" + System.currentTimeMillis() + ".jpg"; final File originalFile = new File( getExternalFilesDir(android.os.Environment.DIRECTORY_PICTURES), fileName); OutputStream fos = new FileOutputStream(originalFile); int totalBytes = Tools.streamCopyAndClose(fis, fos); if (debug) Log.w(TAG, "onActivityResult() copied " + totalBytes + " to file: " + originalFile.getName()); FileInputStream fisOriginal = new FileInputStream(originalFile) { public void close() throws IOException { super.close(); boolean deleted = originalFile.delete(); if (debug) Log.w(TAG, "close() original file is" + (!deleted ? " not" : "") + " removed: " + originalFile.getName()); } }; final MessagePart originalPart = layerClient.newMessagePart(mimeType, fisOriginal, originalFile.length()); File tempDir = getCacheDir(); MessagePart[] previewAndSize = Atlas.buildPreviewAndSize(originalFile, layerClient, tempDir); if (previewAndSize == null) { Log.e(TAG, "onActivityResult() cannot build preview, cancel send..."); return; } Message msg = layerClient.newMessage(originalPart, previewAndSize[0], previewAndSize[1]); if (debug) Log.w(TAG, "onActivityResult() uploaded " + originalFile.length() + " bytes"); preparePushMetadata(msg); conv.send(msg); } catch (Exception e) { Log.e(TAG, "onActivityResult() cannot upload file: " + resultFileName, e); return; } } break; default: break; } }
From source file:com.tuxpan.foregroundcameragalleryplugin.ForegroundCameraLauncher.java
/** * Called when the camera view exits.//from w ww. ja v a 2s .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; int rotate = 0; // If CAMERA if (srcType == CAMERA) { // 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(); try { if (this.encodingType == JPEG) { exif.createInFile(getTempDirectoryPath() + "/.Pic.jpg"); exif.readExifData(); rotate = exif.getOrientation(); } } catch (IOException e) { e.printStackTrace(); } Bitmap bitmap = null; Uri uri = null; // If sending base64 image back if (destType == DATA_URL) { bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString())); if (bitmap == null) { // Try to get the bitmap from intent. bitmap = (Bitmap) intent.getExtras().get("data"); } // Double-check the bitmap. if (bitmap == null) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to create bitmap!"); return; } if (rotate != 0 && this.correctOrientation) { bitmap = getRotatedBitmap(rotate, bitmap, exif); } this.processPicture(bitmap); checkForDuplicateImage(DATA_URL); } // If sending filename back else if (destType == FILE_URI || destType == NATIVE_URI) { if (this.saveToPhotoAlbum) { Uri inputUri = getUriFromMediaStore(); //Just because we have a media URI doesn't mean we have a real file, we need to make it uri = Uri.fromFile(new File(FileHelper.getRealPath(inputUri, this.cordova))); } else { uri = Uri.fromFile( new File(getTempDirectoryPath(), System.currentTimeMillis() + ".jpg")); } if (uri == null) { this.failPicture("Error capturing image - no media storage found."); } // If all this is true we shouldn't compress the image. if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100 && !this.correctOrientation) { writeUncompressedImage(uri); this.callbackContext.success(uri.toString()); } else { bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString())); if (rotate != 0 && this.correctOrientation) { bitmap = getRotatedBitmap(rotate, bitmap, exif); } // 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 if (this.encodingType == JPEG) { String exifPath; if (this.saveToPhotoAlbum) { exifPath = FileHelper.getRealPath(uri, this.cordova); } else { exifPath = uri.getPath(); } exif.createOutFile(exifPath); exif.writeExifData(); } } // Send Uri back to JavaScript for viewing image this.callbackContext.success(uri.toString()); } this.cleanup(FILE_URI, this.imageUri, uri, bitmap); bitmap = null; } 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(); // If you ask for video or all media type you will automatically get back a file URI // and there will be no attempt to resize any returned data if (this.mediaType != PICTURE) { this.callbackContext.success(uri.toString()); } else { // This is a special case to just return the path as no scaling, // rotating, nor compressing needs to be done if (this.targetHeight == -1 && this.targetWidth == -1 && (destType == FILE_URI || destType == NATIVE_URI) && !this.correctOrientation) { this.callbackContext.success(uri.toString()); } else { String uriString = uri.toString(); // Get the path to the image. Makes loading so much easier. String mimeType = FileHelper.getMimeType(uriString, this.cordova); // If we don't have a valid image so quit. if (!("image/jpeg".equalsIgnoreCase(mimeType) || "image/png".equalsIgnoreCase(mimeType))) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to retrieve path to picture!"); return; } Bitmap bitmap = null; try { bitmap = getScaledBitmap(uriString); } catch (IOException e) { e.printStackTrace(); } if (bitmap == null) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to create bitmap!"); return; } if (this.correctOrientation) { rotate = getImageOrientation(uri); if (rotate != 0) { // Matrix matrix = new Matrix(); // matrix.setRotate(rotate); // bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); RotateTask r = new RotateTask(bitmap, srcType, destType, rotate, intent); r.execute(); return; } } returnImageToProcess(bitmap, srcType, destType, intent, rotate); } } } else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Selection cancelled."); } else { this.failPicture("Selection did not complete!"); } } }
From source file:edu.asu.msse.sgowdru.moviemediaplayerrpc.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 1) { if (resultCode == Activity.RESULT_OK) { System.out.println("IN RESULT OK"); adapter.notifyDataSetChanged(); }/*from ww w.j ava 2 s . co m*/ } }
From source file:com.anjlab.android.iab.v3.BillingProcessor.java
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode != PURCHASE_FLOW_REQUEST_CODE) return false; int responseCode = data.getIntExtra(Constants.RESPONSE_CODE, Constants.BILLING_RESPONSE_RESULT_OK); Log.d(LOG_TAG, String.format("resultCode = %d, responseCode = %d", resultCode, responseCode)); String purchasePayload = getPurchasePayload(); if (resultCode == Activity.RESULT_OK && responseCode == Constants.BILLING_RESPONSE_RESULT_OK && !TextUtils.isEmpty(purchasePayload)) { String purchaseData = data.getStringExtra(Constants.INAPP_PURCHASE_DATA); String dataSignature = data.getStringExtra(Constants.RESPONSE_INAPP_SIGNATURE); try {//from w ww . java 2 s . c om JSONObject purchase = new JSONObject(purchaseData); String productId = purchase.getString(Constants.RESPONSE_PRODUCT_ID); String developerPayload = purchase.getString(Constants.RESPONSE_PAYLOAD); if (developerPayload == null) developerPayload = ""; boolean purchasedSubscription = purchasePayload.startsWith(Constants.PRODUCT_TYPE_SUBSCRIPTION); if (purchasePayload.equals(developerPayload)) { if (verifyPurchaseSignature(productId, purchaseData, dataSignature)) { BillingCache cache = purchasedSubscription ? cachedSubscriptions : cachedProducts; cache.put(productId, purchaseData, dataSignature); if (eventHandler != null) eventHandler.onProductPurchased(productId, new TransactionDetails(new PurchaseInfo(purchaseData, dataSignature))); } else { Log.e(LOG_TAG, "Public key signature doesn't match!"); if (eventHandler != null) eventHandler.onBillingError(Constants.BILLING_ERROR_INVALID_SIGNATURE, null); } } else { Log.e(LOG_TAG, String.format("Payload mismatch: %s != %s", purchasePayload, developerPayload)); if (eventHandler != null) eventHandler.onBillingError(Constants.BILLING_ERROR_INVALID_SIGNATURE, null); } } catch (Exception e) { Log.e(LOG_TAG, e.toString()); if (eventHandler != null) eventHandler.onBillingError(Constants.BILLING_ERROR_OTHER_ERROR, null); } } else { if (eventHandler != null) eventHandler.onBillingError(responseCode, null); } return true; }
From source file:edu.cmu.hcii.hangg.beeksbeacon.Fragments.ManageBeaconFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == Constants.REQUEST_CODE_PLACE_PICKER) { if (resultCode == Activity.RESULT_OK) { Place place = PlacePicker.getPlace(data, getActivity()); if (place == null) { return; }//w w w. j av a 2 s .c om // The place picker presents two selection options: "select this location" and // "nearby places". Only the nearby places selection returns a placeId we can // submit to the service; the location selection will return a hex-like 0xbeef // identifier for that position instead, which isn't what we want. Here we check // if the entire string is hex and clear the placeId if it is. String id = place.getId(); if (id.startsWith("0x") && id.matches("0x[0-9a-f]+")) { placeId.setText(""); beaconInstance.placeId = ""; } else { placeId.setText(id); beaconInstance.placeId = id; } LatLng placeLatLng = place.getLatLng(); latLng.setText(placeLatLng.toString()); beaconInstance.latitude = placeLatLng.latitude; beaconInstance.longitude = placeLatLng.longitude; updateBeacon(); } else { logErrorAndToast("Error loading place picker. Is the Places API enabled? " + "See https://developers.google.com/places/android-api/signup for more detail"); } } }
From source file:ca.ualberta.cmput301w14t08.geochan.fragments.PostFragment.java
/** * Handles the return from the camera activity * // ww w .j a v a 2 s .com * @param requestCode Type of activity requested * @param resultCode Code indicating activity success/failure * @param data Image data associated with the camera activity */ public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { if (requestCode == ImageHelper.REQUEST_CAMERA) { Bitmap imageBitmap = null; try { imageBitmap = BitmapFactory.decodeStream( getActivity().getContentResolver().openInputStream(Uri.fromFile(imageFile))); } catch (FileNotFoundException e) { Toaster.toastShort("Error. Could not load image."); } Bitmap squareBitmap = ThumbnailUtils.extractThumbnail(imageBitmap, 100, 100); image = scaleImage(imageBitmap); imageThumb = squareBitmap; Bundle bundle = getArguments(); bundle.putParcelable("IMAGE_THUMB", imageThumb); bundle.putParcelable("IMAGE_FULL", image); } else if (requestCode == ImageHelper.REQUEST_GALLERY) { Bitmap imageBitmap = null; try { imageBitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), data.getData()); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Bitmap squareBitmap = ThumbnailUtils.extractThumbnail(imageBitmap, 100, 100); image = scaleImage(imageBitmap); imageThumb = squareBitmap; Bundle bundle = getArguments(); bundle.putParcelable("IMAGE_THUMB", imageThumb); bundle.putParcelable("IMAGE_FULL", image); } } }
From source file:com.polyvi.xface.extension.messaging.XMessagingExt.java
/** * ??// www .java2 s . com * */ private void genSendSMSBroadreceiver() { if (null == mSendSMSBroadcastReceiver) { mSendSMSBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context arg0, Intent arg1) { // ? SMS_RESULT_STATUS status = SMS_RESULT_STATUS.NO_STATUS; switch (getResultCode()) { case Activity.RESULT_OK:// ??? status = SMS_RESULT_STATUS.SEND_SUCCESS; break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE:// status = SMS_RESULT_STATUS.ERROR_GENERIC_FAILURE; break; case SmsManager.RESULT_ERROR_NO_SERVICE:// ? status = SMS_RESULT_STATUS.ERROR_NO_SERVICE; break; case SmsManager.RESULT_ERROR_NULL_PDU:// PDU?? status = SMS_RESULT_STATUS.ERROR_NULL_PDU; break; case SmsManager.RESULT_ERROR_RADIO_OFF:// status = SMS_RESULT_STATUS.ERROR_RADIO_OFF; break; } resolveSMSSendResult(status); } }; } }
From source file:com.authorwjf.bounce.BluetoothChat.java
public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_CONNECT_DEVICE_SECURE: // When DeviceListActivity returns with a device to connect if (resultCode == Activity.RESULT_OK) { connectDevice(data, true);/*ww w . j a v a2 s .co m*/ } 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 occurred Toast.makeText(this, R.string.bt_not_enabled_leaving, Toast.LENGTH_SHORT).show(); } } }