System Utilities

Android Id

A 64-bit number (as a hex string) that is randomly generated when the user first sets up the device and should remain constant for the lifetime of the user's device.

The code snippet bellow shows how you can retrieve the Android Id:

AndroidNativeUtility.OnAndroidIdLoaded += OnAndroidIdLoaded;
AndroidNativeUtility.Instance.LoadAndroidId();

void OnAndroidIdLoaded (string id) {
	AndroidNativeUtility.OnAndroidIdLoaded -= OnAndroidIdLoaded;
	AndroidMessage.Create("Android Id Loaded", id);
}

Internal Storage Path

The code snippet bellow shows how you can retrieve the Internal Storage Path:

AndroidNativeUtility.InternalStoragePathLoaded += InternalStoragePathLoaded;
AndroidNativeUtility.Instance.GetInternalStoragePath();

void InternalStoragePathLoaded (string path) {
	AN_PoupsProxy.showMessage("Internal Storage Path:", path);
	AndroidNativeUtility.InternalStoragePathLoaded -= InternalStoragePathLoaded;
}

External Storage Path

The code snippet bellow shows how you can retrieve the External Storage Path:

AndroidNativeUtility.ExternalStoragePathLoaded += ExternalStoragePathLoaded;
AndroidNativeUtility.Instance.GetExternalStoragePath();

void ExternalStoragePathLoaded (string path) {
	AN_PoupsProxy.showMessage("External Storage Path:", path);
	AndroidNativeUtility.ExternalStoragePathLoaded -= ExternalStoragePathLoaded;
}

Advertising ID Retrieval

Since Advertizing ID is the part of Google Play Service id, you can found more information about it and code sample how to retrieve it in the Google Play Utilities article.

Locale

The default locale is appropriate for tasks that involve presenting data to the user. In this case, you want to use the user's date/time formats, number formats, rules for conversion to lowercase, and so on. In this case, it's safe to use the convenience methods.

The default locale is not appropriate for machine-readable output. The best choice there is usually Locale.US â this locale is guaranteed to be available on all devices, and the fact that it has no surprising special cases and is frequently used (especially for computer-computer communication) means that it tends to be the most efficient choice too.

Following code snippet shows how to retrieve basic Locale info:

AndroidNativeUtility.LocaleInfoLoaded += LocaleInfoLoaded;
AndroidNativeUtility.Instance.LoadLocaleInfo();

void LocaleInfoLoaded (AN_Locale locale){
	AN_PoupsProxy.showMessage("Locale Indo:", locale.CountryCode + "/" 
		                          + locale.DisplayCountry + "  :   "
		                          + locale.LanguageCode + "/" 
		                          + locale.DisplayLanguage);
	AndroidNativeUtility.LocaleInfoLoaded -= LocaleInfoLoaded;
}

The locale info is represented as the AN_Locale object.

public class AN_Locale {

	//Returns the country code for this locale, or "" if this locale doesn't correspond to a specific country.
	public string CountryCode {get;}

	//Returns the name of this locale's country, localized to locale. Returns the empty string if this locale does not correspond to a specific country.
	public string DisplayCountry {get;}

	//Returns the language code for this Locale or the empty string if no language was set.
	public string LanguageCode{get;}

	//Returns the name of this locale's language, localized to locale. If the language name is unknown, the language code is returned.
	public string DisplayLanguage{get;}

}

Device applications list 

Following is the code to get the list of activities/applications installed on Android Device:

AndroidNativeUtility.Instance.LoadPackagesList();
AndroidNativeUtility.ActionDevicePackagesListLoaded += HandleActionDevicePackagesListLoaded;

void HandleActionDevicePackagesListLoaded (string[] pkgAppsList) {
	Debug.Log("device apps loaded: ");
	foreach(string packageName in pkgAppsList) {
		Debug.Log(packageName);
	}
}

Network Info

Before retriving the network information you should enable Network Info API in the plugin settings as showed on the screenshot bellow:

