use of androidx.documentfile.provider.DocumentFile in project kdeconnect-android by KDE.
the class CompositeReceiveFileJob method openFile.
private void openFile(DocumentFile fileDocument) {
String mimeType = FilesHelper.getMimeTypeFromFile(fileDocument.getName());
Intent intent = new Intent(Intent.ACTION_VIEW);
if (Build.VERSION.SDK_INT >= 24) {
// Nougat and later require "content://" uris instead of "file://" uris
File file = new File(fileDocument.getUri().getPath());
Uri contentUri = FileProvider.getUriForFile(getDevice().getContext(), "org.kde.kdeconnect_tp.fileprovider", file);
intent.setDataAndType(contentUri, mimeType);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK);
} else {
intent.setDataAndType(fileDocument.getUri(), mimeType);
}
// Open files for KDE Itinerary explicitly because Android's activity resolution sucks
if (fileDocument.getName().endsWith(".itinerary")) {
intent.setClassName("org.kde.itinerary", "org.kde.itinerary.Activity");
}
getDevice().getContext().startActivity(intent);
}
use of androidx.documentfile.provider.DocumentFile in project AntennaPod by AntennaPod.
the class LocalFeedUpdaterTest method callUpdateFeed.
/**
* Calls the method {@link LocalFeedUpdater#updateFeed(Feed, Context)} with
* the given local feed folder.
*
* @param localFeedDir assets local feed folder with media files
*/
private void callUpdateFeed(@NonNull String localFeedDir) {
DocumentFile documentFile = new AssetsDocumentFile(localFeedDir, context.getAssets());
try (MockedStatic<DocumentFile> dfMock = Mockito.mockStatic(DocumentFile.class)) {
// mock external storage
dfMock.when(() -> DocumentFile.fromTreeUri(any(), any())).thenReturn(documentFile);
// call method to test
Feed feed = new Feed(FEED_URL, null);
LocalFeedUpdater.updateFeed(feed, context);
}
}
use of androidx.documentfile.provider.DocumentFile in project AntennaPod by AntennaPod.
the class LocalFeedUpdaterTest method testGetImageUrl_OtherImageFilenamePng.
@Test
public void testGetImageUrl_OtherImageFilenamePng() {
DocumentFile documentFolder = mockDocumentFolder(mockDocumentFile("audio.mp3", "audio/mp3"), mockDocumentFile("my-image.png", "image/png"));
String imageUrl = LocalFeedUpdater.getImageUrl(context, documentFolder);
assertThat(imageUrl, endsWith("my-image.png"));
}
use of androidx.documentfile.provider.DocumentFile in project AntennaPod by AntennaPod.
the class LocalFeedUpdaterTest method mockDocumentFile.
/**
* Create a DocumentFile mock object.
*/
@NonNull
private static DocumentFile mockDocumentFile(@NonNull String fileName, @NonNull String mimeType) {
DocumentFile file = mock(DocumentFile.class);
when(file.getName()).thenReturn(fileName);
when(file.getUri()).thenReturn(Uri.parse("file:///path/" + fileName));
when(file.getType()).thenReturn(mimeType);
return file;
}
use of androidx.documentfile.provider.DocumentFile in project AntennaPod by AntennaPod.
the class LocalFeedUpdaterTest method testGetImageUrl_OtherImageFilenameJpeg.
@Test
public void testGetImageUrl_OtherImageFilenameJpeg() {
DocumentFile documentFolder = mockDocumentFolder(mockDocumentFile("audio.mp3", "audio/mp3"), mockDocumentFile("my-image.jpeg", "image/jpeg"));
String imageUrl = LocalFeedUpdater.getImageUrl(context, documentFolder);
assertThat(imageUrl, endsWith("my-image.jpeg"));
}
Aggregations