Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit e4ddb31

Browse files
committed
Implement hasStrings in terms of getClipboardData on Android
1 parent a627037 commit e4ddb31

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformChannel.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
155155
result.success(null);
156156
break;
157157
}
158+
case "Clipboard.hasStrings":
159+
{
160+
boolean hasStrings = platformMessageHandler.clipboardHasStrings();
161+
JSONObject response = new JSONObject();
162+
response.put("value", hasStrings);
163+
result.success(response);
164+
break;
165+
}
158166
default:
159167
result.notImplemented();
160168
break;
@@ -426,6 +434,11 @@ public interface PlatformMessageHandler {
426434
* {@code text}.
427435
*/
428436
void setClipboardData(@NonNull String text);
437+
438+
/** The Flutter application would like to know if the clipboard currently contains a string
439+
* that can be pasted.
440+
*/
441+
boolean clipboardHasStrings();
429442
}
430443

431444
/** Types of sounds the Android OS can play on behalf of an application. */

shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ public CharSequence getClipboardData(
8585
public void setClipboardData(@NonNull String text) {
8686
PlatformPlugin.this.setClipboardData(text);
8787
}
88+
89+
@Override
90+
public boolean clipboardHasStrings() {
91+
CharSequence data = PlatformPlugin.this.getClipboardData(PlatformChannel.ClipboardContentFormat.PLAIN_TEXT);
92+
return data != null && data.length() > 0;
93+
}
8894
};
8995

9096
public PlatformPlugin(Activity activity, PlatformChannel platformChannel) {

0 commit comments

Comments
 (0)