[Music]
if you're building an enterprise app and
need admins to deploy custom
configurations like server settings
or turning off syncing over mobile you
might want to consider using managed
configurations i'm todd berner and i
work for android enterprise
and today i want to talk to you about
managed configurations
managed configurations let an admin
control how your app behaves
within their organization by using the
settings that you decide to expose
they are previously known as app
restrictions now managed configurations
are used
to configure your app in many ways
things like printer settings email
servers and so on
anything an it admin would like to set
up in your app can be used as a managed
configuration
adding managed configurations
functionality to your app is
straightforward
to declare them in your app you can
create a managed configurations file
and reference that file in your app's
manifest
the manage configurations file is a
simple xml file
that resides in the resources folder it
has a single top level element
and a single child level element for
every configuration option
you'd like to create for your app the
key attribute
is your reference on that configuration
and is what you use to access the value
later on
the title and description texts are used
to communicate with the i t admins
what the configuration option is used
for the data type defines the type of
that configuration
and the default value is what is applied
by default
you can also group configurations
together in bundles
this is typically used when a group of
configurations collectively set up
something in your app
for example a vpn server with a username
and password
this also allows you to create bundle
arrays which you can group multiple
values for the same configuration bundle
once you've created your managed
configurations file in your app
it admins will be able to see all these
configurations through the enterprise
mobility management system
let's look at a real example of what it
admins see
for the gmail app when managed through
their organization
once an it admin creates a set of values
for these configurations
they can then create a policy and send
it over to their managed devices
to read values sent to your app get the
restrictions manager object
which you can get by calling the get
system service on the activity
once you have a restrictions manager you
can get the current configuration
setting
by calling its get applications
restriction method
you can also get the same restrictions
by calling get application restrictions
on a user manager
get application restrictions in both
cases returns a bundle containing
a key value pair for each configuration
that's been set
the key is what you've specified when
declaring the configuration in the
restrictions
xml file and the value is what's been
set by the it admin
your app should now take the appropriate
action or behavior based on those
configuration values
for example this app is checking to see
if the download on cellular
configuration was set to true
if so then it should turn off any
cellular download
in the app retrieving configuration
is a heavy operation and should only be
done when the app first launches or
resumes
a good practice is to cache any settings
for the duration of the app's lifecycle
you can also be notified for any
configuration changes
while your app is running by listening
to the action applications restriction
changed intent once triggered you can
retrieve the values
the same way as we did during app launch
and change the app's behavior
accordingly another good practice when
applying managed configuration is to let
it admins know when the configuration
settings have been successfully applied
and if for any reason there is an error
notify them
this will detect typos and mistakes
earlier when using the values for those
configurations
to send feedback to the it admin you can
use the enterprise.feedback
jetpack library which integrates nicely
with the enterprise mobility tools
and will automatically send admins a
notification of any feedback you've sent
in summary managed configuration lets
apps change behavior
by exposing any settings they choose it
admins then set those values
and the app can read those and change
behavior accordingly
to use them in your app you'll need to
declare those configurations in a
restrictions xml file
read the values at app launch and resume
and then send back an acknowledgement or
error code using the enterprise feedback
jetpack library
finally you can use the testdpc app to
configure any of those settings just
like
an it admin would which will allow you
to test your app
and see how it behave with all the
different settings
check the documentation for more details
on managed configurations and for a
step-by-step
exercise try completing the managed
configuration code lab
where you'll build a sample app that
covers all we talked about here and test
it using test dpc
thanks for watching and happy coding
you