Class Overview
This class provides APIs to control the settings related to location
services.
Summary
[Expand]
Inherited Methods |
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
|
Public Methods
public
List<String>
getAllLocationProviders
()
Deprecated
in API level 27
NOTE: This API is not available since Android 10.
API to get all available location services on the device.
Returns
- A list containing the names of the location services if
successful, else
false
.
Usage
An administrator can use this API to get the different location
services available (e.g., gps, network, passive) on the device.
|
EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
LocationPolicy locationPolicy = edm.getLocationPolicy();
try {
List list = locationPolicy.getAllLocationProviders();
if (list != null) {
// getting all available location provider has succeeded
} else {
// getting all available location provider has failed
}
} catch (SecurityException e) {
Log.w(TAG, "SecurityException: " + e);
}
// Sample Output
// gps
// network
// passive
|
For Container:
// When you create container successfully, containerID will be
// returned via intent.
// Use this containerID in below API.
EnterpriseKnoxManager ekm = EnterpriseKnoxManager.getInstance(context);
KnoxContainerManager kcm = ekm.getKnoxContainerManager(containerID);
LocationPolicy locationPolicy = kcm.getLocationPolicy();
try {
List list = locationPolicy.getAllLocationProviders();
if (list != null) {
// getting all available location provider has succeeded
} else {
// getting all available location provider has failed
}
} catch (SecurityException e) {
Log.w(TAG, "SecurityException: " + e);
}
// Sample Output
// gps
// network
// passive
|
Permission
The use of this API requires the caller to have the
"com.samsung.android.knox.permission.KNOX_LOCATION" permission which has
a protection level of signature
|
public
boolean
getLocationProviderState
(String provider)
Deprecated
in API level 27
NOTE: This API is not available since Android 10.
API to get the enabled or disabled state of a given location provider.
Parameters
provider
| The case sensitive location provider name. Sample values are gps,
network, passive. |
Returns
true
if the location provider is enabled,
false
if the location provider is disabled.
Usage
An administrator can use this API to get the enabled or disabled
state of a location provider. All available location providers on the
device can be obtained by using getAllLocationProviders() .
|
EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
LocationPolicy locationPolicy = edm.getLocationPolicy();
String gpsProvider = "gps";//case sensitive
try {
boolean result = locationPolicy.getLocationProviderState(gpsProvider);
if(result == true){
Log.d(TAG,"GPS location provider is not blocked, and user is
allowed to modify.");
}else{
Log.d(TAG,"GPS location provider is disabled by administrator. User not
allowed to modify.");
}
}catch(SecurityException e) {
Log.w(TAG,"SecurityException: "+e);
}
|
For Container:
// When you create container successfully, containerID will be returned via intent.
// Use this containerID in below API.
EnterpriseKnoxManager ekm = EnterpriseKnoxManager.getInstance(context);
KnoxContainerManager kcm = ekm.getKnoxContainerManager(containerID);
LocationPolicy locationPolicy = kcm.getLocationPolicy();
String gpsProvider = "gps";//case sensitive
try {
boolean result = locationPolicy.getLocationProviderState(gpsProvider);
if(result == true){
Log.d(TAG,"GPS location provider is not blocked, and user is
allowed to modify.");
}else{
Log.d(TAG,"GPS location provider is disabled by administrator. User not
allowed to modify.");
}
}catch(SecurityException e) {
Log.w(TAG,"SecurityException: "+e);
}
|
Permission
The use of this API requires the caller to have the
"com.samsung.android.knox.permission.KNOX_LOCATION" permission which has
a protection level of signature
|
public
boolean
isGPSOn
()
Deprecated
in API level 27
API to check whether GPS is ON or OFF on the device.
Returns
true
if GPS is ON, else false
.
Permission
The use of this API requires the caller to have the
"com.samsung.android.knox.permission.KNOX_LOCATION" permission which has
a protection level of signature
Note: Since MDM 5.4, caller does not need to have
"com.samsung.android.knox.permission.KNOX_LOCATION" permission to call
this API. |
public
boolean
isGPSStateChangeAllowed
()
Deprecated
in API level 35
API to check whether the user is allowed to change the state of GPS on
the device.
Returns
true
if allowed, else false
.
Usage
An administrator can use this API check whether the user is
allowed to change the GPS state. If not allowed, the user cannot change
GPS UI settings.
|
Permission
The use of this API requires the caller to have the
"com.samsung.android.knox.permission.KNOX_LOCATION" permission which has
a protection level of signature.
Note: Since MDM 5.4, caller does not need to have
"com.samsung.android.knox.permission.KNOX_LOCATION" permission to call
this API. |
public
boolean
setGPSStateChangeAllowed
(boolean allow)
Deprecated
in API level 35
API to allow or disallow the user changing the state of GPS on the
device.
Parameters
allow
| true to allow user to change state of GPS,
false to disallow it. |
Returns
true
if successful, else false
.
Usage
An administrator can use this API to allow or disallow the user
changing the state of GPS. If not allowed, the user cannot change GPS UI
settings.
Note:
There is no difference between existing "setLocationProviderState("gps",
true)" and "setGPSStateChangeAllowed(true)".
There is one difference between existing "setLocationProviderState("gps",
false)" and "setGPSStateChangeAllowed(false)".
When GPS in ON in device.
a) calling "setLocationProviderState("gps", false)" stops GPS and
disables it from user change.
b) calling "setGPSStateChangeAllowed(false)" disables GPS to user change
but does not stop GPS.
|
EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
LocationPolicy locationPolicy = edm.getLocationPolicy();
try {
boolean result = locationPolicy.setGPSStateChangeAllowed(false);
if (result == true) {
Log.d(TAG, "User is not allowed to change state of GPS");
}
} catch (SecurityException e) {
Log.w(TAG, "SecurityException: " + e);
}
|
For Container:
NOTE: Since MDM 5.3, only Android users (Owner/Guest user)
administrator can call this API. For container, API will return false.
// When you create container successfully, containerID will be
// returned via intent.
// Use this containerID in below API.
EnterpriseKnoxManager ekm = EnterpriseKnoxManager.getInstance(context);
KnoxContainerManager kcm = ekm.getKnoxContainerManager(containerID);
LocationPolicy locationPolicy = kcm.getLocationPolicy();
try {
boolean result = locationPolicy.setGPSStateChangeAllowed(false);
if (result == true) {
Log.d(TAG, "User is not allowed to change state of GPS");
}
} catch (SecurityException e) {
Log.w(TAG, "SecurityException: " + e);
}
|
Permission
The use of this API requires the caller to have the
"com.samsung.android.knox.permission.KNOX_LOCATION" permission which has
a protection level of signature
|
public
boolean
setLocationProviderState
(String provider, boolean enable)
Deprecated
in API level 27
NOTE: This API is not available since Android 10.
API to enable or disable a given location provider.
Parameters
provider
| The case sensitive location provider name. Sample values are gps,
network, passive. |
enable
| true to enable the location provider, false to
disable the provider. |
Returns
true
if set location service is successful, else
false
.
Usage
An administrator can use this API to enable or disable a location
provider. If set to false , given location provider control
is disabled, and the user cannot turn it on until the administrator
enables it again. If set to true , given location provider
control is enabled. Enabling a given location provider enables the
corresponding UI setting for user change but does not enable the location
provider itself. Please note some UI settings may require more than one
location provider enabled so they can be available for user changes. All
available location providers on the device can be obtained by using
getAllLocationProviders() .
|
EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
LocationPolicy locationPolicy = edm.getLocationPolicy();
String gpsProvider = "gps";// case sensitive
try {
boolean result = locationPolicy.setLocationProviderState(gpsProvider, false);
if (result == true) {
Log.d(TAG, " GPS location provider is disabled !!!");
} else {
Log.d(TAG, "GPS location provider disable failed !!!");
}
} catch (SecurityException e) {
Log.w(TAG, "SecurityException: " + e);
}
|
For Container:
NOTE: Since MDM 5.3, only Android users (Owner/Guest user)
administrator can call this API. For container, API will return false.
// When you create container successfully, containerID will be
// returned via intent.
// Use this containerID in below API.
EnterpriseKnoxManager ekm = EnterpriseKnoxManager.getInstance(context);
KnoxContainerManager kcm = ekm.getKnoxContainerManager(containerID);
LocationPolicy locationPolicy = kcm.getLocationPolicy();
String gpsProvider = "gps";// case sensitive
try {
boolean result = locationPolicy.setLocationProviderState(gpsProvider, false);
if (result == true) {
Log.d(TAG, " GPS location provider is disabled !!!");
} else {
Log.d(TAG, "GPS location provider disable failed !!!");
}
} catch (SecurityException e) {
Log.w(TAG, "SecurityException: " + e);
}
|
Permission
The use of this API requires the caller to have the
"com.samsung.android.knox.permission.KNOX_LOCATION" permission which has
a protection level of signature
|
public
boolean
startGPS
(boolean start)
Deprecated
in API level 27
API to start or stop GPS on the device.
Parameters
start
| true to start GPS, false to stop. |
Returns
true
if start or stop GPS is successful, else
false
.
Usage
An administrator can use this API to start or stop GPS on the
device. If set to true , GPS is started. If set to
false , GPS is stopped.
|
EnterpriseDeviceManager edm = EnterpriseDeviceManager.getInstance(context);
LocationPolicy locationPolicy = edm.getLocationPolicy();
try {
boolean result = locationPolicy.startGPS(true);
if (result == true) {
Log.d(TAG, "Start GPS success !!!");
} else {
Log.d(TAG, "Start GPS success fail !!!");
}
} catch (SecurityException e) {
Log.w(TAG, "SecurityException: " + e);
}
|
For Container:
// When you create container successfully, containerID will be
// returned via intent.
// Use this containerID in below API.
EnterpriseKnoxManager ekm = EnterpriseKnoxManager.getInstance(context);
KnoxContainerManager kcm = ekm.getKnoxContainerManager(containerID);
LocationPolicy locationPolicy = kcm.getLocationPolicy();
try {
boolean result = locationPolicy.startGPS(true);
if (result == true) {
Log.d(TAG, "Start GPS success !!!");
} else {
Log.d(TAG, "Start GPS success fail !!!");
}
} catch (SecurityException e) {
Log.w(TAG, "SecurityException: " + e);
}
|
Permission
The use of this API requires the caller to have the
"com.samsung.android.knox.permission.KNOX_LOCATION" permission which has
a protection level of signature
|