BasicManagedProfile / src / com.example.android.basicmanagedprofile /

MainActivity.java

1
/*
2
 * Copyright (C) 2014 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.basicmanagedprofile;
18
 
19
import android.app.Activity;
20
import android.app.admin.DevicePolicyManager;
21
import android.content.Context;
22
import android.os.Bundle;
23
 
24
public class MainActivity extends Activity {
25
 
26
    @Override
27
    protected void onCreate(Bundle savedInstanceState) {
28
        super.onCreate(savedInstanceState);
29
        setContentView(R.layout.activity_main_real);
30
        if (savedInstanceState == null) {
31
            DevicePolicyManager manager = (DevicePolicyManager)
32
                    getSystemService(Context.DEVICE_POLICY_SERVICE);
33
            if (manager.isProfileOwnerApp(getApplicationContext().getPackageName())) {
34
                // If the managed profile is already set up, we show the main screen.
35
                showMainFragment();
36
            } else {
37
                // If not, we show the set up screen.
38
                showSetupProfile();
39
            }
40
        }
41
    }
42
 
43
    private void showSetupProfile() {
44
        getFragmentManager().beginTransaction()
45
                .replace(R.id.container, SetupProfileFragment.newInstance())
46
                .commit();
47
    }
48
 
49
    private void showMainFragment() {
50
        getFragmentManager().beginTransaction()
51
                .add(R.id.container, BasicManagedProfileFragment.newInstance())
52
                .commit();
53
    }
54
 
55
}