android.app.admin.DevicePolicyManager#ACTION_ADD_DEVICE_ADMIN源码实例Demo

下面列出了android.app.admin.DevicePolicyManager#ACTION_ADD_DEVICE_ADMIN 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: RelaxFinger   文件: SettingFragment.java
private void lockScreenChange(boolean newValue) {

        mPreferences.put("lockScreenSwitch", newValue);
        mIsAdmin = mDeviceManager.isAdminActive(mComponentName);

        if (newValue) {

            if (!mIsAdmin) {
                Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
                intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mComponentName);
                mContext.startActivity(intent);
            }
        } else {

            if (mIsAdmin) {

                mDeviceManager.removeActiveAdmin(mComponentName);
            }
        }

    }
 
源代码2 项目: product-emm   文件: MainActivity.java
/**
 * Start device admin activation request.
 *
 * @param cdmDeviceAdmin - Device admin component.
 */
private void startDeviceAdminPrompt(ComponentName cdmDeviceAdmin) {
    DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (!devicePolicyManager.isAdminActive(cdmDeviceAdmin)) {
        Intent deviceAdminIntent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        deviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, cdmDeviceAdmin);
        deviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                                   getResources().getString(R.string.device_admin_enable_alert));
        startActivityForResult(deviceAdminIntent, ACTIVATION_REQUEST);
    } else {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP |
                        Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }
}
 
源代码3 项目: SnooperStopper   文件: MainActivity.java
@Override
public boolean onPreferenceChange(Preference pref, Object newValue) {
    boolean isChecked = (boolean) newValue;
    if (isChecked) {
        Log.d(TAG, "switchAdmin.isChecked() == true");
        Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, snooperStopperDeviceAdmin);
        intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                "Monitors failed unlock attempts and shutdowns phone if limit is reached");
        startActivityForResult(intent, ACTIVATION_REQUEST);
    } else {
        Log.d(TAG, "switchAdmin.isChecked() == false");
        devicePolicyManager.removeActiveAdmin(snooperStopperDeviceAdmin);
        updateSwitchAdminHandler.postDelayed(updateSwitchAdminRunnable, 1000);
    }
    return true;
}
 
源代码4 项目: odm   文件: GetAdminActivity.java
@Override
public void onClick(View v) {
	/*
	if (v == lock) {
		boolean active = deviceManger.isAdminActive(compName);
		if (active) {
			deviceManger.lockNow();
		}
	}
	*/
	if (v == enable) {
		Logd(TAG, "Attempting to enable admin");
		Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
		intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, compName);
		intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "ODM requires admin access for locking and wiping the device.");
		startActivityForResult(intent, RESULT_ENABLE);
	}
}
 
源代码5 项目: MaxLock   文件: ConfigView.java
@SuppressLint("CommitPrefEdits")
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
    int c = -1;
    switch (compoundButton.getId()) {
        case R.id.first_start_app_xposed:
            c++;
        case R.id.first_start_app_settings:
            c++;
        case R.id.first_start_app_package:
            c++;
            MLPreferences.getPrefsApps(getContext()).edit().putBoolean(app_names[c], b).commit();
            break;
        case R.id.first_start_app_device_admin:
            if (b) {
                Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
                intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, deviceAdmin);
                getContext().startActivity(intent);
            } else {
                devicePolicyManager.removeActiveAdmin(deviceAdmin);
            }
            break;
    }
}
 
源代码6 项目: AdminControl   文件: ControlYourDeviceActivity.java
/**
 * Show android system dialog to request device admin permission.
 * */
private void promptDeviceAdmin() {
        Intent requestDeviceAdminIntent =
                new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        requestDeviceAdminIntent
                .putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceOwnerComponent);
        startActivityForResult(requestDeviceAdminIntent, ACTIVATION_REQUEST);
}
 
源代码7 项目: notSABS   文件: DeviceAdminInteractor.java
/**
 * Force user to enable administrator
 */
public void forceEnableAdmin(Context context) {
    Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName);
    intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Policy provider");
    ((Activity) context).startActivityForResult(intent, RESULT_ENABLE);
}
 
源代码8 项目: SABS   文件: DeviceAdminInteractor.java
/**
 * Force user to enable administrator
 */
public void forceEnableAdmin(Context context) {
    Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName);
    intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Policy provider");
    ((Activity) context).startActivityForResult(intent, RESULT_ENABLE);
}
 
源代码9 项目: LaunchEnr   文件: PermissionUtils.java
public static void askForAdmin(Activity activity) {

        ComponentName mComponentName = new ComponentName(activity, AdminReceiver.class);
        Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mComponentName);
        activity.startActivity(intent);
    }
 
源代码10 项目: FreezeYou   文件: DevicePolicyManagerUtils.java
public static void openDevicePolicyManager(Context context) {
    showToast(context, R.string.needActiveAccessibilityService);
    ComponentName componentName = new ComponentName(context, DeviceAdminReceiver.class);
    Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName);
    context.startActivity(intent);
}
 
源代码11 项目: Lock   文件: MainActivity.java
private void enableAppAsAdministrator() {
    i("[enableAppAsAdministrator] startActivityForResult: requestCode=%d", REQUEST_CODE_ENABLE_ADMIN);
    Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mCN);
    intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, getString(R.string.receiver_expl));
    startActivityForResult(intent, REQUEST_CODE_ENABLE_ADMIN);
}
 
