Class AndroidUtils
Provides Android helpers: the app's name, the UI thread, the device's ID, toasts, and what kind of device it is.
public static class AndroidUtils
- Inheritance
-
AndroidUtils
- Inherited Members
Methods
GetAppName(Context?)
Gets the app's name, as Android labels it.
public static string GetAppName(Context? context)
Parameters
contextContextThe context.
Returns
- string
The name.
Exceptions
- ArgumentNullException
context, its package name or its package manager is null.
GetDeviceId(Context)
Gets the device's Android ID: from Android 8, one for each app signing key, user and device.
public static string? GetDeviceId(Context context)
Parameters
contextContextThe context.
Returns
IsPhone(Context?)
Determines whether the device is a phone, as Chrome tells one by its "Mobile": narrower than a tablet's 600 dp, and no TV, which the width alone would take for a phone (a 1080p TV is 540 dp).
public static bool IsPhone(Context? context = null)
Parameters
contextContextThe context, or null for the application's; an activity is measured by the largest window the display gives it, from Android 11.
Returns
IsTv(Context?)
Determines whether the device is a TV: in TV mode, or with the leanback feature.
public static bool IsTv(Context? context = null)
Parameters
Returns
RunOnUiThread(Activity, Action)
Runs an action on the activity's UI thread: at once where the caller is on it, or else queued there.
public static Task RunOnUiThread(Activity activity, Action action)
Parameters
Returns
- Task
A task that completes when the action has run, or fails with its exception.
Remarks
An awaiting caller may resume on the UI thread.
RunOnUiThread<T>(Activity, Func<T>)
Runs a function on the activity's UI thread: at once where the caller is on it, or else queued there.
public static Task<T> RunOnUiThread<T>(Activity activity, Func<T> action)
Parameters
Returns
- Task<T>
A task whose result is the function's, or that fails with its exception.
Type Parameters
TThe type of the function's result.
Remarks
An awaiting caller may resume on the UI thread.
ShowToast(string)
Shows a short toast, from any thread; one that cannot be shown is logged.
public static void ShowToast(string message)
Parameters
messagestringThe message.