當前位置: 首頁>>代碼示例>>Java>>正文


Java DevicePolicyManager.isDeviceOwnerApp方法代碼示例

本文整理匯總了Java中android.app.admin.DevicePolicyManager.isDeviceOwnerApp方法的典型用法代碼示例。如果您正苦於以下問題:Java DevicePolicyManager.isDeviceOwnerApp方法的具體用法?Java DevicePolicyManager.isDeviceOwnerApp怎麽用?Java DevicePolicyManager.isDeviceOwnerApp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.app.admin.DevicePolicyManager的用法示例。


在下文中一共展示了DevicePolicyManager.isDeviceOwnerApp方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getCurrentState

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
private State getCurrentState() {
    ComponentName componentName = componentName();
    DevicePolicyManager policyManager =
            (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (!policyManager.isAdminActive(componentName)) {
        return State.NEEDS_PERMISSIONS;
    }
    if (!policyManager.getCameraDisabled(componentName)) {
        return State.HAS_PERMISSIONS;
    }
    if (!policyManager.isDeviceOwnerApp(BuildConfig.APPLICATION_ID)) {
        return State.CAMERA_DISABLED;
    }
    // Apparently we can't query for user restrictions, so just always set them if they're not
    // already set. We know that we're allowed to because we're the device owner.
    policyManager.addUserRestriction(componentName, UserManager.DISALLOW_ADD_USER);
    policyManager.addUserRestriction(componentName, UserManager.DISALLOW_FACTORY_RESET);
    return State.IS_DEVICE_OWNER;
}
 
開發者ID:disablecamera,項目名稱:disablecamera,代碼行數:20,代碼來源:DisableCameraActivity.java

示例2: onCreate

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);

    ComponentName deviceAdmin = new ComponentName(this, AdminReceiver.class);
    mDpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (!mDpm.isAdminActive(deviceAdmin)) {
        Toast.makeText(this, getString(R.string.not_device_admin), Toast.LENGTH_SHORT).show();
    }

    if (mDpm.isDeviceOwnerApp(getPackageName())) {
        mDpm.setLockTaskPackages(deviceAdmin, new String[]{getPackageName()});
    } else {
        Toast.makeText(this, getString(R.string.not_device_owner), Toast.LENGTH_SHORT).show();
    }

    mDecorView = getWindow().getDecorView();

    mWebView.loadUrl("http://www.vicarasolutions.com/");
}
 
開發者ID:sureshjoshi,項目名稱:android-kiosk-example,代碼行數:23,代碼來源:MainActivity.java

示例3: isManaged

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
/**
 * @return true if the device or profile is already owned
 */
public static boolean isManaged(Context context) {
    DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(
            Context.DEVICE_POLICY_SERVICE);

    List<ComponentName> admins = devicePolicyManager.getActiveAdmins();
    if (admins == null) return false;
    for (ComponentName admin : admins) {
        String adminPackageName = admin.getPackageName();
        if (devicePolicyManager.isDeviceOwnerApp(adminPackageName)
                || devicePolicyManager.isProfileOwnerApp(adminPackageName)) {
            return true;
        }
    }

    return false;
}
 
開發者ID:googlesamples,項目名稱:android-testdpc,代碼行數:20,代碼來源:ProvisioningStateUtil.java

示例4: lockApplication

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
public static boolean lockApplication(Activity activity) {
    DevicePolicyManager dpm =
            (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (dpm.isLockTaskPermitted(activity.getPackageName())
            && dpm.isDeviceOwnerApp(activity.getPackageName())) {
        IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MAIN);
        intentFilter.addCategory(Intent.CATEGORY_HOME);
        intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
        ComponentName adminComponentName =
                new ComponentName(activity, HomerPlayerDeviceAdmin.class);
        ComponentName activityComponentName =
                new ComponentName(activity, MainActivity.class);
        dpm.addPersistentPreferredActivity(
                adminComponentName, intentFilter, activityComponentName);
        lockScreen(activity);
        return true;
    }
    return false;
}
 
開發者ID:msimonides,項目名稱:homerplayer,代碼行數:20,代碼來源:ApplicationLocker.java

示例5: enableLockTask

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
public static void enableLockTask(Context context) {
    DevicePolicyManager dpm =
            (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    ComponentName adminComponentName = new ComponentName(context, HomerPlayerDeviceAdmin.class);
    if (dpm.isAdminActive(adminComponentName) &&
           dpm.isDeviceOwnerApp(context.getPackageName()))
        dpm.setLockTaskPackages(adminComponentName, new String[]{context.getPackageName()});
}
 
開發者ID:msimonides,項目名稱:homerplayer,代碼行數:9,代碼來源:HomerPlayerDeviceAdmin.java

示例6: canEditWifi

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
private boolean canEditWifi()
{
    DevicePolicyManager devicePolicyManager =
            (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);

    return devicePolicyManager.isAdminActive(new ComponentName(this, AdminReceiver.class)) &&
           devicePolicyManager.isDeviceOwnerApp(getPackageName());
}
 
開發者ID:steinwurf,項目名稱:adb-join-wifi,代碼行數:10,代碼來源:MainActivity.java

示例7: updatePasswordQualityNotification

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
private static void updatePasswordQualityNotification(Context context) {
    DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(
            Context.DEVICE_POLICY_SERVICE);

    if (!devicePolicyManager.isProfileOwnerApp(context.getPackageName())
            && !devicePolicyManager.isDeviceOwnerApp(context.getPackageName())) {
        // Only try to update the notification if we are a profile or device owner.
        return;
    }

    NotificationManager nm = (NotificationManager)
            context.getSystemService(Context.NOTIFICATION_SERVICE);

    if (!devicePolicyManager.isActivePasswordSufficient()) {
        NotificationCompat.Builder warn = NotificationUtil.getNotificationBuilder(context);
        warn.setOngoing(true)
                .setSmallIcon(R.drawable.ic_launcher)
                .setTicker(context.getText(R.string.password_not_compliant_title))
                .setContentTitle(context.getText(R.string.password_not_compliant_title))
                .setContentText(context.getText(R.string.password_not_compliant_content))
                .setContentIntent(PendingIntent.getActivity(context, /*requestCode*/ -1,
                        new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD), /*flags*/ 0));
        nm.notify(CHANGE_PASSWORD_NOTIFICATION_ID, warn.getNotification());
    } else {
        nm.cancel(CHANGE_PASSWORD_NOTIFICATION_ID);
    }
}
 
