Android Utilities
Helpers for UI-thread work, Android listeners, 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:
- running code on the UI thread
- attaching simple click listeners
- copying text to the clipboard
For logging, use self.logger.
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 (legacy)
Legacy
log() is kept for existing plugins. New code should use self.logger: it has levels, a per-plugin logcat tag, tracebacks and object dumps.
log(data) writes to logcat at debug level:
- simple values such as
str,int,float,bool, andNoneare logged as text - any other object is logged as its
dump()
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.