Skip to content

Most visited

Recently visited

navigation
DeviceOwner / src / com.example.android.deviceowner /

DeviceOwnerReceiver.java

1
/*
2
 * Copyright (C) 2015 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
 
17
package com.example.android.deviceowner;
18
 
19
import android.app.admin.DeviceAdminReceiver;
20
import android.app.admin.DevicePolicyManager;
21
import android.content.ComponentName;
22
import android.content.Context;
23
import android.content.Intent;
24
 
25
/**
26
 * Handles events related to device owner.
27
 */
28
public class DeviceOwnerReceiver extends DeviceAdminReceiver {
29
 
30
    /**
31
     * Called on the new profile when device owner provisioning has completed. Device owner
32
     * provisioning is the process of setting up the device so that its main profile is managed by
33
     * the mobile device management (MDM) application set up as the device owner.
34
     */
35
    @Override
36
    public void onProfileProvisioningComplete(Context context, Intent intent) {
37
        // Enable the profile
38
        DevicePolicyManager manager =
39
                (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
40
        ComponentName componentName = getComponentName(context);
41
        manager.setProfileName(componentName, context.getString(R.string.profile_name));
42
        // Open the main screen
43
        Intent launch = new Intent(context, MainActivity.class);
44
        launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
45
        context.startActivity(launch);
46
    }
47
 
48
    /**
49
     * @return A newly instantiated {@link android.content.ComponentName} for this
50
     * DeviceAdminReceiver.
51
     */
52
    public static ComponentName getComponentName(Context context) {
53
        return new ComponentName(context.getApplicationContext(), DeviceOwnerReceiver.class);
54
    }
55
 
56
}
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)