Android Utilities
Helpers for UI-thread work, Android listeners, logging, clipboard access, and Java Runnable wrappers.
This module provides small but very frequently used helpers for Android-side work inside plugins.
Most of the time you will use it for three things:
- running code on the UI thread
- attaching simple click listeners
- logging and quick debugging
Wrappers for Java Interfaces
These wrappers let you pass Python callables into Android APIs that expect Java listener objects.
R (Runnable Proxy)
R(fn) creates a real Java Runnable backed by your Python callable.
This is useful when some Android or Telegram API expects a java.lang.Runnable instance, for example view.post(...), delayed callbacks, or various internal helper methods.
`run_on_ui_thread` already wraps your callable
run_on_ui_thread(...) accepts a normal Python callable and internally converts it to a Java Runnable for you.
Use R(...) when some other API explicitly requires a Runnable object.
OnClickListener
OnClickListener(fn) is a convenience wrapper for android.view.View.OnClickListener.
Your callable receives the clicked View as its only argument.
OnLongClickListener
OnLongClickListener(fn) is a convenience wrapper for android.view.View.OnLongClickListener.
The wrapped Python callable is expected to return a boolean:
True: consume the long-click eventFalse: let Android continue processing it
Utility Functions
run_on_ui_thread
run_on_ui_thread(func, delay=0) schedules a Python callable on the Android UI thread.
Any UI mutation should happen there: changing text, updating views, showing dialogs, attaching adapters, and so on.
Parameters:
func: Python callable to executedelay: optional delay in milliseconds
log
log(data) sends data into the app's logging pipeline.
It behaves slightly differently depending on the value you pass:
- simple values such as
str,int,float,bool, andNoneare logged as text - complex objects are passed to the Java-side object inspector, which is useful for debugging Telegram and Android objects
copy_to_clipboard
copy_to_clipboard(text) copies a string to the Android clipboard and, if the operation succeeds, shows the standard "copied" bulletin.
This is handy for deeplinks, debug info, exported IDs, or user-facing share actions.