Table of Contents

Class AndroidUtils

Namespace
VpnHood.Core.Client.Devices.Android.Utils
Assembly
VpnHood.Core.Client.Devices.Android.dll

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

context Context

The 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

context Context

The context.

Returns

string

The ID, or null where Android gives none or it cannot be read, which is logged.

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

context Context

The context, or null for the application's; an activity is measured by the largest window the display gives it, from Android 11.

Returns

bool

true if the device is a phone; otherwise, false.

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

context Context

The context, or null for the application's.

Returns

bool

true if the device is a TV; otherwise, false.

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

activity Activity

The activity.

action Action

The action.

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

activity Activity

The activity.

action Func<T>

The function.

Returns

Task<T>

A task whose result is the function's, or that fails with its exception.

Type Parameters

T

The 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

message string

The message.