苹果手机远程控制安卓手机

发布时间: 2023-02-23 18:12 阅读: 文章来源:转载

今天我们介绍一下MDM,看了下边的介绍你就知道如何控制自己的设备了,首先介绍一下MDM是什么的缩写,MDM是什么?MDM 是 (Mobile Device Management )的缩写,中文翻译过来就是移动设备管理。随着移动设备计算能力地增强,移动设备携带越来越方便,移动化办公已经成为一种潮流,一种趋势,企业对移动设备管理的需求越来越急切。MDM是企业IT 向移动互联网过渡的平台技术,帮助企业将IT管理能力从传统的 PC 延伸到移动设备甚至 移动应用APP 。随着时间的发展, MDM 厂商逐渐扩展出 MAM (Mobile Application Management)移动设备的应用程序管理,MEM(Mobile Email Management)移动设备的邮件管理和 MCM (Mobile Content Management)移动设备的内容管理等更多功能,但是MDM是这些管理的基础。

一、激活设备管理器

使用MDM功能要先激活设备管理器

代码如下:

/** * 激活设备管理权限 成功执行激活时,DeviceAdminReceiver中的 onEnabled 会响应 */ private void activeManage() { // 启动设备管理(隐式Intent) - 在AndroidManifest.xml中设定相应过滤器 Intent intents = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); // 权限列表 intents.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName); // 描述(additional explanation) intents.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "------ 其他描述 ------"); startActivityForResult(intents, 0); }

二、可以远程对设备做哪些操作

要先获得DevicePolicyManager实例才可以进行控制操作

DevicePolicyManager mDPM = (DevicePolicyManager) mContext .getSystemService(Context.DEVICE_POLICY_SERVICE);

1、控制锁屏

mDPM.lockNow();

2、控制摄像机的使用

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public int setCameraDisabled(boolean disableCamera) { if (isDeviceAdminActive()) { if (API_LEVEL < 14) { return ERROR_UNSUPPORTED; } mDPM.setCameraDisabled(mDeviceAdminSample, disableCamera); return 0; } else { // activateDeviceAdmin(); return ERROR_UNACTIVATED; } } public boolean getCameraDisabled() { if (isDeviceAdminActive()) { if (API_LEVEL < 14) { return false; } return mDPM.getCameraDisabled(mDeviceAdminSample); } else { // activateDeviceAdmin(); return false; } }

3、控制密码

public int resetPasswd(String newPasswd) { if (isDeviceAdminActive()) { boolean succeed = mDPM.resetPassword(newPasswd, DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY); if (succeed) { return 0; } else { return ERROR_PASSWD_QUALITY; } } else { // 激活时间与用户的操作有关,所以不等待,直接返回操作失败 activateDeviceAdmin(); return ERROR_UNACTIVATED; } } public int setPasswdQuality(int value) { if (isDeviceAdminActive()) { if (API_LEVEL < 11) { return ERROR_UNSUPPORTED; } mDPM.setPasswordQuality(mDeviceAdminSample, value); return 0; } else { activateDeviceAdmin(); return ERROR_UNACTIVATED; } } public String getPasswordQuality() { if (isDeviceAdminActive()) { int quality = mDPM.getPasswordQuality(mDeviceAdminSample); switch (quality) { case DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK: return "图案"; case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: return "数字"; case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC: return "字母"; case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC: return "数字和字母"; default: return "其它"; } } else { activateDeviceAdmin(); return "未知"; } } public int setPasswordMinimumLength(int value) { if (isDeviceAdminActive()) { mDPM.setPasswordMinimumLength(mDeviceAdminSample, value); return 0; } else { activateDeviceAdmin(); return ERROR_UNACTIVATED; } } /* * -1无法获取 */ public int getPasswordMinimumLength() { if (isDeviceAdminActive()) { return mDPM.getPasswordMinimumLength(mDeviceAdminSample); } else { activateDeviceAdmin(); return -1; } } // TODO: 2017-2-7 策略信息中并没有该项 @TargetApi(Build.VERSION_CODES.HONEYCOMB) public int setPasswordMinimumLetters(int value) { if (isDeviceAdminActive()) { if (API_LEVEL < 11) { return ERROR_UNSUPPORTED; } mDPM.setPasswordMinimumLetters(mDeviceAdminSample, value); return 0; } else { activateDeviceAdmin(); return ERROR_UNACTIVATED; } } @TargetApi(Build.VERSION_CODES.HONEYCOMB) public int setPasswordMinimumNumeric(int value) { if (isDeviceAdminActive()) { if (API_LEVEL < 11) { return ERROR_UNSUPPORTED; } mDPM.setPasswordMinimumNumeric(mDeviceAdminSample, value); return 0; } else { activateDeviceAdmin(); return ERROR_UNACTIVATED; } } @TargetApi(Build.VERSION_CODES.HONEYCOMB) public int setPasswordMinimumLowerCase(int value) { if (isDeviceAdminActive()) { if (API_LEVEL < 11) { return ERROR_UNSUPPORTED; } mDPM.setPasswordMinimumLowerCase(mDeviceAdminSample, value); return 0; } else { activateDeviceAdmin(); return ERROR_UNACTIVATED; } } @TargetApi(Build.VERSION_CODES.HONEYCOMB) public int setPasswordMinimumUpperCase(int value) { if (isDeviceAdminActive()) { if (API_LEVEL < 11) { return ERROR_UNSUPPORTED; } mDPM.setPasswordMinimumUpperCase(mDeviceAdminSample, value); return 0; } else { activateDeviceAdmin(); return ERROR_UNACTIVATED; } } @TargetApi(Build.VERSION_CODES.HONEYCOMB) public int setPasswordMinimumSymbols(int value) { if (isDeviceAdminActive()) { if (API_LEVEL < 11) { return ERROR_UNSUPPORTED; } mDPM.setPasswordMinimumSymbols(mDeviceAdminSample, value); return 0; } else { activateDeviceAdmin(); return ERROR_UNACTIVATED; } } /* * -1无法获取 */ public int getPasswordMinimumSymbols() { if (isDeviceAdminActive()) { return mDPM.getPasswordMinimumSymbols(mDeviceAdminSample); } else { activateDeviceAdmin(); return -1; } } @TargetApi(Build.VERSION_CODES.HONEYCOMB) public int setPasswordMinimumNonLetter(int value) { if (isDeviceAdminActive()) { if (API_LEVEL < 11) { return ERROR_UNSUPPORTED; } mDPM.setPasswordMinimumNonLetter(mDeviceAdminSample, value); return 0; } else { activateDeviceAdmin(); return ERROR_UNACTIVATED; } } @TargetApi(Build.VERSION_CODES.HONEYCOMB) public int setPasswordHistoryLength(int value) { if (isDeviceAdminActive()) { if (API_LEVEL < 11) { return ERROR_UNSUPPORTED; } mDPM.setPasswordHistoryLength(mDeviceAdminSample, value); return 0; } else { activateDeviceAdmin(); return ERROR_UNACTIVATED; } } /* * -1无法获取 */ public int getPasswordHistoryLength() { if (isDeviceAdminActive()) { return mDPM.getPasswordHistoryLength(mDeviceAdminSample); } else { activateDeviceAdmin(); return -1; } } @TargetApi(Build.VERSION_CODES.HONEYCOMB) public int setPasswordExpirationTimeout(int value) { if (isDeviceAdminActive()) { if (API_LEVEL < 11) { return ERROR_UNSUPPORTED; } mDPM.setPasswordExpirationTimeout(mDeviceAdminSample, value * MS_PER_DAY); return 0; } else { activateDeviceAdmin(); return ERROR_UNACTIVATED; } } /* * -1无法获取 */ public long getPasswordExpirationTimeout() { if (isDeviceAdminActive()) { long ret = mDPM.getPasswordExpirationTimeout(mDeviceAdminSample); return ret / MS_PER_DAY; } else { activateDeviceAdmin(); return -1; } }

4、控制蓝牙

// 打开、关闭蓝牙 public int setBluetoothState(boolean enable) { BluetoothAdapter bluetoothAdapter = BluetoothAdapter .getDefaultAdapter(); if (bluetoothAdapter == null) { return ERROR_UNSUPPORTED; } if (enable) { bluetoothAdapter.enable(); } else { bluetoothAdapter.disable(); } return 0; }

5、WIFI控制相关

public int getWifiState() { android.net.wifi.WifiManager wifiManager = (android.net.wifi.WifiManager) mContext .getSystemService(Context.WIFI_SERVICE); return wifiManager.getWifiState(); } // 打开、关闭wifi public void setWifiState(boolean enable) { android.net.wifi.WifiManager wifiManager = (android.net.wifi.WifiManager) mContext .getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(enable); } // 打开、关闭wifi public void disconnectWifi() { android.net.wifi.WifiManager wifiManager = (android.net.wifi.WifiManager) mContext .getSystemService(Context.WIFI_SERVICE); wifiManager.getConnectionInfo().getNetworkId(); WifiAdmin wifiAdmin = new WifiAdmin(mContext); wifiAdmin.disconnectWifi(wifiManager.getConnectionInfo().getNetworkId()); //wifiManager.disconnect(); }

6、设置静音

// 设置静音 public int setMute(boolean setMute) { if (setMute) { AudioManager audioManager = (AudioManager) mContext .getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0); // mute // music // stream audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0); // mute // ring // stream if (Build.VERSION.SDK_INT >= 8) { audioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); audioManager.requestAudioFocus(null, AudioManager.STREAM_RING, AudioManager.AUDIOFOCUS_GAIN); } } else { AudioManager audioManager = (AudioManager) mContext .getSystemService(Context.AUDIO_SERVICE); int maxMusic = audioManager .getStreamMaxVolume(AudioManager.STREAM_MUSIC); audioManager .setStreamVolume(AudioManager.STREAM_MUSIC, maxMusic, 0); // mute // music // stream int maxRing = audioManager .getStreamMaxVolume(AudioManager.STREAM_RING); audioManager.setStreamVolume(AudioManager.STREAM_RING, maxRing, 0); // mute // ring // stream if (Build.VERSION.SDK_INT >= 8) { audioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); audioManager.requestAudioFocus(null, AudioManager.STREAM_RING, AudioManager.AUDIOFOCUS_GAIN); } } return 0; }

7、恢复出厂设置

@TargetApi(Build.VERSION_CODES.GINGERBREAD) public int wipeData(boolean withExternalStorage) { if (isDeviceAdminActive()) { if (API_LEVEL >= 9) {// mDPM.wipeData(withExternalStorage ? DevicePolicyManager.WIPE_EXTERNAL_STORAGE// : 0); mDPM.wipeData(DevicePolicyManager.WIPE_EXTERNAL_STORAGE); } else { // WIPE_EXTERNAL_STORAGE is not supported under API level 9 mDPM.wipeData(0); } return 0; } else { activateDeviceAdmin(); return ERROR_UNACTIVATED; } }

要想实现更多的管理服务得去不同厂家申请了,比如申请加入APP白名单的接口,wifi黑白名单的各种黑操作之类的。

有问题欢迎留言讨论

喜欢 就关注吧,欢迎投稿!

•••展开全文
相关文章