[英]Policy body to install an Application on the Managed device using AndroidManagement API
I'm building an MDM application using Google's AndroidManagement API in a C# Console application and I have created a policy for the device as well which has the default values. 我正在C#控制台应用程序中使用Google的AndroidManagement API构建MDM应用程序,我也为该设备创建了一个具有默认值的策略。
I'm trying to create an Application Policy to install a new app package on the device and all the blogs suggest to add the application policy in a JSON : 我正在尝试创建一个应用程序策略来在设备上安装新的应用程序包,并且所有博客都建议在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
}
And the Policy body instance is created : 并创建了Policy正文实例:
public static Google.Apis.AndroidManagement.v1.Data.Policy body = new Google.Apis.AndroidManagement.v1.Data.Policy();
Json loads perfectly but the application policy lists
cannot be saved into the ApplicationPolicy
because of type conversions. 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; }
}
How can I achieve this? 我怎样才能做到这一点?
Thanks! 谢谢!
When using the C# library you cannot "load" the JSON directly, the Patch method takes a Policy object that you need to build using C# semantics. 使用C#库时,无法直接“加载”JSON, Patch方法会使用需要使用C#语义构建的Policy对象。 It's the same for Java. Java也是如此。 On the other hand the Python library takes a dictionary which is easy to generate from a JSON. 另一方面,Python库使用一个易于从JSON生成的字典。
For C# this would look like: 对于C#,这看起来像:
using Google.Apis.AndroidManagement.v1.Data;
var policy = new Policy();
policy.CameraDisabled = true;
policy.ScreenCaptureDisabled = true;
policy.AdjustVolumeDisabled = true;
var app1 = new ApplicationPolicy();
app.PackageName = "com.android.chrome";
app.InstallType = "FORCE_INSTALLED";
app.LockTaskAllowed = true;
app.DefaultPermissionPolicy = "GRANT";
var app2 = new ApplicationPolicy();
app.PackageName = "com.example";
app.InstallType = "FORCE_INSTALLED";
policy.Applications = new List<ApplicationPolicy> {app1, app2};
Disclaimer: I'm not used to C#, so it's possible that this code doesn't compile, but hopefully that gives you the idea. 免责声明:我不习惯使用C#,所以这段代码可能无法编译,但希望这能让你有所了解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.