Enabling this API will trigger new permission in your manifest:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

The code snippet bellow shows how you can retrive and print the current network info.

public void LoadNetworkInfo() {
	AndroidNativeUtility.ActionNetworkInfoLoaded += HandleActionNetworkInfoLoaded;
	AndroidNativeUtility.Instance.LoadNetworkInfo();
}

void HandleActionNetworkInfoLoaded (AN_NetworkInfo info) {
	string infoString = "";
	infoString += "IpAddress: " + info.IpAddress + " \n";
	infoString += "SubnetMask: " + info.SubnetMask + " \n";
	infoString += "MacAddress: " + info.MacAddress + " \n";
	infoString += "SSID: " + info.SSID + " \n";
	infoString += "BSSID: " + info.BSSID + " \n";

	infoString += "LinkSpeed: " + info.LinkSpeed + " \n";
	infoString += "NetworkId: " + info.NetworkId + " \n";

	Debug.Log(infoString);

	AndroidNativeUtility.ActionNetworkInfoLoaded -= HandleActionNetworkInfoLoaded;
}

If you device currently conneted to the WIFI network the output should be similar to:

IpAddress: 192.168.0.151 
SubnetMask: 255.255.255.0 
MacAddress: 54:a0:50:97:00:30 
SSID: "WORK" 
BSSID: bc:ee:7b:8f:6c:c0 
LinkSpeed: 65 
NetworkId: 3 

The netwrok info represtned as AN_NetworkInfo object:

public class AN_NetworkInfo  {

	//Device local Ip Address
	public string IpAddress {get;}

	//Device Mac Address
	public string MacAddress {get;}

	//Network Sub Mask
	public string SubnetMask {get;}
	
	//Returns the service set identifier (SSID) of the current 802.11 network. If the SSID can be decoded as UTF-8, it will be returned surrounded by double quotation marks. Otherwise, it is returned as a string of hex digits. The SSID may be <unknown ssid> if there is no network currently connected.
	public string SSID {get;}

	//Return the basic service set identifier (BSSID) of the current access point. The BSSID may be null if there is no network currently connected.
	public string BSSID {get;}

	//Link speed in Mbps
	public int LinkSpeed {get;}

	//Each configured network has a unique small integer ID, used to identify the network when performing operations on the supplicant. This method returns the ID for the currently connected network.
	public int NetworkId {get;}
}

Important:

To provide users with greater data protection, starting in Android 6.0, Android removes programmatic access to the device’s local hardware identifier for apps using the Wi-Fi and Bluetooth APIs. The WifiInfo.getMacAddress() and the BluetoothAdapter.getAddress() methods now return a constant value of 02:00:00:00:00:00.

Please, see official Android 6.0 Changelog.

 

Current Device Accounts

This API allows you to retrieve list of user accounts available on current device. Before you can use this API, make sure that Google Play Advanced Sign In is enabled (this API is provided by google play lib).

Note: This API works without signing to the Google Play Service. It basically designed for users who want to create their own signing interface with own account picker. But can be used for any other purpose as well.

Enabling this API will trigger new permission in your manifest:

<uses-permission android:name="android.permission.GET_ACCOUNTS" />

Following code snippet shows how to retrieve accounts list:

GooglePlayManager.ActionAvailableDeviceAccountsLoaded += ActionAvailableDeviceAccountsLoaded;
GooglePlayManager.Instance.RetrieveDeviceGoogleAccounts();


private void ActionAvailableDeviceAccountsLoaded(List<string> accounts) {
    GooglePlayManager.ActionAvailableDeviceAccountsLoaded -= ActionAvailableDeviceAccountsLoaded;

	string msg = "Device contains following google accounts:" + "\n";
	foreach(string acc in GooglePlayManager.Instance.deviceGoogleAccountList) {
		msg += acc + "\n";
	} 

	AndroidDialog dialog = AndroidDialog.Create("Accounts Loaded", msg, "Sign With Fitst one", "Do Nothing");
	dialog.ActionComplete += SighDialogComplete;
}

