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


Java UserManager類代碼示例

本文整理匯總了Java中android.os.UserManager的典型用法代碼示例。如果您正苦於以下問題:Java UserManager類的具體用法?Java UserManager怎麽用?Java UserManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: getCurrentState

import android.os.UserManager; //導入依賴的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: onResume

import android.os.UserManager; //導入依賴的package包/類
@Override
public void onResume() {
    super.onResume();
    refreshNotificationListeners();
    lookupRingtoneNames();
    updateNotificationPreferenceState();
    mSettingsObserver.register(true);
    mReceiver.register(true);
    updateRingPreference();
    updateEffectsSuppressor();
    for (VolumeSeekBarPreference volumePref : mVolumePrefs) {
        volumePref.onActivityResume();
    }
    if (mIncreasingRingVolume != null) {
        mIncreasingRingVolume.onActivityResume();
    }
    boolean isRestricted = mUserManager.hasUserRestriction(UserManager.DISALLOW_ADJUST_VOLUME);
    for (String key : RESTRICTED_KEYS) {
        Preference pref = findPreference(key);
        if (pref != null) {
            pref.setEnabled(!isRestricted);
        }
    }
}
 
開發者ID:ric96,項目名稱:lineagex86,代碼行數:25,代碼來源:SoundSettings.java

示例3: createWorkspaceLoaderFromAppRestriction

import android.os.UserManager; //導入依賴的package包/類
/**
 * Creates workspace loader from an XML resource listed in the app restrictions.
 *
 * @return the loader if the restrictions are set and the resource exists; null otherwise.
 */
private AutoInstallsLayout createWorkspaceLoaderFromAppRestriction(AppWidgetHost widgetHost) {
    Context ctx = getContext();
    UserManager um = (UserManager) ctx.getSystemService(Context.USER_SERVICE);
    Bundle bundle = um.getApplicationRestrictions(ctx.getPackageName());
    if (bundle == null) {
        return null;
    }

    String packageName = bundle.getString(RESTRICTION_PACKAGE_NAME);
    if (packageName != null) {
        try {
            Resources targetResources = ctx.getPackageManager()
                    .getResourcesForApplication(packageName);
            return AutoInstallsLayout.get(ctx, packageName, targetResources,
                    widgetHost, mOpenHelper);
        } catch (NameNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }
    return null;
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:28,代碼來源:LauncherProvider.java

示例4: getLauncherShortcuts

import android.os.UserManager; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.N_MR1)
private int getLauncherShortcuts() {
    LauncherApps launcherApps = (LauncherApps) getSystemService(LAUNCHER_APPS_SERVICE);
    if(launcherApps.hasShortcutHostPermission()) {
        UserManager userManager = (UserManager) getSystemService(USER_SERVICE);

        LauncherApps.ShortcutQuery query = new LauncherApps.ShortcutQuery();
        query.setActivity(ComponentName.unflattenFromString(componentName));
        query.setQueryFlags(LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC
                | LauncherApps.ShortcutQuery.FLAG_MATCH_MANIFEST
                | LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED);

        shortcuts = launcherApps.getShortcuts(query, userManager.getUserForSerialNumber(userId));
        if(shortcuts != null)
            return shortcuts.size();
    }

    return 0;
}
 
開發者ID:farmerbb,項目名稱:Taskbar,代碼行數:20,代碼來源:ContextMenuActivity.java

示例5: isRestrictedProfile

import android.os.UserManager; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static boolean isRestrictedProfile(Context context) {
    if (Versions.preJBMR2) {
        // Early versions don't support restrictions at all
        return false;
    }

    final UserManager mgr = (UserManager) context.getSystemService(Context.USER_SERVICE);
    final Bundle restrictions = new Bundle();
    restrictions.putAll(mgr.getApplicationRestrictions(context.getPackageName()));
    restrictions.putAll(mgr.getUserRestrictions());

    for (String key : restrictions.keySet()) {
        if (restrictions.getBoolean(key)) {
            // At least one restriction is enabled -> We are a restricted profile
            return true;
        }
    }

    return false;
}
 
開發者ID:jrconlin,項目名稱:mc_backup,代碼行數:22,代碼來源:RestrictedProfiles.java

示例6: onStartCommand

import android.os.UserManager; //導入依賴的package包/類
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    createNotificationChannel();
    startForeground();

    if (getSystemService(UserManager.class).isUserUnlocked()
            || getActiveResetPasswordToken() == null) {
        stopSelf();
        mNm.cancel(NOTIFICATION_FOREGROUND);
        return START_NOT_STICKY;
    }
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_USER_UNLOCKED);
    filter.addAction(ACTION_RESET_PASSWORD);
    registerReceiver(receiver, filter);

    showNotification();
    return START_REDELIVER_INTENT;
}
 