源代码12 项目: libcommon   文件: DeviceAdminReceiverLock.java
public static void requestScreenLock(@NonNull final Activity activity, final boolean finish) {
	if (!checkScreenLock(activity, finish)) {
		// スクリーンをロックできなかった時はデバイス管理者が無効になってるはずなのでデバイス管理者有効画面を表示する
		final Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
		intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, new ComponentName(activity, DeviceAdminReceiverLock.class));
		intent.putExtra(EXTRA_REQUEST_FINISH, finish);
		activity.startActivityForResult(intent, REQ_SCREEN_LOCK);
	}
}
 
源代码13 项目: product-emm   文件: AlreadyRegisteredActivity.java
/**
 * Start device admin activation request.
 * @param cdmDeviceAdmin - Device admin component.
 */
private void startDeviceAdminPrompt(ComponentName cdmDeviceAdmin){
	Intent deviceAdminIntent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
	deviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, cdmDeviceAdmin);
	deviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
	                           getResources()
			                           .getString(R.string.device_admin_enable_alert));
	startActivityForResult(deviceAdminIntent, ACTIVATION_REQUEST);
}
 
源代码14 项目: codeexamples-android   文件: DeviceAdminSample.java
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    if (super.onPreferenceChange(preference, newValue)) {
        return true;
    }
    boolean value = (Boolean) newValue;
    if (preference == mEnableCheckbox) {
        if (value != mAdminActive) {
            if (value) {
                // Launch the activity to have the user enable our admin.
                Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
                intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminSample);
                intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                        mActivity.getString(R.string.add_admin_extra_app_text));
                startActivityForResult(intent, REQUEST_CODE_ENABLE_ADMIN);
                // return false - don't update checkbox until we're really active
                return false;
            } else {
                mDPM.removeActiveAdmin(mDeviceAdminSample);
                enableDeviceCapabilitiesArea(false);
                mAdminActive = false;
            }
        }
    } else if (preference == mDisableCameraCheckbox) {
        mDPM.setCameraDisabled(mDeviceAdminSample, value);
        reloadSummaries();
    }
    return true;
}
 
源代码15 项目: habpanelviewer   文件: PreferencesOther.java
private void installAsAdmin() {
    Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, AdminReceiver.COMP);
    intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, getString(R.string.deviceAdminDescription));
    startActivityForResult(intent, Constants.REQUEST_DEVICE_ADMIN);
}
 
源代码16 项目: rebootmenu   文件: URMUtils.java
/**
 * 用辅助功能锁屏
 *
 * @param activity            1
 * @param componentName       2
 * @param requestCode         3
 * @param devicePolicyManager 4
 * @param needConfig          是否需要 配置管理员
 */

public static void lockScreen(@NonNull Activity activity, ComponentName componentName, int requestCode, DevicePolicyManager devicePolicyManager, boolean needConfig) {
    new DebugLog("lockScreen", DebugLog.LogLevel.V);
    //设备管理器是否启用
    boolean active = devicePolicyManager.isAdminActive(componentName);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
        //自动移除不必要的管理员,避免在卸载时造成困扰
        if (active) devicePolicyManager.removeActiveAdmin(componentName);
        //请求打开辅助服务设置
        if (!isAccessibilitySettingsOn(activity.getApplicationContext())) {
            new TextToast(activity.getApplicationContext(), activity.getString(R.string.service_disabled));
            try {
                activity.startActivity(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS));
            } catch (Throwable t) {
                t.printStackTrace();
                UIUtils.visibleHint(activity, R.string.accessibility_settings_not_found);
            }
        } else
            LocalBroadcastManager.getInstance(activity).sendBroadcast(new Intent(UnRootAccessibility.LOCK_SCREEN_ACTION));
        activity.finish();
    } else {
        if (!active) {
            //请求启用
            Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
            intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName);
            intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, activity.getString(R.string.service_explanation));
            try {
                activity.startActivityForResult(intent, requestCode);
            } catch (ActivityNotFoundException e) {
                UIUtils.visibleHint(activity, R.string.hint_add_dev_admin_activity_not_found);
            }
        } else {
            devicePolicyManager.lockNow();
            if (needConfig)
                //如果需要二次确认,禁用设备管理器。(这里的策略和root模式的锁屏无需确认不同)
                if (!ConfigManager.get(ConfigManager.NO_NEED_TO_CONFIRM)) {
                    devicePolicyManager.removeActiveAdmin(componentName);
                }
            activity.finish();
        }
    }
}
 
源代码17 项目: always-on-amoled   文件: SettingsFragment.java
private void askDeviceAdmin(@StringRes int message) {
    Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mAdminName);
    intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, getString(message));
    startActivityForResult(intent, DEVICE_ADMIN_REQUEST_CODE);
}
 
源代码18 项目: SimplePomodoro-android   文件: MyScreenLocker.java
public void activeManage() {
    Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName);
    intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, mActivity.getString(R.string.screen_locker_warnning));
    mActivity.startActivityForResult(intent, 0);
}