Settings Page API

You can start settings activity with the OpenSettingsPage method, you can also specify settings page you would like to show. User will return to your app by pressing back button.

If you want to open current application settings page:

AndroidNativeUtility.OpenSettingsPage(AN_SettingsActivityAction.ACTION_APPLICATION_DETAILS_SETTINGS);

Full list of available action can be found under AN_SettingsActivityAction class.

public class AN_SettingsActivityAction  {
	
    //Activity Action: Show system settings.
	public const string ACTION_SETTINGS;
	
    //Activity Action: Show settings to allow configuration of APNs.
	public const string ACTION_APN_SETTINGS;

    //Activity Action: Show settings to allow configuration of current location
	public const string ACTION_LOCATION_SOURCE_SETTINGS;
	
    //Activity Action: Show settings to allow configuration of wireless controls
    //such as Wi-Fi, Bluetooth and Mobile networks..
	public const string ACTION_WIRELESS_SETTINGS;
	
    //Activity Action: Show settings to allow entering/exiting airplane mode.
	public const string ACTION_AIRPLANE_MODE_SETTINGS;
	
    //Activity Action: Show settings for accessibility modules.
	public const string ACTION_ACCESSIBILITY_SETTINGS;
	
    //Activity Action: Show settings to control access to usage information.
	public const string ACTION_USAGE_ACCESS_SETTINGS;
	
    //Activity Action: Show settings to allow configuration of security and
    //location privacy.
	public const string ACTION_SECURITY_SETTINGS;
	
    //Activity Action: Show trusted credentials settings, opening to the user tab,
    //to allow management of installed credentials.
	public const string ACTION_TRUSTED_CREDENTIALS_USER;
	
    //Activity Action: Show dialog explaining that an installed CA cert may enable
    //monitoring of encrypted network traffic.
	public const string ACTION_MONITORING_CERT_INFO;

    //Activity Action: Show settings to allow configuration of privacy options.
	public const string ACTION_PRIVACY_SETTINGS;

    //Activity Action: Show settings to allow configuration of Wi-Fi.
	public const string ACTION_WIFI_SETTINGS;

    //Activity Action: Show settings to allow configuration of a static IP
    //address for Wi-Fi.
	public const string ACTION_WIFI_IP_SETTINGS;
	
    //Activity Action: Show settings to allow configuration of Bluetooth.
	public const string ACTION_BLUETOOTH_SETTINGS;
	
    //Activity Action: Show settings to allow configuration of Wifi Displays.
	public const string ACTION_WIFI_DISPLAY_SETTINGS;

    //Activity Action: Show settings to allow configuration of
    //cast endpoints.
	public const string ACTION_CAST_SETTINGS;
	
    //Activity Action: Show settings to allow configuration of date and time.
	public const string ACTION_DATE_SETTINGS;

    // Activity Action: Show settings to allow configuration of sound and volume.
	public const string ACTION_SOUND_SETTINGS;

    //Activity Action: Show settings to allow configuration of display.
	public const string ACTION_DISPLAY_SETTINGS;
	
    //Activity Action: Show settings to allow configuration of locale.
	public const string ACTION_LOCALE_SETTINGS;

    //Activity Action: Show settings to configure input methods, in particular
    //allowing the user to enable input methods.
	public const string ACTION_VOICE_INPUT_SETTINGS;

    //Activity Action: Show settings to configure input methods, in particular
    //allowing the user to enable input methods.
	public const string ACTION_INPUT_METHOD_SETTINGS;

    //Activity Action: Show settings to enable/disable input method subtypes.
	public const string ACTION_INPUT_METHOD_SUBTYPE_SETTINGS;
	
    //Activity Action: Show a dialog to select input method.
	public const string ACTION_SHOW_INPUT_METHOD_PICKER;

