List of usage examples for android.content Intent getData
public @Nullable Uri getData()
From source file:cn.edu.nuc.seeworld.fg.ColorFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == CAMERA && resultCode == Activity.RESULT_OK && null != data) { String sdState = Environment.getExternalStorageState(); if (!sdState.equals(Environment.MEDIA_MOUNTED)) { return; }/*w w w .j a va2s . co m*/ String name = DateFormat.format("yyyyMMdd_hhmmss", Calendar.getInstance(Locale.CHINA)) + ".jpg"; Bundle bundle = data.getExtras(); //???? Bitmap bitmap = (Bitmap) bundle.get("data"); FileOutputStream fout = null; File file = new File("/sdcard/pintu/"); file.mkdirs(); String filename = file.getPath() + name; try { fout = new FileOutputStream(filename); pic_path = filename; bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fout); } catch (FileNotFoundException e) { e.printStackTrace(); } finally { try { fout.flush(); fout.close(); } catch (IOException e) { e.printStackTrace(); } } pic_imageView.setImageBitmap(bitmap); pic_imageView.setVisibility(View.VISIBLE); } if (requestCode == PHOTO && resultCode == Activity.RESULT_OK && null != data) { Uri selectedImage = data.getData(); String[] filePathColumns = { MediaStore.Images.Media.DATA }; Cursor c = this.getActivity().getContentResolver().query(selectedImage, filePathColumns, null, null, null); c.moveToFirst(); int columnIndex = c.getColumnIndex(filePathColumns[0]); String picturePath = c.getString(columnIndex); c.close(); //? Log.d("SEEWORLDTAG", picturePath); Bitmap bitmap = BitmapFactory.decodeFile(picturePath); pic_path = picturePath; pic_imageView.setImageBitmap(bitmap); pic_imageView.setVisibility(View.VISIBLE); } }
From source file:com.polyvi.xface.extension.camera.XCameraExt.java
private void cameraSucess(Intent intent) { try {//w ww . ja v a2s . c om Bitmap bitmap = null; try { //???imagebitmap if (mAllowEdit) { //??????Android??? //???URI Bundle extras = intent.getExtras(); if (extras != null) { bitmap = extras.getParcelable("data"); } //?????URI if ((bitmap == null) || (extras == null)) { bitmap = getCroppedBitmap(intent); } } else { // ???? bitmap = android.provider.MediaStore.Images.Media.getBitmap(getContext().getContentResolver(), mImageUri); } } catch (FileNotFoundException e) { Uri uri = intent.getData(); android.content.ContentResolver resolver = getContext().getContentResolver(); bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri)); } catch (IOException e) { mCallbackCtx.error("Can't open image"); } catch (OutOfMemoryError e) { XNotification notification = new XNotification(mExtensionContext.getSystemContext()); notification.alert("Size of Image is too large!", "Save Image Error", "OK", null, DURATION); mCallbackCtx.error("Size of image is too large"); return; } // ??? Bitmap scaleBitmap = scaleBitmap(bitmap); Uri uri = null; if (mDestType == DATA_URL) { processPicture(scaleBitmap); checkForDuplicateImage(DATA_URL); } else if (mDestType == FILE_URI || mDestType == NATIVE_URI) { if (!this.mSaveToPhotoAlbum) { String suffixName = null; if (mEncodingType == JPEG) { suffixName = ".jpg"; } else if (mEncodingType == PNG) { suffixName = ".png"; } else { throw new IllegalArgumentException("Invalid Encoding Type: " + mEncodingType); } String photoName = System.currentTimeMillis() + suffixName; uri = Uri.fromFile(new File(mWebContext.getWorkSpace(), photoName)); } else { uri = getUriFromMediaStore(); } if (uri == null) { mCallbackCtx.error("Error capturing image - no media storage found."); } // ? OutputStream os = getContext().getContentResolver().openOutputStream(uri); scaleBitmap.compress(Bitmap.CompressFormat.JPEG, mQuality, os); os.close(); // ??success callback XPathResolver pathResolver = new XPathResolver(uri.toString(), "", getContext()); mCallbackCtx.success(XConstant.FILE_SCHEME + pathResolver.resolve()); } scaleBitmap.recycle(); scaleBitmap = null; cleanup(FILE_URI, mImageUri, uri, bitmap); } catch (IOException e) { mCallbackCtx.error("Error capturing image."); } }
From source file:com.xorcode.andtweet.TweetListActivity.java
/** * Prepare query to the ContentProvider (to the database) and load List of Tweets with data * @param queryIntent// w ww . j a v a 2 s .c om * @param otherThread This method is being accessed from other thread * @param loadOneMorePage load one more page of tweets */ protected void queryListData(Intent queryIntent, boolean otherThread, boolean loadOneMorePage) { // The search query is provided as an "extra" string in the query intent // TODO maybe use mQueryString here... String queryString = queryIntent.getStringExtra(SearchManager.QUERY); Intent intent = getIntent(); if (MyLog.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "doSearchQuery; queryString=\"" + queryString + "\"; TimelineType=" + mTimelineType); } Uri contentUri = Tweets.CONTENT_URI; SelectionAndArgs sa = new SelectionAndArgs(); String sortOrder = Tweets.DEFAULT_SORT_ORDER; // Id of the last (oldest) tweet to retrieve long lastItemId = -1; if (queryString != null && queryString.length() > 0) { // Record the query string in the recent queries suggestions // provider SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, TimelineSearchSuggestionProvider.AUTHORITY, TimelineSearchSuggestionProvider.MODE); suggestions.saveRecentQuery(queryString, null); contentUri = Tweets.SEARCH_URI; contentUri = Uri.withAppendedPath(contentUri, Uri.encode(queryString)); } intent.putExtra(SearchManager.QUERY, queryString); if (!contentUri.equals(intent.getData())) { intent.setData(contentUri); } if (sa.nArgs == 0) { // In fact this is needed every time you want to load next page of // tweets. // So we have to duplicate here everything we set in // com.xorcode.andtweet.TimelineActivity.onOptionsItemSelected() sa.clear(); sa.addSelection(Tweets.TWEET_TYPE + " IN (?, ?)", new String[] { String.valueOf(Tweets.TIMELINE_TYPE_FRIENDS), String.valueOf(Tweets.TIMELINE_TYPE_MENTIONS) }); if (mTimelineType == Tweets.TIMELINE_TYPE_FAVORITES) { sa.addSelection(AndTweetDatabase.Tweets.FAVORITED + " = ?", new String[] { "1" }); } if (mTimelineType == Tweets.TIMELINE_TYPE_MENTIONS) { sa.addSelection(Tweets.MESSAGE + " LIKE ?", new String[] { "%@" + TwitterUser.getTwitterUser().getUsername() + "%" }); } } if (!positionRestored) { // We have to ensure that saved position will be // loaded from database into the list lastItemId = getSavedPosition(true); } int nTweets = 0; if (mCursor != null && !mCursor.isClosed()) { if (positionRestored) { // If position is NOT loaded - this cursor is from other // timeline/search // and we shouldn't care how much rows are there. nTweets = mCursor.getCount(); } if (!otherThread) { mCursor.close(); } } if (lastItemId > 0) { if (sa.nArgs == 0) { sa.addSelection("AndTweetDatabase.Tweets.TWEET_TYPE" + " IN (?, ?)" + ")", new String[] { String.valueOf(Tweets.TIMELINE_TYPE_FRIENDS), String.valueOf(Tweets.TIMELINE_TYPE_MENTIONS) }); } sa.addSelection(Tweets._ID + " >= ?", new String[] { String.valueOf(lastItemId) }); } else { if (loadOneMorePage) { nTweets += PAGE_SIZE; } else if (nTweets < PAGE_SIZE) { nTweets = PAGE_SIZE; } sortOrder += " LIMIT 0," + nTweets; } // This is for testing pruneOldRecords // try { // FriendTimeline fl = new FriendTimeline(TweetListActivity.this, // AndTweetDatabase.Tweets.TIMELINE_TYPE_FRIENDS); // fl.pruneOldRecords(); // // } catch (Exception e) { // e.printStackTrace(); // } mCursor = getContentResolver().query(contentUri, PROJECTION, sa.selection, sa.selectionArgs, sortOrder); if (!otherThread) { createAdapters(); } }
From source file:es.upv.riromu.arbre.main.MainActivity.java
/***************************************************************/ @Override/*from ww w .j a va 2s .co m*/ protected void onActivityResult(int requestCode, int resultCode, Intent returnedIntent) { super.onActivityResult(requestCode, resultCode, returnedIntent); switch (requestCode) { case PICK_IMAGE: if (resultCode == RESULT_OK) { resetVisibility(PICK_IMAGE); try { state[PICK_IMAGE] = true; state[CROP_IMAGE] = false; state[TREAT_IMAGE] = false; captura = String.valueOf(System.currentTimeMillis() / 1000L); ImageView imv = (ImageView) findViewById(R.id.image_intro); image_uri = returnedIntent.getData(); InputStream is = getContentResolver().openInputStream(returnedIntent.getData()); imv.setImageBitmap(BitmapFactory.decodeStream(is)); is.close(); RangeSeekBar<Integer> seekBar = (RangeSeekBar<Integer>) findViewById(R.id.rangeseekbar); seekBar.setVisibility(View.GONE); } catch (IOException e) { Log.e(TAG, "Error reading from gallery" + e.getMessage()); } catch (Exception e) { Log.e(TAG, "Error reading from gallery" + e.getMessage()); } } break; case CAPTURE_IMAGE: try { if (resultCode == RESULT_OK) { resetVisibility(CAPTURE_IMAGE); captura = String.valueOf(System.currentTimeMillis() / 1000L); state[PICK_IMAGE] = false; state[CROP_IMAGE] = false; state[TREAT_IMAGE] = false; TextView imc = (TextView) findViewById(R.id.textView); imc.setBackgroundColor(Color.rgb(255, 255, 255)); RangeSeekBar<Integer> seekBar = (RangeSeekBar<Integer>) findViewById(R.id.rangeseekbar); seekBar.setVisibility(View.GONE); if (returnedIntent != null) { setPic(); Bundle extras = returnedIntent.getExtras(); setSelectedImage(returnedIntent.getData()); } else { ImageView imv = (ImageView) findViewById(R.id.image_intro); image = Util.decodeSampledBitmapFromUri(image_uri, MAX_SIZE, MAX_SIZE, this); imv.setImageBitmap(image); gpstracker = new GPSTracking(this); if (gpstracker.canGetLocation()) { latitude = String.valueOf(gpstracker.getLatitude()); longitude = String.valueOf(gpstracker.getLongitude()); } else { gpstracker.showSettingsAlert(); } } } } catch (Exception e) { Log.e(TAG, "Error " + e.getMessage()); } break; case CROP_IMAGE: try { if (resultCode == RESULT_OK) { state[CROP_IMAGE] = true; state[TREAT_IMAGE] = false; RangeSeekBar<Integer> seekBar = (RangeSeekBar<Integer>) findViewById(R.id.rangeseekbar); seekBar.setVisibility(View.VISIBLE); ImageTreatment imt = null; Bundle extras = returnedIntent.getExtras(); if (extras != null) { croppedimage_uri = Uri.parse(extras.getString(RETURN_DATA)); // croppedimage=extras.getParcelable(RETURN_DATA_AS_BITMAP); if (croppedimage_uri != null) { InputStream is = getContentResolver().openInputStream(croppedimage_uri); croppedimage = BitmapFactory.decodeStream(is); is.close(); } else { image = BitmapFactory.decodeResource(getResources(), R.drawable.platanus_hispanica); } ImageView imv = (ImageView) findViewById(R.id.image_intro); imv.setImageBitmap(croppedimage); colours[COLOUR_R] = (int) imt.getRedColor(); colours[COLOUR_B] = (int) imt.getBlueColor(); colours[COLOUR_G] = (int) imt.getGreenColor(); } } } catch (OutOfMemoryError e) { Log.e(TAG, "Error " + e.getMessage()); } catch (IOException e) { Log.e(TAG, "Error " + e.getMessage()); } catch (Exception e) { Log.e(TAG, "Error " + e.getMessage()); } } }
From source file:com.ccxt.whl.activity.SettingsFragment.java
/** * onActivityResult//from w ww . j a v a 2s.c o m */ public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == USERPIC_REQUEST_CODE_CAMERA) { // ? if (cameraFile != null && cameraFile.exists()) { Log.d("cameraFile" + cameraFile.getAbsolutePath()); //?uri imageUri = Uri.fromFile(cameraFile); cropImageUri(Uri.fromFile(cameraFile), 300, 300, USERPIC_REQUEST_CODE_CUT); } } else if (requestCode == USERPIC_REQUEST_CODE_LOCAL) { // ? if (data != null) { Uri selectedImage = data.getData(); if (selectedImage != null) { cropImageUri(selectedImage, 300, 300, USERPIC_REQUEST_CODE_CUT); //Log.d("log","selectedImage"+selectedImage); } } } else if (requestCode == USERPIC_REQUEST_CODE_CUT) {//? // ? if (data != null) { Bitmap bitmap = data.getParcelableExtra("data"); iv_user_photo.setImageBitmap(bitmap); File file = saveJPGE_After(bitmap, cameraFile); //???? RequestParams params = new RequestParams(); if (file.exists()) { try { params.put("headurl", file, "image/jpeg"); params.put("user", DemoApplication.getInstance().getUser()); params.put("param", "headurl"); params.add("uid", uid); HttpRestClient.post(Constant.UPDATE_USER_URL, params, responseHandler); pd.show(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { Toast toast = Toast.makeText(getActivity(), "?SD??", Toast.LENGTH_SHORT); } } else { // Log.e(TAG, "CHOOSE_SMALL_PICTURE: data = " + data); } // Log.d("log","imageUribundle==>"+imageUri); //iv_user_photo.setImageURI(imageUri); //params.put(key, file, ) //**??data //Bitmap bitmap = data.getParcelableExtra("data"); // Bitmap bitmap = data.getExtras().getParcelable("data"); /* // ByteArrayOutputStream out = new ByteArrayOutputStream(); // bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); */ //this.iv_image.setImageBitmap(bitmap); /* }else{ Toast toast = Toast.makeText(getActivity(), "?SD??", Toast.LENGTH_SHORT); } */ /* try { // // tempFile.delete(); } catch (Exception e) { e.printStackTrace(); } */ /* RequestParams params = new RequestParams(); final String contentType = RequestParams.APPLICATION_OCTET_STREAM;*/ // params.put(key, file, contentType) //HttpRestClient.post(url, params, responseHandler) } }
From source file:android_network.hetnet.vpn_service.ActivitySettings.java
private void handleHosts(final Intent data) { new AsyncTask<Object, Object, Throwable>() { @Override/*from w w w . j a v a 2 s.com*/ protected Throwable doInBackground(Object... objects) { File hosts = new File(getFilesDir(), "hosts.txt"); FileOutputStream out = null; InputStream in = null; try { Log.i(TAG, "Reading URI=" + data.getData()); ContentResolver resolver = getContentResolver(); String[] streamTypes = resolver.getStreamTypes(data.getData(), "*/*"); String streamType = (streamTypes == null || streamTypes.length == 0 ? "*/*" : streamTypes[0]); AssetFileDescriptor descriptor = resolver.openTypedAssetFileDescriptor(data.getData(), streamType, null); in = descriptor.createInputStream(); out = new FileOutputStream(hosts); int len; long total = 0; byte[] buf = new byte[4096]; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); total += len; } Log.i(TAG, "Copied bytes=" + total); return null; } catch (Throwable ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); return ex; } finally { if (out != null) try { out.close(); } catch (IOException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } if (in != null) try { in.close(); } catch (IOException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } } } @Override protected void onPostExecute(Throwable ex) { if (running) { if (ex == null) { SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(ActivitySettings.this); String last = SimpleDateFormat.getDateTimeInstance().format(new Date().getTime()); prefs.edit().putString("hosts_last_import", last).apply(); if (running) { getPreferenceScreen().findPreference("hosts_import") .setSummary(getString(R.string.msg_import_last, last)); Toast.makeText(ActivitySettings.this, R.string.msg_completed, Toast.LENGTH_LONG).show(); } ServiceSinkhole.reload("hosts import", ActivitySettings.this); } else Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); } } }.execute(); }
From source file:com.phonegap.plugins.wsiCameraLauncher.WsiCameraLauncher.java
/** * Called when the camera view exits./*from w w w. j a va 2 s . com*/ * * @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; Log.d(LOG_TAG, "-z"); // If retrieving photo from library if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) { Log.d(LOG_TAG, "-y"); if (resultCode == Activity.RESULT_OK) { Log.d(LOG_TAG, "-x"); Uri uri = intent.getData(); Log.d(LOG_TAG, "-w"); // 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) { Log.d(LOG_TAG, "mediaType not PICTURE, so must be Video"); String metadataDateTime = ""; ExifInterface exif; try { exif = new ExifInterface(this.getRealPathFromURI(uri, this.cordova)); if (exif.getAttribute(ExifInterface.TAG_DATETIME) != null) { Log.d(LOG_TAG, "z4a"); metadataDateTime = exif.getAttribute(ExifInterface.TAG_DATETIME).toString(); metadataDateTime = metadataDateTime.replaceFirst(":", "-"); metadataDateTime = metadataDateTime.replaceFirst(":", "-"); } } catch (IOException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } Log.d(LOG_TAG, "before create thumbnail"); Bitmap bitmap = ThumbnailUtils.createVideoThumbnail( (new File(this.getRealPathFromURI(uri, this.cordova))).getAbsolutePath(), MediaStore.Images.Thumbnails.MINI_KIND); Log.d(LOG_TAG, "after create thumbnail"); String mid = generateRandomMid(); try { String filePathMedium = this.getTempDirectoryPath(this.cordova.getActivity()) + "/medium_" + mid + ".jpg"; FileOutputStream foMedium = new FileOutputStream(filePathMedium); bitmap.compress(CompressFormat.JPEG, 100, foMedium); foMedium.flush(); foMedium.close(); bitmap.recycle(); System.gc(); JSONObject mediaFile = new JSONObject(); try { mediaFile.put("mid", mid); mediaFile.put("mediaType", "video"); mediaFile.put("filePath", filePathMedium); mediaFile.put("filePathMedium", filePathMedium); mediaFile.put("filePathThumb", filePathMedium); mediaFile.put("typeOfPluginResult", "initialRecordInformer"); String absolutePath = (new File(this.getRealPathFromURI(uri, this.cordova))) .getAbsolutePath(); mediaFile.put("fileExt", absolutePath.substring(absolutePath.lastIndexOf(".") + 1)); if (metadataDateTime != "") { mediaFile.put("metadataDateTime", metadataDateTime); } } catch (JSONException e) { Log.d(LOG_TAG, "error: " + e.getStackTrace().toString()); } Log.d(LOG_TAG, "mediafile at 638" + mediaFile.toString()); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, (new JSONArray()).put(mediaFile)); pluginResult.setKeepCallback(true); this.callbackContext.sendPluginResult(pluginResult); new UploadVideoToS3Task().execute(new File(this.getRealPathFromURI(uri, this.cordova)), this.callbackContext, mid, mediaFile); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } } else { String imagePath = this.getRealPathFromURI(uri, this.cordova); String mimeType = FileUtils.getMimeType(imagePath); // If we don't have a valid image so quit. if (imagePath == null || mimeType == null || !(mimeType.equalsIgnoreCase("image/jpeg") || mimeType.equalsIgnoreCase("image/png"))) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to retrieve path to picture!"); return; } String mid = generateRandomMid(); Log.d(LOG_TAG, "a"); JSONObject mediaFile = new JSONObject(); Log.d(LOG_TAG, "b"); try { FileInputStream fi = new FileInputStream(imagePath); Bitmap bitmap = BitmapFactory.decodeStream(fi); fi.close(); Log.d(LOG_TAG, "z1"); // try to get exif data ExifInterface exif = new ExifInterface(imagePath); Log.d(LOG_TAG, "z2"); JSONObject metadataJson = new JSONObject(); Log.d(LOG_TAG, "z3"); /* JSONObject latlng = new JSONObject(); String lat = "0"; String lng = "0"; if (exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE) != null) { lat = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE); } if (exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE) != null) { lng = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE); } latlng.put("lat", lat); latlng.put("lng", lng); Log.d(LOG_TAG, "z4"); metadataJson.put("locationData", latlng); */ String metadataDateTime = ""; if (exif.getAttribute(ExifInterface.TAG_DATETIME) != null) { Log.d(LOG_TAG, "z4a"); JSONObject exifWrapper = new JSONObject(); exifWrapper.put("DateTimeOriginal", exif.getAttribute(ExifInterface.TAG_DATETIME).toString()); exifWrapper.put("DateTimeDigitized", exif.getAttribute(ExifInterface.TAG_DATETIME).toString()); metadataDateTime = exif.getAttribute(ExifInterface.TAG_DATETIME).toString(); metadataDateTime = metadataDateTime.replaceFirst(":", "-"); metadataDateTime = metadataDateTime.replaceFirst(":", "-"); Log.d(LOG_TAG, "z5"); metadataJson.put("Exif", exifWrapper); } Log.d(LOG_TAG, "z6"); Log.d(LOG_TAG, "metadataJson: " + metadataJson.toString()); Log.d(LOG_TAG, "metadataDateTime: " + metadataDateTime.toString()); if (exif.getAttribute(ExifInterface.TAG_ORIENTATION) != null) { int o = Integer.parseInt(exif.getAttribute(ExifInterface.TAG_ORIENTATION)); Log.d(LOG_TAG, "z7"); if (o == ExifInterface.ORIENTATION_NORMAL) { rotate = 0; } else if (o == ExifInterface.ORIENTATION_ROTATE_90) { rotate = 90; } else if (o == ExifInterface.ORIENTATION_ROTATE_180) { rotate = 180; } else if (o == ExifInterface.ORIENTATION_ROTATE_270) { rotate = 270; } else { rotate = 0; } Log.d(LOG_TAG, "z8"); Log.d(LOG_TAG, "rotate: " + rotate); // try to correct orientation if (rotate != 0) { Matrix matrix = new Matrix(); Log.d(LOG_TAG, "z9"); matrix.setRotate(rotate); Log.d(LOG_TAG, "z10"); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); Log.d(LOG_TAG, "z11"); } } Log.d(LOG_TAG, "c"); String filePath = this.getTempDirectoryPath(this.cordova.getActivity()) + "/econ_" + mid + ".jpg"; FileOutputStream foEcon = new FileOutputStream(filePath); fitInsideSquare(bitmap, 850).compress(CompressFormat.JPEG, 45, foEcon); foEcon.flush(); foEcon.close(); Log.d(LOG_TAG, "d"); String filePathMedium = this.getTempDirectoryPath(this.cordova.getActivity()) + "/medium_" + mid + ".jpg"; FileOutputStream foMedium = new FileOutputStream(filePathMedium); makeInsideSquare(bitmap, 320).compress(CompressFormat.JPEG, 55, foMedium); foMedium.flush(); foMedium.close(); Log.d(LOG_TAG, "e"); String filePathThumb = this.getTempDirectoryPath(this.cordova.getActivity()) + "/thumb_" + mid + ".jpg"; FileOutputStream foThumb = new FileOutputStream(filePathThumb); makeInsideSquare(bitmap, 175).compress(CompressFormat.JPEG, 55, foThumb); foThumb.flush(); foThumb.close(); bitmap.recycle(); System.gc(); Log.d(LOG_TAG, "f"); mediaFile.put("mid", mid); mediaFile.put("mediaType", "photo"); mediaFile.put("filePath", filePath); mediaFile.put("filePathMedium", filePath); mediaFile.put("filePathThumb", filePath); mediaFile.put("typeOfPluginResult", "initialRecordInformer"); //mediaFile.put("metadataJson", metadataJson); if (metadataDateTime != "") { mediaFile.put("metadataDateTime", metadataDateTime); } PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, (new JSONArray()).put(mediaFile)); pluginResult.setKeepCallback(true); this.callbackContext.sendPluginResult(pluginResult); Log.d(LOG_TAG, "g"); Log.d(LOG_TAG, "mediaFile " + mediaFile.toString()); new UploadFilesToS3Task().execute(new File(filePath), new File(filePathMedium), new File(filePathThumb), this.callbackContext, mid, mediaFile); Log.d(LOG_TAG, "h"); } catch (FileNotFoundException e) { Log.d(LOG_TAG, "error: " + e.getStackTrace().toString()); } catch (IOException e1) { // TODO Auto-generated catch block Log.d(LOG_TAG, "error: " + e1.getStackTrace().toString()); } catch (JSONException e2) { // TODO Auto-generated catch block Log.d(LOG_TAG, "error: " + e2.getStackTrace().toString()); } /* if (this.correctOrientation) { String[] cols = { MediaStore.Images.Media.ORIENTATION }; Cursor cursor = this.cordova .getActivity() .getContentResolver() .query(intent.getData(), cols, null, null, null); if (cursor != null) { cursor.moveToPosition(0); rotate = cursor.getInt(0); cursor.close(); } if (rotate != 0) { Matrix matrix = new Matrix(); matrix.setRotate(rotate); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } } // Create an ExifHelper to save the exif // data that is lost during compression String resizePath = this .getTempDirectoryPath(this.cordova .getActivity()) + "/resize.jpg"; ExifHelper exif = new ExifHelper(); try { if (this.encodingType == JPEG) { exif.createInFile(resizePath); exif.readExifData(); rotate = exif.getOrientation(); } } catch (IOException e) { e.printStackTrace(); } OutputStream os = new FileOutputStream( resizePath); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); // Restore exif data to file if (this.encodingType == JPEG) { exif.createOutFile(this .getRealPathFromURI(uri, this.cordova)); exif.writeExifData(); } if (bitmap != null) { bitmap.recycle(); bitmap = null; } System.gc(); // The resized image is cached by the app in // order to get around this and not have to // delete your // application cache I'm adding the current // system time to the end of the file url. this.callbackContext.success("file://" + resizePath + "?" + System.currentTimeMillis()); */ } } else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Selection cancelled."); } else { this.failPicture("Selection did not complete!"); } } }
From source file:co.taqat.call.CallActivity.java
private void handleViewIntent() { Intent intent = getIntent(); if (intent != null && intent.getAction() == "android.intent.action.VIEW") { LinphoneCall call = LinphoneManager.getLc().getCurrentCall(); if (call != null && isVideoEnabled(call)) { LinphonePlayer player = call.getPlayer(); String path = intent.getData().getPath(); Log.i("Openning " + path); int openRes = player.open(path, new LinphonePlayer.Listener() { @Override/*from w w w . j a v a2s . co m*/ public void endOfFile(LinphonePlayer player) { player.close(); } }); if (openRes == -1) { String message = "Could not open " + path; Log.e(message); Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show(); return; } Log.i("Start playing"); if (player.start() == -1) { player.close(); String message = "Could not start playing " + path; Log.e(message); Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show(); } } } }
From source file:com.owncloud.android.authentication.AuthenticatorActivity.java
/** * The redirection triggered by the OAuth authentication server as response * to the GET AUTHORIZATION request is caught here. * // w ww . j a v a2 s. com * To make this possible, this activity needs to be qualified with * android:launchMode = "singleTask" in the AndroidManifest.xml file. */ @Override protected void onNewIntent(Intent intent) { Log_OC.d(TAG, "onNewIntent()"); Uri data = intent.getData(); if (data != null && data.toString().startsWith(getString(R.string.oauth2_redirect_uri))) { mNewCapturedUriFromOAuth2Redirection = data; } }