mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-22 01:51:47 +00:00
Add share action button to received file notification
Summary: You can share the just-received file. It doesn't work with a custom download directory (just like opening such files doesn't work yet). It also won't close the notification once shared. Test Plan: Sharing to other apps works. Reviewers: #kde_connect, nicolasfella Reviewed By: #kde_connect, nicolasfella Subscribers: nicolasfella, #kde_connect Tags: #kde_connect Differential Revision: https://phabricator.kde.org/D11680
This commit is contained in:
parent
7c8301a7cc
commit
94ef1294c5
9
res/drawable/ic_share_white.xml
Normal file
9
res/drawable/ic_share_white.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z"/>
|
||||
</vector>
|
@ -177,6 +177,8 @@
|
||||
<string name="share_destination_customize_summary_disabled">Received files will appear in Downloads</string>
|
||||
<string name="share_destination_customize_summary_enabled">Files will be stored in the directory below</string>
|
||||
<string name="share_destination_folder_preference">Destination directory</string>
|
||||
<string name="share">Share</string>
|
||||
<string name="share_received_file">Share \"%s\"</string>
|
||||
<string name="title_activity_notification_filter">Notification filter</string>
|
||||
<string name="filter_apps_info">Notifications will be synchronized for the selected apps.</string>
|
||||
<string name="sftp_internal_storage">Internal storage</string>
|
||||
|
@ -119,20 +119,34 @@ public class ShareNotification {
|
||||
}
|
||||
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
||||
shareIntent.setType(mimeType);
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
//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);
|
||||
shareIntent.putExtra(Intent.EXTRA_STREAM, destinationUri);
|
||||
}
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
TaskStackBuilder stackBuilder = TaskStackBuilder.create(device.getContext());
|
||||
stackBuilder.addNextIntent(intent);
|
||||
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
builder.setContentText(device.getContext().getResources().getString(R.string.received_file_text, filename))
|
||||
.setContentIntent(resultPendingIntent);
|
||||
|
||||
shareIntent = Intent.createChooser(shareIntent,
|
||||
device.getContext().getString(R.string.share_received_file, destinationUri.getLastPathSegment()));
|
||||
PendingIntent sharePendingIntent = PendingIntent.getActivity(device.getContext(), 0,
|
||||
shareIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
NotificationCompat.Action.Builder shareAction = new NotificationCompat.Action.Builder(
|
||||
R.drawable.ic_share_white, device.getContext().getString(R.string.share), sharePendingIntent);
|
||||
builder.addAction(shareAction.build());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user