本文整理匯總了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;
}
示例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/");
}
示例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;
}
示例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;
}
示例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()});
}
示例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());
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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());
}
示例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());
}
示例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());
}