開發者ID:googlesamples,項目名稱:android-testdpc,代碼行數:28,代碼來源:DeviceAdminReceiver.java

示例8: onCreate

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
    // Check arguments- see whether we're supposed to run on behalf of the parent profile.
    final Bundle arguments = getArguments();
    if (arguments != null) {
        mParentInstance = arguments.getBoolean(EXTRA_PARENT_PROFILE, false);
    }

    mAdminComponent = DeviceAdminReceiver.getComponentName(getActivity());

    // Get a device policy manager for the current user.
    mDevicePolicyManager = (DevicePolicyManager)
            getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);

    // Store whether we are the profile owner for faster lookup.
    mProfileOwner = mDevicePolicyManager.isProfileOwnerApp(getActivity().getPackageName());
    mDeviceOwner = mDevicePolicyManager.isDeviceOwnerApp(getActivity().getPackageName());

    if (mParentInstance) {
        mDevicePolicyManager = mDevicePolicyManager.getParentProfileInstance(mAdminComponent);
    }

    // Put at last to make sure all initializations above are done before subclass's
    // onCreatePreferences is called.
    super.onCreate(savedInstanceState);

    // Switch to parent profile if we are running on their behalf.
    // This needs to be called after super.onCreate because preference manager is set up
    // inside super.onCreate.
    if (mParentInstance) {
        final PreferenceManager pm = getPreferenceManager();
        pm.setSharedPreferencesName(pm.getSharedPreferencesName() + TAG_PARENT);
    }
}
 
開發者ID:googlesamples,項目名稱:android-testdpc,代碼行數:35,代碼來源:ProfileOrParentFragment.java

示例9: isManagedByTestDPC

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
/**
 * @return true if the device or profile is already owned by TestDPC
 */
public static boolean isManagedByTestDPC(Context context) {
    DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(
            Context.DEVICE_POLICY_SERVICE);
    String packageName = context.getPackageName();

    return devicePolicyManager.isProfileOwnerApp(packageName)
            || devicePolicyManager.isDeviceOwnerApp(packageName);
}
 
開發者ID:googlesamples,項目名稱:android-testdpc,代碼行數:12,代碼來源:ProvisioningStateUtil.java

示例10: getCurrentAdmin

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
private int getCurrentAdmin() {
    final DevicePolicyManager dpm =
            (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
    final String packageName = mContext.getPackageName();

    if (dpm.isDeviceOwnerApp(packageName)) {
        return ADMIN_DEVICE_OWNER;
    }
    if (dpm.isProfileOwnerApp(packageName)) {
        return ADMIN_PROFILE_OWNER;
    }
    return ADMIN_NONE;
}
 
開發者ID:googlesamples,項目名稱:android-testdpc,代碼行數:14,代碼來源:DpcPreferenceHelper.java

示例11: isAvailable

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
@Override
public boolean isAvailable(Context context) {
    DevicePolicyManager dpm = (DevicePolicyManager)
            context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    return dpm.isDeviceOwnerApp(context.getPackageName())
            && Util.getBindDeviceAdminTargetUsers(context).size() == 1;
}
 
開發者ID:googlesamples,項目名稱:android-testdpc,代碼行數:8,代碼來源:BindDeviceAdminFragment.java

示例12: unlockApplication

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
public static void unlockApplication(Activity activity) {
    DevicePolicyManager dpm =
            (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (dpm.isLockTaskPermitted(activity.getPackageName())
            && dpm.isDeviceOwnerApp(activity.getPackageName())) {
        ComponentName adminComponentName =
                new ComponentName(activity, HomerPlayerDeviceAdmin.class);
        dpm.clearPackagePersistentPreferredActivities(
                adminComponentName, activity.getPackageName());
        unlockScreen(activity);
    }
}
 
開發者ID:msimonides,項目名稱:homerplayer,代碼行數:13,代碼來源:ApplicationLocker.java

示例13: isDeviceOwnerApp

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
public static boolean isDeviceOwnerApp(Context context) {
    DevicePolicyManager manager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    return manager.isDeviceOwnerApp(context.getPackageName());
}
 
開發者ID:mthli,項目名稱:Mount,代碼行數:5,代碼來源:PolicyUtils.java

示例14: isDeviceOwner

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
@TargetApi(VERSION_CODES.LOLLIPOP)
public static boolean isDeviceOwner(Context context) {
    final DevicePolicyManager dpm = getDevicePolicyManager(context);
    return dpm.isDeviceOwnerApp(context.getPackageName());
}
 
開發者ID:googlesamples,項目名稱:android-testdpc,代碼行數:6,代碼來源:Util.java

示例15: isDeviceOwner

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
public static boolean isDeviceOwner(Context context) {
    DevicePolicyManager dpm =
            (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    return dpm.isDeviceOwnerApp(context.getPackageName());
}
 
開發者ID:msimonides,項目名稱:homerplayer,代碼行數:6,代碼來源:HomerPlayerDeviceAdmin.java


注:本文中的android.app.admin.DevicePolicyManager.isDeviceOwnerApp方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。