2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 21:55:10 +00:00

Share Plugin: improvements for Android 11

* Do not ask for WRITE_EXTERNAL_STORAGE in Android 11+ (writing to "Downloads" is [allowed by default since 11](https://stackoverflow.com/questions/70248631/starting-from-android11-do-i-need-to-comply-to-androids-saf-just-to-even-creat)).
* Do not check for permissions before receiving a file. Try and let it error out, instead of silently doing nothing.
* Fix not offering to open content:// urls (we checked the URLs to be file:// urls to then convert them to content://).
* Better permission explanation text.
This commit is contained in:
Albert Vaca Cintora
2023-03-15 22:01:39 +00:00
committed by Philip Cohn-Cort
parent d2edd7a325
commit 3bfae23d1b
3 changed files with 11 additions and 14 deletions

View File

@@ -316,7 +316,7 @@
<string name="permission_explanation">This plugin needs permissions to work</string>
<string name="optional_permission_explanation">You need to grant extra permissions to enable all functions</string>
<string name="plugins_need_optional_permission">Some plugins have features disabled because of lack of permission (tap for more info):</string>
<string name="share_optional_permission_explanation">To receive shared files you need to choose a destination directory</string>
<string name="share_optional_permission_explanation">To receive files you need to allow storage access</string>
<string name="telepathy_permission_explanation">To read and write SMS from your desktop you need to give permission to SMS</string>
<string name="telephony_permission_explanation">To see phone calls on the desktop you need to give permission to phone call logs and phone state</string>
<string name="telephony_optional_permission_explanation">To see a contact name instead of a phone number you need to give access to the phone\'s contacts</string>

View File

@@ -132,20 +132,15 @@ class ReceiveNotification {
}
}
if (!"file".equals(destinationUri.getScheme())) {
return;
}
Intent intent = new Intent(Intent.ACTION_VIEW);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType(mimeType);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && "file".equals(destinationUri.getScheme())) {
//Nougat and later require "content://" uris instead of "file://" uris
File file = new File(destinationUri.getPath());
Uri contentUri = FileProvider.getUriForFile(device.getContext(), "org.kde.kdeconnect_tp.fileprovider", file);
intent.setDataAndType(contentUri, mimeType);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
} else {
intent.setDataAndType(destinationUri, mimeType);

View File

@@ -13,7 +13,9 @@ import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
@@ -23,6 +25,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.WorkerThread;
import androidx.core.content.ContextCompat;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.kde.kdeconnect.Helpers.FilesHelper;
import org.kde.kdeconnect.Helpers.IntentHelper;
@@ -127,12 +130,7 @@ public class SharePlugin extends Plugin {
}
if (np.has("filename")) {
if (isPermissionGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
receiveFile(np);
} else {
Log.i("SharePlugin", "no Permission for Storage");
}
receiveFile(np);
} else if (np.has("text")) {
Log.i("SharePlugin", "hasText");
receiveText(np);
@@ -289,7 +287,11 @@ public class SharePlugin extends Plugin {
@Override
public String[] getOptionalPermissions() {
return new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
return ArrayUtils.EMPTY_STRING_ARRAY;
} else {
return new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE};
}
}
private class Callback implements BackgroundJob.Callback<Void> {