List of usage examples for android.net Uri fromFile
public static Uri fromFile(File file)
From source file:com.phonegap.plugins.wsiCameraLauncher.WsiCameraLauncher.java
/** * Take a picture with the camera. When an image is captured or the camera * view is cancelled, the result is returned in * CordovaActivity.onActivityResult, which forwards the result to * this.onActivityResult.//from w ww. j a v a 2 s. co m * * The image can either be returned as a base64 string or a URI that points * to the file. To display base64 string in an img tag, set the source to: * img.src="data:image/jpeg;base64,"+result; or to display URI in an img tag * img.src=result; * * @param quality * Compression quality hint (0-100: 0=low quality & high * compression, 100=compress of max quality) * @param returnType * Set the type of image to return. */ public void takePicture(int returnType, int encodingType) { // Save the number of images currently on disk for later this.numPics = queryImgDB(whichContentStore()).getCount(); // Display camera Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); // Specify file so that large image is captured and returned File photo = createCaptureFile(encodingType); intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo)); this.imageUri = Uri.fromFile(photo); if (this.cordova != null) { this.cordova.startActivityForResult((CordovaPlugin) this, intent, (CAMERA + 1) * 16 + returnType + 1); } // else // LOG.d(LOG_TAG, // "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity"); }
From source file:com.logilite.vision.camera.CameraLauncher.java
/** * Take a picture with the camera./* ww w . j a va2 s.c om*/ * When an image is captured or the camera view is cancelled, the result is returned * in CordovaActivity.onActivityResult, which forwards the result to this.onActivityResult. * * The image can either be returned as a base64 string or a URI that points to the file. * To display base64 string in an img tag, set the source to: * img.src="data:image/jpeg;base64,"+result; * or to display URI in an img tag * img.src=result; * * @param quality Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality) * @param returnType Set the type of image to return. */ public void takePicture(int returnType, int encodingType) { // Save the number of images currently on disk for later this.numPics = queryImgDB(whichContentStore()).getCount(); // Display camera Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); // Specify file so that large image is captured and returned File photo = createCaptureFile(encodingType); intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo)); this.imageUri = Uri.fromFile(photo); if (this.cordova != null) { this.cordova.startActivityForResult((CordovaPlugin) this, intent, (CAMERA + 1) * 16 + returnType + 1); } // else // LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity"); }
From source file:it.evilsocket.dsploit.core.UpdateService.java
public static boolean isUpdateAvailable() { boolean exitForError = true; String localVersion = System.getAppVersionName(); // cannot retrieve installed apk version if (localVersion == null) return false; try {/* w w w .j a v a2s . c o m*/ synchronized (mApkInfo) { // Read remote version if (mApkInfo.version == null) { URL url = new URL(REMOTE_VERSION_URL); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line, buffer = ""; while ((line = reader.readLine()) != null) { buffer += line + "\n"; } reader.close(); mApkInfo.url = REMOTE_APK_URL; mApkInfo.versionString = buffer.split("\n")[0].trim(); if (!VERSION_CHECK.matcher(mApkInfo.versionString).matches()) throw new org.apache.http.ParseException( String.format("remote version parse failed: '%s'", mApkInfo.versionString)); mApkInfo.version = getVersionCode(mApkInfo.versionString); mApkInfo.name = String.format("dSploit-%s.apk", mApkInfo.versionString); mApkInfo.path = String.format("%s/%s", System.getStoragePath(), mApkInfo.name); mApkInfo.contentIntent = new Intent(Intent.ACTION_VIEW); mApkInfo.contentIntent.setDataAndType(Uri.fromFile(new File(mApkInfo.path)), "application/vnd.android.package-archive"); mApkInfo.contentIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } // Compare versions double installedVersionCode = getVersionCode(localVersion); Logger.debug( String.format("mApkInstalledVersion = %s ( %s ) ", localVersion, installedVersionCode)); Logger.debug(String.format("mRemoteVersion = %s ( %s ) ", mApkInfo.versionString, mApkInfo.version)); exitForError = false; if (mApkInfo.version > installedVersionCode) return true; } } catch (org.apache.http.ParseException e) { Logger.error(e.getMessage()); } catch (Exception e) { System.errorLogging(e); } finally { if (exitForError) mApkInfo.reset(); } return false; }
From source file:com.zira.registration.DocumentUploadActivity.java
protected void selectImage() { final CharSequence[] options = { "Take Photo", "Choose from Gallery", "Cancel" }; AlertDialog.Builder builder = new AlertDialog.Builder(DocumentUploadActivity.this); builder.setTitle("Add Photo!"); builder.setItems(options, new DialogInterface.OnClickListener() { @Override/*from www. j a v a 2 s . c o m*/ public void onClick(DialogInterface dialog, int item) { if (options[item].equals("Take Photo")) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { mCurrentPhotoPath = Util.createImageFile(); photoFile = new File(mCurrentPhotoPath); } catch (Exception ex) { // Error occurred while creating the File ex.printStackTrace(); } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); startActivityForResult(takePictureIntent, 1); } } } else if (options[item].equals("Choose from Gallery")) { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Select Picture"), 2); } else if (options[item].equals("Cancel")) { dialog.dismiss(); } } }); builder.show(); }
From source file:com.VVTeam.ManHood.Fragment.HistogramFragment.java
private void initViews(View view) { parentLayout = (RelativeLayout) view.findViewById(R.id.fragment_histogram_parent_relative_layout); /*BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 2;//from ww w . j a v a2 s. c o m parentLayout.setBackgroundDrawable(new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.histogram_bg, options)));*/ settingsRelative = (RelativeLayout) view.findViewById(R.id.fragment_histogram_settings_relative_layout); markRelative = (RelativeLayout) view.findViewById(R.id.fragment_histogram_mark_relative_layout); worldRelative = (RelativeLayout) view.findViewById(R.id.fragment_histogram_world_relative); // worldRelative.setSelected(true); worldRelative.setBackgroundResource(R.drawable.cell_p); areaRelative = (RelativeLayout) view.findViewById(R.id.fragment_histogram_area_relative); hoodRelative = (RelativeLayout) view.findViewById(R.id.fragment_histogram_hood_relative); yourResultButton = (Button) view.findViewById(R.id.fragment_histogram_your_result_button); contentRelative = (RelativeLayout) view.findViewById(R.id.fragment_histogram_content_relative); RelativeLayout shareRelative = (RelativeLayout) view .findViewById(R.id.fragment_histogram_share_button_relative); shareRelative.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub GoogleTracker.StarSendEvent(getActivity(), "ui_action", "user_action", "histogram_share"); Bitmap image = makeSnapshot(); File pictureFile = getOutputMediaFile(); try { FileOutputStream fos = new FileOutputStream(pictureFile); image.compress(Bitmap.CompressFormat.PNG, 90, fos); fos.close(); } catch (Exception e) { } // String pathofBmp = Images.Media.insertImage(getActivity().getContentResolver(), makeSnapshot(), "Man Hood App", null); // Uri bmpUri = Uri.parse(pathofBmp); Uri bmpUri = Uri.fromFile(pictureFile); final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); emailIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); emailIntent.setType("image/png"); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Man Hood App"); getActivity().startActivity(emailIntent); } }); polarPlot = (PolarPlot) view.findViewById(R.id.polarPlot); thicknessHisto = (Histogram) view.findViewById(R.id.thicknessHisto); thicknessHisto.setOrientation(ORIENT.LEFT); thicknessHisto.setBackgroundColor(Color.TRANSPARENT); lengthHisto = (Histogram) view.findViewById(R.id.lengthHistogram); lengthHisto.setOrientation(ORIENT.RIGHT); lengthHisto.setBackgroundColor(Color.TRANSPARENT); girthHisto = (Histogram) view.findViewById(R.id.girthHistogram); girthHisto.setOrientation(ORIENT.BOTTOM); girthHisto.setBackgroundColor(Color.TRANSPARENT); lengthHisto.setCallBackListener(new HistogramCallBack() { @Override public void setValueSelectionChangedBlock(Histogram histo, HistogramSelectionState selectionState, float value, HistogramBin bin) { // TODO Auto-generated method stub if (selectionState == HistogramSelectionState.HistogramSelectionStateSelected) { histogramSelected = true; setNearestUserID(usersData.userIDWithNearestLength(value)); setSelection(true, girthHisto, usersData.girthOfUserWithID(nearestUserID)); setSelection(true, thicknessHisto, usersData.thicknessOfUserWithID(nearestUserID)); // setSelection(false, lengthHisto, 0.0f); setSelection(true, lengthHisto, value); setupPolarPlotWithCurrentUserID(nearestUserID, usersData, selfUserData); } else if (selectionState == HistogramSelectionState.HistogramSelectionStateNotSelected) { histogramSelected = false; setNearestUserID(null); setSelectionForAverage(); setupPolarPlotWithCurrentUserID(nearestUserID, usersData, selfUserData); } else if (selectionState == HistogramSelectionState.HistogramSelectionStateDelayedFinish) { } } }); girthHisto.setCallBackListener(new HistogramCallBack() { @Override public void setValueSelectionChangedBlock(Histogram histo, HistogramSelectionState selectionState, float value, HistogramBin bin) { // TODO Auto-generated method stub if (selectionState == HistogramSelectionState.HistogramSelectionStateSelected) { histogramSelected = true; setNearestUserID(usersData.userIDWithNearestGirth(value)); setSelection(true, lengthHisto, usersData.lengthOfUserWithID(nearestUserID)); setSelection(true, thicknessHisto, usersData.thicknessOfUserWithID(nearestUserID)); // setSelection(false, girthHisto, 0.0f); setSelection(true, girthHisto, value); setupPolarPlotWithCurrentUserID(nearestUserID, usersData, selfUserData); } else if (selectionState == HistogramSelectionState.HistogramSelectionStateNotSelected) { histogramSelected = false; setNearestUserID(null); setSelectionForAverage(); setupPolarPlotWithCurrentUserID(nearestUserID, usersData, selfUserData); } else if (selectionState == HistogramSelectionState.HistogramSelectionStateDelayedFinish) { } } }); thicknessHisto.setCallBackListener(new HistogramCallBack() { @Override public void setValueSelectionChangedBlock(Histogram histo, HistogramSelectionState selectionState, float value, HistogramBin bin) { // TODO Auto-generated method stub if (selectionState == HistogramSelectionState.HistogramSelectionStateSelected) { histogramSelected = true; setNearestUserID(usersData.userIDWithNearestThickness(value)); setSelection(true, girthHisto, usersData.girthOfUserWithID(nearestUserID)); setSelection(true, lengthHisto, usersData.lengthOfUserWithID(nearestUserID)); // setSelection(false, thicknessHisto, 0.0f); setSelection(true, thicknessHisto, value); setupPolarPlotWithCurrentUserID(nearestUserID, usersData, selfUserData); } else if (selectionState == HistogramSelectionState.HistogramSelectionStateNotSelected) { histogramSelected = false; setNearestUserID(null); setSelectionForAverage(); setupPolarPlotWithCurrentUserID(nearestUserID, usersData, selfUserData); } else if (selectionState == HistogramSelectionState.HistogramSelectionStateDelayedFinish) { } } }); textBoxTitleLabel = (TextView) view.findViewById(R.id.txtBoxTitle); textBoxTitleLabel.setText("AVERAGE"); layoutSubTitle = (LinearLayout) view.findViewById(R.id.layoutSubTitle); layoutSubTitle.setVisibility(View.INVISIBLE); textBoxSubtitleLabel = (TextView) view.findViewById(R.id.txtBoxSubTitleLabel); textBoxSubtitleValueLabel = (TextView) view.findViewById(R.id.txtBoxSubTitleValue); lengthSelectedLabel = (TextView) view.findViewById(R.id.txtlengthselected); lengthSelectedLabel.setText("50%"); lengthTOPLabel = (TextView) view.findViewById(R.id.lengthTOPLabel); girthSelectedLabel = (TextView) view.findViewById(R.id.txtgirthselected); girthSelectedLabel.setText("50%"); girthTOPLabel = (TextView) view.findViewById(R.id.girthTOPLabel); thicknessSelectedLabel = (TextView) view.findViewById(R.id.txtthicknessselected); thicknessSelectedLabel.setText("50%"); thinkestAtTOPLabel = (TextView) view.findViewById(R.id.thinkestAtTOPLabel); curvedSelectedLabel = (TextView) view.findViewById(R.id.txtcurvedselected); curvedSelectedLabel.setText("0"); girthTopLB = (TextView) view.findViewById(R.id.girthTop); girthMiddleLB = (TextView) view.findViewById(R.id.girthMiddle); girthBottomLB = (TextView) view.findViewById(R.id.girthBottom); thicknessTopLB = (TextView) view.findViewById(R.id.thicknessTop); thicknessMiddleLB = (TextView) view.findViewById(R.id.thicknessMiddle); thicknessBottomLB = (TextView) view.findViewById(R.id.thicknessBottom); lengthTopLB = (TextView) view.findViewById(R.id.lengthTop); lengthMiddleLB = (TextView) view.findViewById(R.id.lengthMiddle); lengthBottomLB = (TextView) view.findViewById(R.id.lengthBottom); settingsRelative.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((MainActivity) getActivity()).openSettingsActivity(); } }); markRelative.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((MainActivity) getActivity()).openCertificateActivity(); } }); worldRelative.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setSelectedRange(SliceRange.SliceRangeAll); updateRangeSwitch(); } }); areaRelative.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setSelectedRange(SliceRange.SliceRange200); updateRangeSwitch(); } }); hoodRelative.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setSelectedRange(SliceRange.SliceRange20); updateRangeSwitch(); } }); yourResultButton.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub if (event.getAction() == MotionEvent.ACTION_DOWN) { youTouchDown(); } else if (event.getAction() == MotionEvent.ACTION_UP) { youTouchUp(); // final Handler handler = new Handler(); // handler.postDelayed(new Runnable() { // @Override // public void run() { // youTouchUp(); // } // }, 2000); } return true; } }); RequestManager.getInstance().checkUser(); /* in-app billing */ String base64EncodedPublicKey = LICENSE_KEY; // Create the helper, passing it our context and the public key to verify signatures with Log.d(TAG, "Creating IAB helper."); mHelper = new IabHelper(getActivity(), base64EncodedPublicKey); // enable debug logging (for a production application, you should set this to false). mHelper.enableDebugLogging(true); // Start setup. This is asynchronous and the specified listener // will be called once setup completes. Log.d(TAG, "Starting setup."); mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { public void onIabSetupFinished(IabResult result) { Log.d(TAG, "Setup finished."); if (!result.isSuccess()) { // Oh noes, there was a problem. Log.d(TAG, "Problem setting up in-app billing: " + result); return; } // Have we been disposed of in the meantime? If so, quit. if (mHelper == null) return; // IAB is fully set up. Now, let's get an inventory of stuff we own. Log.d(TAG, "Setup successful. Querying inventory."); mHelper.queryInventoryAsync(mGotInventoryListener); } }); }
From source file:com.hackensack.umc.activity.ProfileSelfiewithCropActivity.java
public Uri dispatchTakePictureIntent(Context context, int cameraFacing, int selectedImageView) { Uri imageUri = null;/*from w w w . jav a 2 s . c om*/ Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); // Intent intent = new Intent(context, PictureDemo.class); if (cameraFacing == 1) { intent.putExtra("android.intent.extras.CAMERA_FACING", Camera.CameraInfo.CAMERA_FACING_FRONT); } else { intent.putExtra("android.intent.extras.CAMERA_FACING", Camera.CameraInfo.CAMERA_FACING_BACK); } File photo; try { // place where to store camera taken picture photo = CameraFunctionality.createTemporaryFile("picture_" + selectedImageView, ".png"); // photo.delete(); } catch (Exception e) { Log.v(TAG, "Can't create file to take picture!"); //Toast.makeText(getActivity(), "Please check SD card! Image shot is impossible!", 10000); return imageUri; } imageUri = Uri.fromFile(photo); intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); //start camera intent ((Activity) context).startActivityForResult(intent, Constant.FRAGMENT_CONST_REQUEST_IMAGE_CAPTURE); return imageUri; }
From source file:com.dnielfe.manager.utils.SimpleUtils.java
public static void openFile(final Context context, final File target) { final String mime = MimeTypes.getMimeType(target); final Intent i = new Intent(Intent.ACTION_VIEW); if (mime != null) { i.setDataAndType(Uri.fromFile(target), mime); } else {// ww w .j a va2 s .c o m i.setDataAndType(Uri.fromFile(target), "*/*"); } if (context.getPackageManager().queryIntentActivities(i, 0).isEmpty()) { Toast.makeText(context, R.string.cantopenfile, Toast.LENGTH_SHORT).show(); return; } try { context.startActivity(i); } catch (Exception e) { Toast.makeText(context, context.getString(R.string.cantopenfile) + e.getMessage(), Toast.LENGTH_SHORT) .show(); } }
From source file:com.tuxpan.foregroundcameragalleryplugin.ForegroundCameraLauncher.java
/** * Take a picture with the camera./*from w w w. j a v a2 s.co m*/ * When an image is captured or the camera view is cancelled, the result is returned * in CordovaActivity.onActivityResult, which forwards the result to this.onActivityResult. * * The image can either be returned as a base64 string or a URI that points to the file. * To display base64 string in an img tag, set the source to: * img.src="data:image/jpeg;base64,"+result; * or to display URI in an img tag * img.src=result; * * @param quality Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality) * @param returnType Set the type of image to return. */ public void takePicture(int returnType, int encodingType) { // Save the number of images currently on disk for later this.numPics = queryImgDB(whichContentStore()).getCount(); // Display camera // Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); Intent intent = new Intent(this.cordova.getActivity().getApplicationContext(), CameraActivity.class); // Specify file so that large image is captured and returned File photo = createCaptureFile(encodingType); intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo)); this.imageUri = Uri.fromFile(photo); if (this.cordova != null) { this.cordova.startActivityForResult((CordovaPlugin) this, intent, (CAMERA + 1) * 16 + returnType + 1); } // else // LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity"); }