mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-03 15:45:10 +00:00
Fix file opening
Summary: During the SharePlugin refactoring the way the mime type was determined changed which broke opening files from the desktop. Test Plan: I can open pkpass/jsonld files in Itinerary again Reviewers: #kde_connect, albertvaka Reviewed By: #kde_connect, albertvaka Subscribers: eduisters, kdeconnect Tags: #kde_connect Differential Revision: https://phabricator.kde.org/D17976
This commit is contained in:
@@ -310,15 +310,16 @@ class CompositeReceiveFileRunnable implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void openFile(DocumentFile fileDocument) {
|
private void openFile(DocumentFile fileDocument) {
|
||||||
|
String mimeType = FilesHelper.getMimeTypeFromFile(fileDocument.getName());
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
if (Build.VERSION.SDK_INT >= 24) {
|
if (Build.VERSION.SDK_INT >= 24) {
|
||||||
//Nougat and later require "content://" uris instead of "file://" uris
|
//Nougat and later require "content://" uris instead of "file://" uris
|
||||||
File file = new File(fileDocument.getUri().getPath());
|
File file = new File(fileDocument.getUri().getPath());
|
||||||
Uri contentUri = FileProvider.getUriForFile(device.getContext(), "org.kde.kdeconnect_tp.fileprovider", file);
|
Uri contentUri = FileProvider.getUriForFile(device.getContext(), "org.kde.kdeconnect_tp.fileprovider", file);
|
||||||
intent.setDataAndType(contentUri, fileDocument.getType());
|
intent.setDataAndType(contentUri, mimeType);
|
||||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
} else {
|
} else {
|
||||||
intent.setDataAndType(fileDocument.getUri(), fileDocument.getType());
|
intent.setDataAndType(fileDocument.getUri(), mimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
device.getContext().startActivity(intent);
|
device.getContext().startActivity(intent);
|
||||||
|
Reference in New Issue
Block a user