mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-01 14:45:08 +00:00
If transfer failed, don't create a pending intent nor index the file
This commit is contained in:
@@ -172,45 +172,38 @@ public class SharePlugin extends Plugin {
|
|||||||
try {
|
try {
|
||||||
Log.i("SharePlugin", "Transfer finished");
|
Log.i("SharePlugin", "Transfer finished");
|
||||||
|
|
||||||
//Make sure it is added to the Android Gallery
|
|
||||||
MediaStoreHelper.indexFile(context, destinationUri);
|
|
||||||
|
|
||||||
//Update the notification and allow to open the file from it
|
//Update the notification and allow to open the file from it
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
||||||
intent.setDataAndType(destinationUri, mimeType);
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
|
|
||||||
stackBuilder.addNextIntent(intent);
|
|
||||||
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(
|
|
||||||
0,
|
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT
|
|
||||||
);
|
|
||||||
|
|
||||||
Resources res = context.getResources();
|
Resources res = context.getResources();
|
||||||
|
|
||||||
String message = successful? res.getString(R.string.received_file_title, device.getName()) : res.getString(R.string.received_file_fail_title, device.getName());
|
String message = successful? res.getString(R.string.received_file_title, device.getName()) : res.getString(R.string.received_file_fail_title, device.getName());
|
||||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
|
||||||
.setContentTitle(message)
|
.setContentTitle(message)
|
||||||
.setTicker(message)
|
.setTicker(message)
|
||||||
.setSmallIcon(android.R.drawable.stat_sys_download_done)
|
.setSmallIcon(android.R.drawable.stat_sys_download_done)
|
||||||
.setAutoCancel(true);
|
.setAutoCancel(true);
|
||||||
|
|
||||||
if (successful) {
|
if (successful) {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
|
intent.setDataAndType(destinationUri, mimeType);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
|
||||||
|
stackBuilder.addNextIntent(intent);
|
||||||
|
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
builder.setContentText(res.getString(R.string.received_file_text, filename))
|
builder.setContentText(res.getString(R.string.received_file_text, filename))
|
||||||
.setContentIntent(resultPendingIntent);
|
.setContentIntent(resultPendingIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
if (prefs.getBoolean("share_notification_preference", true)) {
|
if (prefs.getBoolean("share_notification_preference", true)) {
|
||||||
builder.setDefaults(Notification.DEFAULT_ALL);
|
builder.setDefaults(Notification.DEFAULT_ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
NotificationHelper.notifyCompat(notificationManager, notificationId, builder.build());
|
NotificationHelper.notifyCompat(notificationManager, notificationId, builder.build());
|
||||||
|
|
||||||
|
if (successful) {
|
||||||
|
//Make sure it is added to the Android Gallery
|
||||||
|
MediaStoreHelper.indexFile(context, destinationUri);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e("SharePlugin", "Receiver thread exception");
|
Log.e("SharePlugin", "Receiver thread exception");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
Reference in New Issue
Block a user