Android: Clear the clipboard when getting a null mimedata
From API 28 it is possible to clear the clipboard so we should ensure that this is done if API 28 or later is being used. Otherwise it is not removed, but that is due to limitations on the Android side. Pick-to: 5.15 Change-Id: I1fe504d0e566c6923b39b2adf4540619c6b1daf7 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
parent
6a2224fd58
commit
f71a400bf6
@ -847,6 +847,8 @@ public class QtNative
|
||||
|
||||
private static void clearClipData()
|
||||
{
|
||||
if (Build.VERSION.SDK_INT >= 28 && m_clipboardManager != null && m_usePrimaryClip)
|
||||
m_clipboardManager.clearPrimaryClip();
|
||||
m_usePrimaryClip = false;
|
||||
}
|
||||
private static void setClipboardText(String text)
|
||||
|
@ -63,9 +63,13 @@ namespace QtAndroidClipboard
|
||||
return;
|
||||
}
|
||||
}
|
||||
void setClipboardMimeData(QMimeData *data)
|
||||
void clearClipboardData()
|
||||
{
|
||||
QJNIObjectPrivate::callStaticMethod<void>(applicationClass(), "clearClipData");
|
||||
}
|
||||
void setClipboardMimeData(QMimeData *data)
|
||||
{
|
||||
clearClipboardData();
|
||||
if (data->hasText()) {
|
||||
QJNIObjectPrivate::callStaticMethod<void>(applicationClass(),
|
||||
"setClipboardText", "(Ljava/lang/String;)V",
|
||||
|
@ -53,6 +53,7 @@ namespace QtAndroidClipboard
|
||||
void setClipboardManager(QAndroidPlatformClipboard *manager);
|
||||
void setClipboardMimeData(QMimeData *data);
|
||||
QMimeData *getClipboardMimeData();
|
||||
void clearClipboardData();
|
||||
void onClipboardDataChanged(JNIEnv */*env*/, jobject /*thiz*/);
|
||||
// Clipboard support
|
||||
}
|
||||
|
@ -66,6 +66,10 @@ QMimeData *QAndroidPlatformClipboard::mimeData(QClipboard::Mode mode)
|
||||
|
||||
void QAndroidPlatformClipboard::setMimeData(QMimeData *data, QClipboard::Mode mode)
|
||||
{
|
||||
if (!data) {
|
||||
QtAndroidClipboard::clearClipboardData();
|
||||
return;
|
||||
}
|
||||
if (data && supportsMode(mode))
|
||||
QtAndroidClipboard::setClipboardMimeData(data);
|
||||
if (data != 0)
|
||||
|
Loading…
Reference in New Issue
Block a user