List of usage examples for android.support.v4.content FileProvider getUriForFile
public static Uri getUriForFile(Context context, String str, File file)
From source file:org.fs.galleon.presenters.ToolsFragmentPresenter.java
private void dispatchTakePictureIntent() { createIfNotExists().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) .subscribe(file -> {//from ww w .j a v a 2 s. c o m if (file.exists()) { log(Log.INFO, String.format(Locale.ENGLISH, "%s is temp file.", file.getAbsolutePath())); } if (view.isAvailable()) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(view.getContext().getPackageManager()) != null) { this.tempTakenPhoto = file;//set it in property Uri uri = FileProvider.getUriForFile(view.getContext(), GRANT_PERMISSION, file); intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); //fileProvider requires gran permission to others access that uri if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { final Context context = view.getContext(); List<ResolveInfo> infos = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (infos != null) { StreamSupport.stream(infos).filter(x -> x.activityInfo != null) .map(x -> x.activityInfo.packageName).forEach(pack -> { context.grantUriPermission(pack, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); }); } } view.startActivityForResult(intent, REQUEST_TAKE_PHOTO); } else { view.showError("You need to install app that can capture photo."); } } }, this::log); }
From source file:com.orpheusdroid.screenrecorder.adapter.VideoRecyclerAdapter.java
/** * Share the videos selected/* w w w. j a v a 2 s . c om*/ * * @param position Integer value representing the position of the video to be shared * @see #shareVideos(ArrayList positions) */ private void shareVideo(int position) { Uri fileUri = FileProvider.getUriForFile(context, context.getPackageName() + ".provider", videos.get(position).getFile()); Intent Shareintent = new Intent().setAction(Intent.ACTION_SEND).setType("video/*") .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION).putExtra(Intent.EXTRA_STREAM, fileUri); context.startActivity( Intent.createChooser(Shareintent, context.getString(R.string.share_intent_notification_title))); }
From source file:net.gerosyab.dailylog.activity.MainActivity.java
private void exportCategory(final long id) { //?? ? ?? csv //? ?? ?? //w w w . jav a2s. c o m // ? ? ? ? Category category = categories.get((int) id); ProgressDialog progressDialog = new ProgressDialog(MainActivity.this); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.setTitle("Exporting data [" + category.getName() + "]"); progressDialog.show(); String filename = category.getName() + "" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".data"; FileOutputStream outputStream = null; File resultFilePath = null; File resultFile = null; CSVWriter cw = null; try { resultFile = new File(context.getCacheDir(), filename); outputStream = new FileOutputStream(resultFile.getAbsolutePath()); // cw = new CSVWriter(new OutputStreamWriter(outputStream, "UTF-8"),'\t', '"'); cw = new CSVWriter(new OutputStreamWriter(outputStream, "UTF-8"), ',', '"'); // Export Data String[] metaDataStr = { "Version:" + AppDatabase.VERSION, "Name:" + category.getName(), "Unit:" + category.getUnit(), "Type:" + category.getRecordType(), "DefaultValue:" + category.getDefaultValue(), "Columns:date(yyyy-MM-dd 24HH:mm:ss)/value(boolean|numeric|string)" }; cw.writeNext(metaDataStr); List<Record> records = category.getRecordsOrderByDateAscending(realm); for (Record record : records) { String value = null; if (category.getRecordType() == StaticData.RECORD_TYPE_BOOLEAN) { value = "true"; } else if (category.getRecordType() == StaticData.RECORD_TYPE_NUMBER) { value = "" + record.getNumber(); } else if (category.getRecordType() == StaticData.RECORD_TYPE_MEMO) { value = record.getString(); } String[] s = { record.getDateString(StaticData.fmtForBackup), value }; cw.writeNext(s); } cw.close(); outputStream.close(); progressDialog.dismiss(); Uri fileUri = FileProvider.getUriForFile(context, "net.gerosyab.dailylog.fileprovider", resultFile); Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, fileUri); shareIntent.setType("text/plain"); startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to))); } catch (UnsupportedEncodingException e) { Log.e("DailyLog", e.getMessage()); e.printStackTrace(); } catch (IllegalArgumentException e) { Log.e("DailyLog", e.getMessage()); e.printStackTrace(); } catch (Exception e) { Log.e("DailyLog", e.getMessage()); e.printStackTrace(); } finally { progressDialog.dismiss(); } }
From source file:com.android.mms.transaction.RetrieveTransaction.java
public void sendAcknowledgeInd() { if (mMessageUri == null) { MmsLog.w(MmsApp.TXN_TAG, "RetrieveTransaction: mMessageUri is null"); return;/*from ww w .j a va 2 s . c om*/ } // Send M-Acknowledge.ind to MMSC if required. // If the Transaction-ID isn't set in the M-Retrieve.conf, it means // the MMS proxy-relay doesn't require an ACK. MmsLog.i(MmsApp.TXN_TAG, "RetrieveTransaction: sendAcknowledgeInd()"); try { Uri uri = Uri.parse(mMessageUri); PduPersister persister = PduPersister.getPduPersister(mContext); RetrieveConf retrieveConf = null; retrieveConf = (RetrieveConf) persister.load(uri); byte[] tranId = retrieveConf.getTransactionId(); if (tranId != null) { // Create M-Acknowledge.ind AcknowledgeInd acknowledgeInd = new AcknowledgeInd(PduHeaders.CURRENT_MMS_VERSION, tranId); // insert the 'from' address per spec String lineNumber = MessageUtils.getLocalNumber(mSubId); if (lineNumber != null) { acknowledgeInd.setFrom(new EncodedStringValue(lineNumber)); } else { MmsLog.d(MmsApp.TXN_TAG, "getLocalNumber(" + mSubId + "),return null"); } /// M:Code analyze 012,add for new feature,judge if it is allowed /// to send delivery report for acknowledgeInd transaction @{ /// M: modify for MmsPreference Plugin @{ mOpRetrieveTransactionExt.sendAcknowledgeInd(mContext, mSubId, acknowledgeInd); /// @} byte[] datas = new PduComposer(mContext, acknowledgeInd).make(); File pduFile = createPduFile(datas, ACK_RESP_NAME + mUri.getLastPathSegment()); if (pduFile == null) { return; } SmsManager manager = SmsManager.getSmsManagerForSubscriptionId(mSubId); /* Intent intent = new Intent(TransactionService.ACTION_TRANSACION_PROCESSED); intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId); // intent.putExtra(TransactionBundle.URI, mUri.toString()); PendingIntent sentIntent = PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); */ // Pack M-NotifyResp.ind and send it Uri pduFileUri = FileProvider.getUriForFile(mContext, MMS_FILE_PROVIDER_AUTHORITIES, pduFile); if (MmsConfig.getNotifyWapMMSC()) { manager.sendMultimediaMessage(mContext, pduFileUri, mContentLocation, null, null); } else { manager.sendMultimediaMessage(mContext, pduFileUri, null, null, null); } } } catch (MmsException ex) { ex.printStackTrace(); } }
From source file:com.team.formal.eyeshopping.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Bitmap bitmap = null;/*from ww w . j a va 2 s .com*/ if (requestCode == GALLERY_IMAGE_REQUEST && resultCode == RESULT_OK && data != null) { bitmap = uploadImage(data.getData()); Intent intent = new Intent(getApplicationContext(), ActivityShowVisuallySimilarImages.class); intent.putExtra("uri", our_uri); startActivityForResult(intent, SHOW_VISUALLY_SIMILAR_IMAGES_REQUEST); } else if (requestCode == CAMERA_IMAGE_REQUEST && resultCode == RESULT_OK) { Uri photoUri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".provider", getCameraFile()); bitmap = uploadImage(photoUri); Intent intent = new Intent(getApplicationContext(), ActivityShowVisuallySimilarImages.class); intent.putExtra("uri", our_uri); startActivityForResult(intent, SHOW_VISUALLY_SIMILAR_IMAGES_REQUEST); } }
From source file:br.com.brolam.cloudvision.ui.helpers.ImagesHelper.java
/** * Recuperar o endereo no File Provider conforme a chave de um Note Vision. * @param noteVisionKey informar uma chave vlida. * @return Uri com o endereo da imagem no File Provider. */// www. j av a2s. c om private Uri getImageUriFileProvider(String noteVisionKey) { File imageFile = new File(getImageUriFile(noteVisionKey).getPath()); return FileProvider.getUriForFile(this.activity, "br.com.brolam.cloudvision.fileprovider", imageFile); }
From source file:com.mbientlab.metawear.app.AccelerometerFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { checkboxes = new HashMap<>(); checkboxes.put(CheckBoxName.TAP, (CheckBox) view.findViewById(R.id.checkBox1)); checkboxes.put(CheckBoxName.SHAKE, (CheckBox) view.findViewById(R.id.checkBox2)); checkboxes.put(CheckBoxName.ORIENTATION, (CheckBox) view.findViewById(R.id.checkBox3)); checkboxes.put(CheckBoxName.FREE_FALL, (CheckBox) view.findViewById(R.id.checkBox4)); checkboxes.put(CheckBoxName.SAMPLING, (CheckBox) view.findViewById(R.id.checkBox5)); ((Button) view.findViewById(R.id.button3)).setOnClickListener(new OnClickListener() { @Override/*from w w w. j a va 2s.co m*/ public void onClick(View arg0) { if (mwMnger.controllerReady()) { accelController.stopComponents(); accelController.disableAllDetection(true); for (CheckBox box : checkboxes.values()) { box.setEnabled(true); } } else { Toast.makeText(getActivity(), R.string.error_connect_board, Toast.LENGTH_LONG).show(); } } }); ((Button) view.findViewById(R.id.button1)).setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (mwMnger.controllerReady()) { if (checkboxes.get(CheckBoxName.TAP).isChecked()) { accelController.enableTapDetection(TapType.values()[accelConfig.tapTypePos()], Axis.values()[accelConfig.tapAxisPos()]); } if (checkboxes.get(CheckBoxName.SHAKE).isChecked()) { accelController.enableShakeDetection(Axis.values()[accelConfig.shakeAxisPos()]); } if (checkboxes.get(CheckBoxName.ORIENTATION).isChecked()) { accelController.enableOrientationDetection(); } if (checkboxes.get(CheckBoxName.FREE_FALL).isChecked()) { if (accelConfig.movementPos() == 0) { accelController.enableFreeFallDetection(); } else { accelController.enableMotionDetection(Axis.values()); } } if (checkboxes.get(CheckBoxName.SAMPLING).isChecked()) { rmsValues = new Vector<>(); SamplingConfig config = accelController.enableXYZSampling(); config.withFullScaleRange(FullScaleRange.values()[accelConfig.fsrPos()]) .withOutputDataRate(OutputDataRate.values()[accelConfig.odrPos()]); accelConfig.initialize(config.getBytes()); start = 0; } accelController.startComponents(); for (CheckBox box : checkboxes.values()) { box.setEnabled(false); } } else { Toast.makeText(getActivity(), R.string.error_connect_board, Toast.LENGTH_LONG).show(); } } }); ((Button) view.findViewById(R.id.button2)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { final FragmentManager fm = getActivity().getSupportFragmentManager(); final AccelerometerSettings dialog = new AccelerometerSettings(); dialog.show(fm, "accelerometer_settings"); } }); ((Button) view.findViewById(R.id.textView10)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (accelConfig.polledBytes() == null) { Toast.makeText(getActivity(), R.string.error_no_accel_data, Toast.LENGTH_SHORT).show(); } else { final FragmentManager fm = getActivity().getSupportFragmentManager(); final DataPlotFragment dialog = new DataPlotFragment(); dialog.show(fm, "resistance_graph_fragment"); } } }); ((Button) view.findViewById(R.id.textView11)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (accelConfig.polledBytes() == null) { Toast.makeText(getActivity(), R.string.error_no_accel_data, Toast.LENGTH_SHORT).show(); } else { writeDataToFile(); Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, "Logged Accelerometer Data"); File file = getActivity().getFileStreamPath(dataFilename); Uri uri = FileProvider.getUriForFile(getActivity(), "com.mbientlab.metawear.app.fileprovider", file); intent.putExtra(Intent.EXTRA_STREAM, uri); startActivity(Intent.createChooser(intent, "Send email...")); } } }); }
From source file:de.kaidev.vertretungsplanapp.MainActivity.java
@Override public void downloadPostExecute(File result) { downloadClearUI();/*from www .j av a 2 s.c om*/ startActivity(new Intent(Intent.ACTION_VIEW).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) .setDataAndType( FileProvider.getUriForFile(this, "de.kaidev.vertretungsplanapp.file_provider", result), "application/vnd.android.package-archive") .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); }
From source file:com.orpheusdroid.screenrecorder.adapter.VideoRecyclerAdapter.java
/** * Share the videos selected//from w w w. ja v a 2s . co m * * @param positions Integer ArrayList containing the positions of the videos to be shared * * @see #shareVideo(int postion) */ private void shareVideos(ArrayList<Integer> positions) { ArrayList<Uri> videoList = new ArrayList<>(); for (int position : positions) { videoList.add(FileProvider.getUriForFile(context, context.getPackageName() + ".provider", videos.get(position).getFile())); } Intent Shareintent = new Intent().setAction(Intent.ACTION_SEND_MULTIPLE).setType("video/*") .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) .putParcelableArrayListExtra(Intent.EXTRA_STREAM, videoList); context.startActivity( Intent.createChooser(Shareintent, context.getString(R.string.share_intent_notification_title))); }
From source file:org.odk.collect.android.widgets.VideoWidget.java
private void playVideoFile() { Intent intent = new Intent("android.intent.action.VIEW"); File file = new File(getInstanceFolder() + File.separator + binaryName); Uri uri = FileProvider.getUriForFile(getContext(), BuildConfig.APPLICATION_ID + ".provider", file); FileUtils.grantFileReadPermissions(intent, uri, getContext()); intent.setDataAndType(uri, "video/*"); try {//from w w w.j av a 2s .co m getContext().startActivity(intent); } catch (ActivityNotFoundException e) { Toast.makeText(getContext(), getContext().getString(R.string.activity_not_found, getContext().getString(R.string.view_video)), Toast.LENGTH_SHORT).show(); } }