DpvrDeviceManager¶
Power Management:¶
AcquireWakeLock¶
public static void AcquireWakeLock(int wakeLockLevel = FORGROUND_WAKE_LOCK)
acquire system wakelock,block device from sleeping.
Parameter | Description |
---|---|
wakeLockLevel | BACKGROUND_WAKE_LOCK, CPU is running,backgound thread is running, but foreground Android app will be paused by system. UnityMain event function such as Update() will be paused. FORGROUND_WAKE_LOCK,keep foreground app running, and the power key is also blocked. Default value:FORGROUND_WAKE_LOCK |
ReleaseWakeLock¶
public static void ReleaseWakeLock(int wakeLockLevel = FORGROUND_WAKE_LOCK)
Release system wakelock to allow system go to sleep. Make sure all the acquired level are released to let system go to sleep.
Parameter | Description |
---|---|
wakeLockLevel | BACKGROUND_WAKE_LOCK, release background wake lock. FORGROUND_WAKE_LOCK,release foreground wake lock,allow power key event, when next time system go to sleep event happen, such as power key or p-sensor, forground app will pause. Default value:FORGROUND_WAKE_LOCK |
App Management¶
GoToApp¶
public static void GoToApp(string packageName)
Open specified app.
Parameter | Description |
---|---|
packageName | App package name. |
CloseApp¶
public static void CloseApp(string packageName)
Kill the process of specified app.
Parameter | Description |
---|---|
packageName | App package name. |
StartAppWithExtra¶
public static bool StartAppWithExtra(string packageName, string className, string[] key, string[] value)
start activity with extras, the keys should correspond with values.
Parameter | Description |
---|---|
packageName | package name |
className | full class name |
key | array of all keys |
value | array of all values |
StartAppWithAction¶
public static bool StartAppWithAction(string action)
start activity by action
Parameter | Description |
---|---|
action | full string of intent action |
InstallApk¶
public static void InstallApk(string apkPath,
OnPackageInstallSuccessHandler successCallback = null,
OnPackageInstallErrorHandler errorHandler = null)
Install apk silently.
Parameter | Description |
---|---|
apkPath | Apk file path. |
successCallback | Callback when install successfully. User can use this method to get install successful event. The callback is called in the thread of user called InstallApk if calling thread has a Android Looper, otherwise called in main thread. |
errorHandler | Callback when install failed. |
Prototype for OnPackageInstallSuccessHandler:
public delegate void OnPackageInstallSuccessHandler(string apkPath, string packageName);
Prototype for OnPackageInstallErrorHandler:
public delegate void OnPackageInstallErrorHandler(string apkPath, int errorCode);
UninstallApk¶
public static void UninstallApk(string packageName,
OnPackageUninstallSuccessHandler successCallback = null,
OnPackageUninstallErrorHandler errorCallback = null)
Uninstall specified app.
Parameter | Description |
---|---|
packageName | App package name. |
successCallback | Callback when uninstall successfully. |
errorCallback | Callback when uninstall failed. |
Prototype for OnPackageUninstallSuccessHandler:
public delegate void OnPackageUninstallSuccessHandler(string packageName);
Prototype for OnPackageUninstallErrorHandler:
public delegate void OnPackageUninstallErrorHandler(string packageName, int errorCode);
GetInstalledAppList¶
public static string[] GetInstalledAppList(bool onlyLauncher = true)
Get installed app package name list, include system apps and un-system apps.
Parameter | Description |
---|---|
onlyLauncher | only apps have launcher |
GetAppNameByPackageName¶
public static string GetAppNameByPkgname(string pkgname)
Get app name by package name.
Parameter | Description |
---|---|
packageName | App package name. |
GetAppIconByPackageName¶
public static byte[] GetAppIconByPkgname(string pkgname)
Get app icon byte array by package name.
Parameter | Description |
---|---|
packageName | App package name. |
ShowControllerBindPage¶
public static void ShowControllerBindPage()
intent to bind controller page in launcher
Home App Management¶
SetHomeKeyApp¶
public static void SetHomeKeyApp(string packageName, string activityName)
Set target app/activity for Home key event(long press back).
Parameter | Description |
---|---|
packageName | App package name. |
activityName | Target activity name. |
RestoreHomeKeyApp¶
public static void RestoreHomeKeyApp()
Restore Home key event to go back to DPVR Launcher.
SetNewLauncher( only on P1Pro device )¶
public static void SetNewLauncher(string packageName)
Allow to set new boot auto-start launcher, including the apps without launcher category. Notice that if you set the app without launcher category, you need to use SetHomeKeyApp() to keep HOME key working normally(long pressing back key go to your setting app). If not, it will go back to original launcher. If your setting app has launcher category, HOME key launcher will be your setting one and SetHomeKeyApp()will be unnecessary.
Parameter | Description |
---|---|
packageName | App package name. |
RestoreDpnLauncher(only on P1Pro device)¶
public static void RestoreDpnLauncher()
Restore to deepoon default DpnLauncher, including boot auto-start app.
System Key Management¶
BlockHomeKey¶
public static void BlockHomeKey()
Block home key event, for M2 and P1, long press back will send home key event.
BlockVolumeKey¶
public static void BlockVolumeKey()
Block volume key press, but user can change volume by code.
ClearOrSetAllBlockState¶
public static void ClearOrSetAllBlockState(bool clearOrSet)
clear/set all system key to block state
Parameter | Description |
---|---|
clearOrSet | true->clear all system key block false->set all system key to block state |
Controller Key Management¶
BlockControllerHomeKey¶
public static void BlockControllerHomeKey()
block controller home key event.
AllowControllerHomeKey¶
public static void AllowControllerHomeKey()
Allow controller home key event ( default ).
BlockControllerBackKey¶
public static void BlockControllerBackKey()
block controller back key event.
AllowControllerBackKey¶
public static void AllowControllerBackKey()
Allow controller back key event ( default ).
BlockControllerDPADKey¶
public static void BlockControllerDPADKey()
block controller dpad key (up down left right center) event.
AllowControllerDPADKey¶
public static void AllowControllerDPADKey()
Allow controller dpad key event ( default ).
BlockControllerTriggerKey¶
public static void BlockControllerTriggerKey()
block controller trigger key event.
AllowControllerTriggerKey¶
public static void AllowControllerTriggerKey()
Allow controller trigger key event ( default ).
ClearOrSetAllControllerState¶
public static void ClearOrSetAllControllerState(bool clear)
reset all controller key state, when clear set to be true, means to clear all controller key block state.
Parameter | Description |
---|---|
clear | true->clear all controller key block state false->set all controller key to block state |
EnableDoubleClickBackKey¶
public static void EnableDoubleClickBackKey(int behavior, string pkgname, string cls="", int delay=3000)
enable double click back key function, when double click, intent to pkgname/cls.
Parameter | Description |
---|---|
behavior | remanin state |
pkgname | package intent to when double click back key |
cls | full class name |
delay | time delay to trigger intent |
DisableDoubleClickBackKey¶
public static void DisableDoubleClickBackKey(int behavior)
disable double click back key function
Parameter | Description |
---|---|
behavior | remain state |
EnableDoubleClickHomeKey¶
public static void EnableDoubleClickHomeKey(int behavior, string pkgname, string cls="", int delay=3000)
enable double click home key function, when double click home key, intent to pkgname/cls
Parameter | Description |
---|---|
behavior | remanin state |
pkgname | package intent to when double click back key |
cls | full class name |
delay | time delay to trigger intent |
DisableDoubleClickHomeKey¶
public static void DisableDoubleClickHomeKey(int behavior)
disable double click home key function
Parameter | Description |
---|---|
behavior | remain state |
RegisterDoubleClickHomeKeyCallback¶
public static void RegisterDoubleClickHomeKeyCallback(OnDoubleClickHomeKeyCallback callback)
register a callback for double click home key event
Parameter | Description |
---|---|
callback | callback when double click home key event triggered |
System Sleep Management¶
BlockSystemSleep¶
public static void BlockSystemSleep()
Block foreground app pause, same as AcquireWakeLock( FORGROUND_WAKE_LOCK ).
AllowSystemSleep¶
public static void AllowSystemSleep()
Allow foreground app pause, same as ReleaseWakeLock( FORGROUND_WAKE_LOCK ).
Battery Management¶
RegisterBatteryCallback¶
public static void RegisterBatteryCallback(OnBatteryLevelHandler batteryHandler)
Register battery callback.
Parameter | Description |
---|---|
batteryHandler | callback when battery level change |
Prototype for OnBatteryLevelHandler
public delegate void OnBatteryLevelHandler(int level, int batteryState)
Wifi Management¶
GetWifiStrength¶
public static int GetWifiStrength()
get wifi strength, the same with name rssi value in android
RegisterWifiReceiver¶
public void RegisterWifiReceiver(OnWifiStateChangeHandler wifiHandler,
OnNetworkStateChangeHandler networkStateHandler,
OnRssiChangeHandler rssiChangeHandler)
register wifi callback, get wifi state/info dynamic
Parameter | Description |
---|---|
wifiHandler | callback when wifi state change |
networkStateHandler | callback when network state change |
rssiChangeHandler | callback when rssi change |
UnRegisterConnectionChangeReceiver¶
public void UnRegisterConnectionChangeReceiver()
unregister wifi callback.
Warning :this method will remove all listeners registered by “RegisterWifiReceiver”
SetWifiEnabled¶
public bool SetWifiEnabled(bool enable)
enable/disable wifi, enable wifi do not mean wifi is connected.
Parameter | Description |
---|---|
enable | true to enable wifi, false to disable wifi |
GetWifiState¶
public int GetWifiState()
return current wifi state, exp: 0 for netStateConnecting, 1 for netStateConnected, etc.
GetConfiguredWifi¶
public string GetConfiguredWifi()
Return a list of all the networks configured for the current foreground user. contains params: networkId/SSID/BSSID/priority/allowedProtocols/allowedKeyManagement /allowedAuthAlgorithms/allowedPairwiseCiphers/allowedGroupCiphers
GetConnectedWifiSSID¶
public string GetConnectedWifiSSID()
Return ssid about the current Wifi connection, if any is active
StartScanWifi¶
public bool StartScanWifi()
Request a scan for access points. Returns immediately. The availability of the results is made known later by means of an asynchronous event sent on completion of the scan.
ConnectWifi¶
public bool ConnectWifi(string ssid, string password, int wificipherType)
connect Wifi by wifi name(ssid) and password
Parameter | Description |
---|---|
ssid | wifi name |
password | wifi password |
wificipherType | wifi cipher type, such as wep |
ConnectStaticIpWifi¶
public bool ConnectStaticIpWifi(string ssid, string password, int wificipherType,
int prefixLength, string ipAddress, string gateway, string dns)
connect static ip wifi
Parameter | Description |
---|---|
ssid | wifi name |
password | wifi password |
wificipherType | wifi cipher type, such as wep |
prefixLength | ip prefix lenght |
ipAddress | ip address |
gateway | dns1 gateway |
dns | dns |
RemoveWifiBySsid¶
public void RemoveWifiBySsid(string ssid)
remove wifi by ssid
Parameter | Description |
---|---|
ssid | wifi name |
Bluetooth Management¶
OpenAndroidBluetoothSetting¶
public static void OpenAndroidBluetoothSetting()
Open Android Bluetooth settings.
RegisterBluetoothCallback¶
public static void RegisterBluetoothCallback(OnBtLocalStateCallback btAdapter,
OnBtLocalScanCallback btDevice,
OnBtDeviceBondCallback btDeviceBond,
OnBtDeviceConnectionStateCallback btConDeviceState)
Register bluetooth callback.
Parameter | Description |
---|---|
btAdapter | callback when local bluetooth on/off state change |
btDevice | callback when bluetooth device scan finished |
btDeviceBond | device bonding state,ref:DeviceBondState |
btConDeviceState | callback when connected device state change |
Prototype for OnBtLocalStateCallback
public delegate void OnBtLocalStateCallback(int state)
Parameter | Description |
---|---|
state | local bluetooth state |
Prototype for OnBtLocalScanCallback
public delegate void OnBtLocalScanCallback(bool scanState, string deviceInfo)
Parameter | Description |
---|---|
scanState | true->is scanning state |
deviceInfo | bluetooth device info, exp:{"DeviceClass":1024,"address":"30:21:30:45:17:7B","name":"ifkoo Q8","rssi":-39} |
Prototype for OnBtDeviceBondCallback
public delegate void OnBtDeviceBondCallback(string deviceName, int bondState)
Parameter | Description |
---|---|
deviceName | device name |
bondState | device bond state |
Prototype for OnBtDeviceConnectionStateCallback
public delegate void OnBtDeviceConnectionStateCallback(string name, int preState, int currentState);
Parameter | Description |
---|---|
name | device name |
preState | device previous state |
currentState | device current state |
UnregisterBluetoothCallback¶
public static void UnregisterBluetoothCallback()
unregister bluetooth callback.
Warning⚠:this method will remove all bluetooth listeners registered
GetConnectedDeviceNameList¶
public static string[] GetConnectedDeviceNameList()
get connected device name list
SetBluetoothEnabled¶
public static bool SetBluetoothEnabled(bool enable)
enable/disable local bluetooth state
Parameter | Description |
---|---|
enable | true->enable bluetooth false->disable bluetooth |
SetLocalName¶
public static bool SetLocalName(string localName)
set local bluetooth device name
Parameter | Description |
---|---|
localName | local bluetooth name user want |
IsDiscovering¶
public static bool IsDiscovering()
Return true if the local Bluetooth adapter is currently in the device discovery process
GetBluetoothBondedDevices¶
public static string GetBluetoothBondedDevices()
Return the json string of objects that are bonded (paired) to the local adapter.
ConnectBluetoothDevice¶
public static bool ConnectBluetoothDevice(string address)
Connect bluetooth device by address
Parameter | Description |
---|---|
address | device address |
warning:only support DeviceClass is AUDIO_VIDEO or PERIPHERAL
RemoveBluetoothDevice¶
public static bool RemoveBluetoothDevice(string address)
remove bluetooth device
Parameter | Description |
---|---|
address | device address |
System Info Query¶
GetProductModel¶
public static string GetProductModel()
Get Android Device model, M2 return VM2, P1 return VP1, P1Pro return P1Pro.
Fota Update Management¶
RegisterFotaUpdate¶
public static bool RegisterFotaUpdate(OnFotaUpdateHandler handler)
Register os update.
Parameter | Description |
---|---|
OnFotaUpdateHandler | callback when there is new os version ready to update |
Prototype for OnFotaUpdateHandler
public delegate void OnFotaUpdateHandler(bool newVersion)
Language Management¶
SetLanguage¶
public static void SetLanguage(string language, string country = "")
Set system language.
Parameter | Description |
---|---|
language | the language user want the system displayed |
country | the country the launguage as a mother language |
GetCurrentSystemLanguage¶
public static string GetCurrentSystemLanguage()
Get current system language.
GetSupportLanguageList¶
public static string[] GetSupportLanguageList()
Get support language list, exp: zh for china
GetCountriesByLanguage¶
public static string[] GetCountriesByLanguage(string language = "zh")
Get countries by language, exp: {“US”,”UK” …} for “en”
MediaPlayerManager¶
PlayVideo¶
public static void PlayVideo(string videoPath, VideoPlayMode playMode, string pkgname="")
start play video
Parameter | Description |
---|---|
videoPath | video full path |
playMode | video play mode, exp: exp:VideoPlayMode.Mode_2D for 2D video |
pkgname | target package after exit player |
PauseVideo¶
public static void PauseVideo(string pauseOrNot)
pause video
Parameter | Description |
---|---|
pauseOrNot | "pause" -> to pause video "play" -> resume play |
SwitchPlayMode¶
public static void SwitchPlayMode(VideoPlayMode videoPlayMode)
switch video play mode
Parameter | Description |
---|---|
videoPlayMode | video play mode, exp:VideoPlayMode.Mode_2D to play video in 2D mode |
SeekPlayer¶
public static void SeekPlayer(string seekTime_s)
seek video player
Parameter | Description |
---|---|
seekTime_s | seek player for seconds |
SetVolume¶
public static void SetVolume(int volumeValue)
set video volume, range[0-100]
Parameter | Description |
---|---|
volumeValue | set volume, range [0,100] |
BlockTouch¶
public static void BlockTouch(int block)
block touch panel
Parameter | Description |
---|---|
block | 1 -> to block touch panel 0 -> unblock touch panel |
PopNotification¶
public static void PopNotification(string msg)
popup notification
Parameter | Description |
---|---|
msg | message to pop |
SetCurrentPackageName¶
public static void SetCurrentPackageName(string pkgname)
set package to load after exit video player
Parameter | Description |
---|---|
pkgname | package to load |
RegisterMediaPlayerStatusCallback¶
public static void RegisterMediaPlayerStatusCallback(MediaPlayerStatusHandler playerStatusHandler)
register a callback to receive media player status
Parameter | Description |
---|---|
playerStatusHandler | callback when player status change |
Prototype for MediaPlayerStatusHandler
public delegate void MediaPlayerStatusHandler(string filename, string state)
Parameter | Description |
---|---|
filename | file name of current playing |
state | string to describe current player status, exp:stop/resume |
DpvrSettingsManager¶
OpenApplicationDetail¶
public static void OpenApplicationDetail(string pkgname)
open application detail page
Parameter | Description |
---|---|
pkgname | target package name |
OpenDisplaySettings¶
public static void OpenDisplaySettings()
open display setting page, display setting include brightness、night light、adaptive brightness、 wallpaper、advanced settings, etc.
Usage¶
Import DpvrDeviceManager.unitypackage in Unity3D.
Call the api when needed, for example, if you want to ShutDown,call DpvrDeviceManager.PowerManager.AndroidShutDown(), and remember to add using space.
Android api requirement : minSdkVersion 19, targetSdkVersion 19, if your project not consistent with this version, you can follow steps below try to fix it, first, pull the AndroidManifest.xml out of the libDPVRDeviceManager.aar, fix minsdkVersion and targetsdkVersion to your own version, if your minsdkversion is less then 24, recommend to remove string “android:directBootAware=”true”” in AndroidManifest.xml, after that, push it to zip file libDPVRDeviceManager.aar to replace original file, then try to build again.