我正在 C# 控制台应用程序中使用 Google 的 AndroidManagement API 构建一个 MDM 应用程序,并且我还为设备创建了一个具有默认值的策略。
我正在尝试创建一个应用程序策略以在设备上安装一个新的应用程序包,所有博客都建议在 JSON 中添加应用程序策略:
{
"applications": [
{
"packageName": "com.example",
"installType": "FORCE_INSTALLED",
"lockTaskAllowed": true,
"defaultPermissionPolicy": "GRANT"
},
{
"packageName": "example2",
"installType": "FORCE_INSTALLED",
"lockTaskAllowed": false,
"defaultPermissionPolicy": "GRANT"
},
{
"packageName": "example3",
"installType": "FORCE_INSTALLED",
"lockTaskAllowed": true,
"defaultPermissionPolicy": "GRANT"
}
],
"cameraDisabled": true,
"screenCaptureDisabled": true,
"adjustVolumeDisabled" : true
}
并创建了 Policy body 实例:
public static Google.Apis.AndroidManagement.v1.Data.Policy body = new Google.Apis.AndroidManagement.v1.Data.Policy();
Json 加载完美,但由于类型转换application policy lists
而无法保存。ApplicationPolicy
{
var appPolicy = JsonConvert.DeserializeObject<Rootobject>(File.ReadAllText(applicationPolicyJson));
policyBody.CameraDisabled = appPolicy.CameraDisabled;
policyBody.ScreenCaptureDisabled = appPolicy.ScreenCaptureDisabled;
policyBody.AdjustVolumeDisabled = appPolicy.AdjustVolumeDisabled;
policyBody.Applications = new List<ApplicationPolicy> {***appPolicy*** };
}
public class Rootobject
{
public Application[] Applications { get; set; }
public bool CameraDisabled { get; set; }
public bool ScreenCaptureDisabled { get; set; }
public bool AdjustVolumeDisabled { get; set; }
}
public class Application
{
public string PackageName { get; set; }
public string InstallType { get; set; }
public bool LockTaskAllowed { get; set; }
public string DefaultPermissionPolicy { get; set; }
}
我怎样才能做到这一点?
谢谢!