`
bogongjie
  • 浏览: 236038 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

android setting 設置<二>

阅读更多

Setting中某些項的設置:

  1.Device administrators.

2.Accessibility SERVICES.

   在設置Device administrators中用到的setActiveAdmin方法已經隱藏了,需要另行編繹.

 

 

public void setDevice(){
		List<ResolveInfo> avail = this.getPackageManager().queryBroadcastReceivers(
				new Intent(DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED),
                PackageManager.GET_META_DATA);
        int count = avail == null ? 0 : avail.size();
        for (int i=0; i<count; i++) {
            ResolveInfo ri = avail.get(i);
            try {
                DeviceAdminInfo dpi = new DeviceAdminInfo(this, ri);
                if (dpi.isVisible() || mActiveAdmins.contains(dpi.getComponent())) {
                    mAvailableAdmins.add(dpi);
                }
            } catch (XmlPullParserException e) {
                Log.w(TAG, "Skipping " + ri.activityInfo, e);
            } catch (IOException e) {
                Log.w(TAG, "Skipping " + ri.activityInfo, e);
            }
        }
        DevicePolicyManager devicePolicyManager = (DevicePolicyManager)getSystemService(DEVICE_POLICY_SERVICE);
        for (int i = 0; i < mAvailableAdmins.size(); i++) {
			ComponentName componentName = mAvailableAdmins.get(i).getComponent();
			devicePolicyManager.setActiveAdmin(componentName,true);
		}
	}
	public void SetAccessibility(){
		AccessibilityManager accessibilityManager =(AccessibilityManager) getSystemService(Service.ACCESSIBILITY_SERVICE);
        List<ServiceInfo> installedServices = accessibilityManager.getAccessibilityServiceList();
//        Log.i("Accessibility Test","The ServiceInfo size is: "+String.valueOf(installedServices.size()));
        for (int i = 0; i < installedServices.size(); i++) {
        	ServiceInfo serviceInfo = installedServices.get(i);
            Settings.Secure.putInt(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 1);
    		Settings.Secure.putString(getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, serviceInfo.packageName + "/" + serviceInfo.name);
    		Settings.Secure.putInt(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 1);
		}
	}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics