mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-02 15:15:09 +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:
committed by
Philip Cohn-Cort
parent
d2edd7a325
commit
3bfae23d1b
@@ -316,7 +316,7 @@
|
|||||||
<string name="permission_explanation">This plugin needs permissions to work</string>
|
<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="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="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="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_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>
|
<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>
|
||||||
|
@@ -132,20 +132,15 @@ class ReceiveNotification {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!"file".equals(destinationUri.getScheme())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
||||||
shareIntent.setType(mimeType);
|
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
|
//Nougat and later require "content://" uris instead of "file://" uris
|
||||||
File file = new File(destinationUri.getPath());
|
File file = new File(destinationUri.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, mimeType);
|
intent.setDataAndType(contentUri, mimeType);
|
||||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
|
|
||||||
shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
|
shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
|
||||||
} else {
|
} else {
|
||||||
intent.setDataAndType(destinationUri, mimeType);
|
intent.setDataAndType(destinationUri, mimeType);
|
||||||
|
@@ -13,7 +13,9 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Environment;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -23,6 +25,7 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.annotation.WorkerThread;
|
import androidx.annotation.WorkerThread;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.kde.kdeconnect.Helpers.FilesHelper;
|
import org.kde.kdeconnect.Helpers.FilesHelper;
|
||||||
import org.kde.kdeconnect.Helpers.IntentHelper;
|
import org.kde.kdeconnect.Helpers.IntentHelper;
|
||||||
@@ -127,12 +130,7 @@ public class SharePlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (np.has("filename")) {
|
if (np.has("filename")) {
|
||||||
if (isPermissionGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
|
||||||
receiveFile(np);
|
receiveFile(np);
|
||||||
} else {
|
|
||||||
Log.i("SharePlugin", "no Permission for Storage");
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (np.has("text")) {
|
} else if (np.has("text")) {
|
||||||
Log.i("SharePlugin", "hasText");
|
Log.i("SharePlugin", "hasText");
|
||||||
receiveText(np);
|
receiveText(np);
|
||||||
@@ -289,8 +287,12 @@ public class SharePlugin extends Plugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getOptionalPermissions() {
|
public String[] getOptionalPermissions() {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
return ArrayUtils.EMPTY_STRING_ARRAY;
|
||||||
|
} else {
|
||||||
return new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE};
|
return new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class Callback implements BackgroundJob.Callback<Void> {
|
private class Callback implements BackgroundJob.Callback<Void> {
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user