    //Activity Action: Show settings to manage the user input dictionary.
	public const string ACTION_USER_DICTIONARY_SETTINGS;

    //Activity Action: Adds a word to the user dictionary.
	public const string ACTION_USER_DICTIONARY_INSERT;

    //Activity Action: Show settings to allow configuration of application-related settings.
	public const string ACTION_APPLICATION_SETTINGS;

    //Activity Action: Show settings to allow configuration of application
	public const string ACTION_APPLICATION_DEVELOPMENT_SETTINGS;

    //Activity Action: Show settings to allow configuration of quick launch shortcuts.
	public const string ACTION_QUICK_LAUNCH_SETTINGS;

    //Activity Action: Show settings to manage installed applications.
	public const string ACTION_MANAGE_APPLICATIONS_SETTINGS;
	
    //Activity Action: Show settings to manage all applications.
	public const string ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS;

    //Activity Action: Show screen of details about a particular application.
	public const string ACTION_APPLICATION_DETAILS_SETTINGS;

    //Activity Action: Show the "app ops" settings screen.
	public const string ACTION_APP_OPS_SETTINGS;
	
    //Activity Action: Show settings for system update functionality.
	public const string ACTION_SYSTEM_UPDATE_SETTINGS;

    //Activity Action: Show settings to allow configuration of sync settings.
	public const string ACTION_SYNC_SETTINGS;

    //Activity Action: Show add account screen for creating a new account.
	public const string ACTION_ADD_ACCOUNT;

    //Activity Action: Show settings for selecting the network operator.
	public const string ACTION_NETWORK_OPERATOR_SETTINGS;

    //Activity Action: Show settings for selection of 2G/3G.
	public const string ACTION_DATA_ROAMING_SETTINGS;

    //Activity Action: Show settings for internal storage.
	public const string ACTION_INTERNAL_STORAGE_SETTINGS;
    
    //Activity Action: Show settings for memory card storage.
	public const string ACTION_MEMORY_CARD_SETTINGS;

    //Activity Action: Show settings for global search.
	public const string ACTION_SEARCH_SETTINGS;

    //Activity Action: Show general device information settings (serial
    //number, software version, phone number, etc.).
	public const string ACTION_DEVICE_INFO_SETTINGS;

    //Activity Action: Show NFC settings.
	public const string ACTION_NFC_SETTINGS;

    //Activity Action: Show NFC Sharing settings.
	public const string ACTION_NFCSHARING_SETTINGS;

    //Activity Action: Show NFC Tap & Pay settings
	public const string ACTION_NFC_PAYMENT_SETTINGS;

    //Activity Action: Show Daydream settings.
	public const string ACTION_DREAM_SETTINGS;
	
    //Activity Action: Show Notification listener settings.
	public const string ACTION_NOTIFICATION_LISTENER_SETTINGS;

    //Activity Action: Show settings for video captioning.
	public const string ACTION_CAPTIONING_SETTINGS;

    //Activity Action: Show the top level print settings.
	public const string ACTION_PRINT_SETTINGS;

    //Activity Action: Show the regulatory information screen for the device.
	public const string ACTION_SHOW_REGULATORY_INFO;

    //Activity Action: Show Device Name Settings.
	public const string DEVICE_NAME_SETTINGS;

    //Activity Action: Show pairing settings.
	public const string ACTION_PAIRING_SETTINGS;

    //Activity Action: Show battery saver settings.
	public const string ACTION_BATTERY_SAVER_SETTINGS;

    //Activity Action: Show Home selection settings. 
	public const string ACTION_HOME_SETTINGS;

    //Activity Action: Show notification settings.
	public	const string ACTION_NOTIFICATION_SETTINGS;

    //Activity Action: Show notification settings for a single app.
	public const string ACTION_APP_NOTIFICATION_SETTINGS;

    //Activity Action: Show notification redaction settings.
	public const string ACTION_APP_NOTIFICATION_REDACTION;
}