開發者ID:googlesamples,項目名稱:android-testdpc,代碼行數:20,代碼來源:ResetPasswordService.java

示例7: getCalendars

import android.os.UserManager; //導入依賴的package包/類
private static List<CalendarInfo> getCalendars(Context context) {
    final List<CalendarInfo> calendars = new ArrayList<>();
    for (UserHandle user : UserManager.get(context).getUserProfiles()) {
        final Context userContext = getContextForUser(context, user);
        if (userContext != null) {
            addCalendars(userContext, calendars);
        }
    }
    Collections.sort(calendars, CALENDAR_NAME);
    return calendars;
}
 
開發者ID:ric96,項目名稱:lineagex86,代碼行數:12,代碼來源:ZenModeEventRuleSettings.java

示例8: supportsDrop

import android.os.UserManager; //導入依賴的package包/類
public static boolean supportsDrop(Context context, Object info) {
    UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
    Bundle restrictions = userManager.getUserRestrictions();
    if (restrictions.getBoolean(UserManager.DISALLOW_APPS_CONTROL, false)
            || restrictions.getBoolean(UserManager.DISALLOW_UNINSTALL_APPS, false)) {
        return false;
    }

    return getUninstallTarget(context, info) != null;
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:11,代碼來源:UninstallDropTarget.java

示例9: getUserLockState

import android.os.UserManager; //導入依賴的package包/類
/**
 * Check if the calling user is running in an "unlocked" state. A user is unlocked only after
 * they've entered their credentials (such as a lock pattern or PIN), and credential-encrypted
 * private app data storage is available.
 * @param context context from which {@link UserManager} should be obtained.
 * @return One of {@link LockState}.
 */
@LockState
public static int getUserLockState(final Context context) {
    if (METHOD_isUserUnlocked == null) {
        return LOCK_STATE_UNKNOWN;
    }
    final UserManager userManager = context.getSystemService(UserManager.class);
    if (userManager == null) {
        return LOCK_STATE_UNKNOWN;
    }
    final Boolean result =
            (Boolean) CompatUtils.invoke(userManager, null, METHOD_isUserUnlocked);
    if (result == null) {
        return LOCK_STATE_UNKNOWN;
    }
    return result ? LOCK_STATE_UNLOCKED : LOCK_STATE_LOCKED;
}
 
開發者ID:rkkr,項目名稱:simple-keyboard,代碼行數:24,代碼來源:UserManagerCompatUtils.java

示例10: updateEnabledState

import android.os.UserManager; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private void updateEnabledState() {
    // This method uses AppRestrictions directly, rather than using the Policy interface,
    // because it must be callable in contexts in which the native library hasn't been
    // loaded. It will always be called from a background thread (except possibly in tests)
    // so can get the App Restrictions synchronously.
    UserManager userManager = (UserManager) getContext().getSystemService(Context.USER_SERVICE);
    Bundle appRestrictions = userManager
            .getApplicationRestrictions(getContext().getPackageName());
    setEnabled(appRestrictions.getBoolean(SUPERVISED_USER_CONTENT_PROVIDER_ENABLED));
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:12,代碼來源:SupervisedUserContentProvider.java

示例11: supportsDrop

import android.os.UserManager; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static boolean supportsDrop(Context context, Object info) {
    if (Utilities.ATLEAST_JB_MR2) {
        UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
        Bundle restrictions = userManager.getUserRestrictions();
        if (restrictions.getBoolean(UserManager.DISALLOW_APPS_CONTROL, false)
                || restrictions.getBoolean(UserManager.DISALLOW_UNINSTALL_APPS, false)) {
            return false;
        }
    }

    Pair<ComponentName, Integer> componentInfo = getAppInfoFlags(info);
    return componentInfo != null && (componentInfo.second & AppInfo.DOWNLOADED_FLAG) != 0;
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:15,代碼來源:UninstallDropTarget.java

示例12: createWorkspaceLoaderFromAppRestriction

import android.os.UserManager; //導入依賴的package包/類
/**
 * Creates workspace loader from an XML resource listed in the app restrictions.
 *
 * @return the loader if the restrictions are set and the resource exists; null otherwise.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private AutoInstallsLayout createWorkspaceLoaderFromAppRestriction(AppWidgetHost widgetHost) {
    // UserManager.getApplicationRestrictions() requires minSdkVersion >= 18
    if (!Utilities.ATLEAST_JB_MR2) {
        return null;
    }

    Context ctx = getContext();
    UserManager um = (UserManager) ctx.getSystemService(Context.USER_SERVICE);
    Bundle bundle = um.getApplicationRestrictions(ctx.getPackageName());
    if (bundle == null) {
        return null;
    }

    String packageName = bundle.getString(RESTRICTION_PACKAGE_NAME);
    if (packageName != null) {
        try {
            Resources targetResources = ctx.getPackageManager()
                    .getResourcesForApplication(packageName);
            return AutoInstallsLayout.get(ctx, packageName, targetResources,
                    widgetHost, mOpenHelper);
        } catch (NameNotFoundException e) {
            Log.e(TAG, "Target package for restricted profile not found", e);
            return null;
        }
    }
    return null;
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:34,代碼來源:LauncherProvider.java

示例13: getAppRestrictions

import android.os.UserManager; //導入依賴的package包/類
private void getAppRestrictions(){
  RestrictionsManager restrictionsManager =
          (RestrictionsManager) this
                  .getSystemService(Context.RESTRICTIONS_SERVICE);

  Bundle appRestrictions = restrictionsManager.getApplicationRestrictions();

  // Block user if KEY_RESTRICTIONS_PENDING is true, and save login hint if available
  if(!appRestrictions.isEmpty()){
    if(appRestrictions.getBoolean(UserManager.
            KEY_RESTRICTIONS_PENDING)!=true){
      mLoginHint = appRestrictions.getString(LOGIN_HINT);
    }
    else {
      Toast.makeText(this,R.string.restrictions_pending_block_user,
              Toast.LENGTH_LONG).show();
      finish();
    }
  }
}
 
開發者ID:googlecodelabs,項目名稱:appauth-android-codelab,代碼行數:21,代碼來源:MainActivity.java

示例14: fixLeakInGetMethod

import android.os.UserManager; //導入依賴的package包/類
/**
 * Dirty fix, since the UserManager.get() method is marked as hidden and can't be
 * accessed directly, the current solution it's to use reflection to invoke the get method.
 *
 * @param app - the Application instance where UserManager.get() will be triggered
 */
@TargetApi(17)
public static void fixLeakInGetMethod(Application app) {
    try {
        final Method m = UserManager.class.getMethod(GET_METHOD, Context.class);
        m.setAccessible(true);
        m.invoke(null, app);

        //above is reflection for below...
        //UserManager.get();
    } catch (Throwable e) {
        Log.e(TAG, e.getLocalizedMessage(), e.getCause());
    }
}
 
開發者ID:BlackBoxVision,項目名稱:mvp-helpers,代碼行數:20,代碼來源:UserManagerLeaks.java

示例15: launchAndroidForWork

import android.os.UserManager; //導入依賴的package包/類
private static void launchAndroidForWork(Context context, ComponentName componentName, Bundle bundle, long userId) {
    UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
    LauncherApps launcherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);

    try {
        launcherApps.startMainActivity(componentName, userManager.getUserForSerialNumber(userId), null, bundle);
    } catch (ActivityNotFoundException | NullPointerException e) { /* Gracefully fail */ }
}
 
開發者ID:farmerbb,項目名稱:Taskbar,代碼行數:9,代碼來源:U.java


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