use of android.support.v4.content.FileProvider.getUriForFile in project android_packages_apps_Dialer by LineageOS.
the class CallComposerActivity method sendAndCall.
@Override
public void sendAndCall() {
if (!sessionReady()) {
sendAndCallReady = true;
showLoadingUi();
LogUtil.i("CallComposerActivity.onClick", "sendAndCall pressed, but the session isn't ready");
Logger.get(this).logImpression(DialerImpression.Type.CALL_COMPOSER_ACTIVITY_SEND_AND_CALL_PRESSED_WHEN_SESSION_NOT_READY);
return;
}
sendAndCall.setEnabled(false);
CallComposerFragment fragment = (CallComposerFragment) adapter.instantiateItem(pager, currentIndex);
MultimediaData.Builder builder = MultimediaData.builder();
if (fragment instanceof MessageComposerFragment) {
MessageComposerFragment messageComposerFragment = (MessageComposerFragment) fragment;
builder.setText(messageComposerFragment.getMessage());
placeRCSCall(builder);
}
if (fragment instanceof GalleryComposerFragment) {
GalleryComposerFragment galleryComposerFragment = (GalleryComposerFragment) fragment;
// If the current data is not a copy, make one.
if (!galleryComposerFragment.selectedDataIsCopy()) {
DialerExecutors.createUiTaskBuilder(getFragmentManager(), "copyAndResizeImageToSend", new CopyAndResizeImageWorker(this.getApplicationContext())).onSuccess(output -> {
Uri shareableUri = FileProvider.getUriForFile(CallComposerActivity.this, Constants.get().getFileProviderAuthority(), output.first);
builder.setImage(grantUriPermission(shareableUri), output.second);
placeRCSCall(builder);
}).onFailure(throwable -> {
// TODO(b/34279096) - gracefully handle message failure
LogUtil.e("CallComposerActivity.onCopyFailed", "copy Failed", throwable);
}).build().executeParallel(galleryComposerFragment.getGalleryData().getFileUri());
} else {
Uri shareableUri = FileProvider.getUriForFile(this, Constants.get().getFileProviderAuthority(), new File(galleryComposerFragment.getGalleryData().getFilePath()));
builder.setImage(grantUriPermission(shareableUri), galleryComposerFragment.getGalleryData().getMimeType());
placeRCSCall(builder);
}
}
if (fragment instanceof CameraComposerFragment) {
CameraComposerFragment cameraComposerFragment = (CameraComposerFragment) fragment;
cameraComposerFragment.getCameraUriWhenReady(uri -> {
builder.setImage(grantUriPermission(uri), cameraComposerFragment.getMimeType());
placeRCSCall(builder);
});
}
}
use of android.support.v4.content.FileProvider.getUriForFile in project PainlessMusicPlayer by Doctoror.
the class MediaBrowserImpl method createMediaItemAlbum.
@NonNull
private MediaItem createMediaItemAlbum(@NonNull final Cursor c) {
final MediaDescriptionCompat.Builder description = new MediaDescriptionCompat.Builder().setMediaId(MediaBrowserConstants.MEDIA_ID_PREFIX_ALBUM.concat(c.getString(AlbumsProvider.COLUMN_ID))).setTitle(c.getString(AlbumsProvider.COLUMN_ALBUM));
final String art = c.getString(AlbumsProvider.COLUMN_ALBUM_ART);
if (!TextUtils.isEmpty(art)) {
final Uri uri = FileProvider.getUriForFile(mContext, mContext.getPackageName().concat(".provider.album_thumbs"), new File(art));
for (final String p : mMediaBrowserCallerPackageNames) {
mContext.grantUriPermission(p, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
description.setIconUri(uri);
}
return new MediaItem(description.build(), MediaItem.FLAG_PLAYABLE);
}
use of android.support.v4.content.FileProvider.getUriForFile in project cw-omnibus by commonsguy.
the class Downloader method raiseNotification.
private void raiseNotification(Intent inbound, File output, Exception e) {
NotificationCompat.Builder b = new NotificationCompat.Builder(this);
b.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL).setWhen(System.currentTimeMillis());
if (e == null) {
b.setContentTitle(getString(R.string.download_complete)).setContentText(getString(R.string.fun)).setSmallIcon(android.R.drawable.stat_sys_download_done).setTicker(getString(R.string.download_complete));
Intent outbound = new Intent(Intent.ACTION_VIEW);
Uri outputUri = FileProvider.getUriForFile(this, AUTHORITY, output);
outbound.setDataAndType(outputUri, inbound.getType());
outbound.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
PendingIntent pi = PendingIntent.getActivity(this, 0, outbound, PendingIntent.FLAG_UPDATE_CURRENT);
b.setContentIntent(pi);
} else {
b.setContentTitle(getString(R.string.exception)).setContentText(e.getMessage()).setSmallIcon(android.R.drawable.stat_notify_error).setTicker(getString(R.string.exception));
}
NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mgr.notify(NOTIFY_ID, b.build());
}
use of android.support.v4.content.FileProvider.getUriForFile in project cw-omnibus by commonsguy.
the class Downloader method raiseNotification.
private void raiseNotification(String mimeType, File output, Exception e) {
NotificationCompat.Builder b = new NotificationCompat.Builder(this);
b.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL);
if (e == null) {
b.setContentTitle(getString(R.string.download_complete)).setContentText(getString(R.string.fun)).setSmallIcon(android.R.drawable.stat_sys_download_done).setTicker(getString(R.string.download_complete));
Intent outbound = new Intent(Intent.ACTION_VIEW);
Uri outputUri = FileProvider.getUriForFile(this, AUTHORITY, output);
outbound.setDataAndType(outputUri, mimeType);
outbound.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
PendingIntent pi = PendingIntent.getActivity(this, 0, outbound, PendingIntent.FLAG_UPDATE_CURRENT);
b.setContentIntent(pi);
} else {
b.setContentTitle(getString(R.string.exception)).setContentText(e.getMessage()).setSmallIcon(android.R.drawable.stat_notify_error).setTicker(getString(R.string.exception));
}
NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mgr.notify(NOTIFY_ID, b.build());
}
use of android.support.v4.content.FileProvider.getUriForFile in project LeafPic by HoraApps.
the class StorageHelper method getMediaPath.
public static String getMediaPath(final Context context, final Uri uri) {
// DocumentProvider
if (DocumentsContract.isDocumentUri(context, uri)) {
// ExternalStorageProvider
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
if ("primary".equalsIgnoreCase(type)) {
return Environment.getExternalStorageDirectory() + "/" + split[1];
}
// TODO handle non-primary volumes
} else // DownloadsProvider
if (isDownloadsDocument(uri)) {
final String id = DocumentsContract.getDocumentId(uri);
final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
return getDataColumn(context, contentUri, null, null);
} else // MediaProvider
if (isMediaDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
Uri contentUri = null;
if ("image".equals(type)) {
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
} else if ("video".equals(type)) {
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} else if ("audio".equals(type)) {
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
final String selection = "_id=?";
final String[] selectionArgs = new String[] { split[1] };
return getDataColumn(context, contentUri, selection, selectionArgs);
}
} else if ("downloads".equals(uri.getAuthority())) {
// download for chrome-dev workaround
String[] seg = uri.toString().split("/");
final String id = seg[seg.length - 1];
final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
return getDataColumn(context, contentUri, null, null);
} else // MediaStore (and general)
if ("content".equalsIgnoreCase(uri.getScheme())) {
try {
// easy way
String a = getDataColumn(context, uri, null, null);
if (a != null)
return a;
} catch (Exception ignored) {
}
// work around for general uri generated by FileProvider.getUriForFile()
String[] split = uri.getPath().split("/");
int z = -1, len = split.length;
for (int i = 0; i < len; i++) {
if (split[i].equals("external_files")) {
z = i;
break;
}
}
if (z != -1) {
StringBuilder partialPath = new StringBuilder();
for (int i = z + 1; i < len; i++) partialPath.append(split[i]).append('/');
String p = partialPath.toString();
for (File file : StorageHelper.getStorageRoots(context)) {
File f = new File(file, p);
if (f.exists())
return f.getPath();
}
}
} else // File
if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();
}
return null;
}
Aggregations