androidandroid-for-work

Google EMM API troubles


Good day! I have interest in Google Play EMM

I have created Device Policy Controller and created Work Profile. Created a Google Developers Console project and added EMM API. Created master service account. In master service account I obtained EMM token.

I have downloaded Google Play EMM API Client Library for Java. As I know, I just need to call something like

Enterprise enterprise = new Enterprise();
enterprise.setPrimaryDomain(primaryDomainName);
Enterprise result = androidEnterprise.enterprises()
   .enroll(authenticationToken, enterprise).execute();

EnterpriseAccount enterpriseAccount = new EnterpriseAccount();
enterpriseAccount.setAccountEmail(serviceAccountEmail);
androidEnterprise.enterprises().setAccount(result.getId(),
enterpriseAccount).execute();

First question - how do I add device(android phone) to master service account grammatically? If i was using Google Android for Work and Google system by default - i would use "Device Enrollment" application. But I have no idea how to do this in programming way.

Second one - in the sample there are such lines

// Optional: you might want to store the bound enterprise's info, but
// these details can always be retrieved with an Enterprises.List call.

Where do they store ? At Google servers? Am I right when I think that when I do enterprise.setPrimaryDomain(primaryDomainName); I get access to all enrolled customers?

Third - is there any NORMAL samples ? Or step by step howto? There is not a lot of information about all this after all ( Thank you.


Solution

  • Still You have same issue? Please let me know i think i can help you for enroll.

    Change request like this:

    Enterprise enterprise = new Enterprise();
    enterprise.setPrimaryDomain(primaryDomainName);
    enterprise.setId("Unique_EMM_ID"); //Which you will get from Google in mail
    enterprise.setKind("androidenterprise#enterprise");
    
    try{
    
          AndroidEnterprise.Enterprises.Enroll enroll = androidEnterprise.enterprises().enroll(authenticationToken, enterprise);
          enroll.setToken(token);
    
          Enterprise result = enroll.execute();
    
          EnterpriseAccount enterpriseAccount = new EnterpriseAccount();
          enterpriseAccount.setKind("androidenterprise#enterpriseAccount");
          enterpriseAccount.setAccountEmail(serviceAccountEmail);
    
          androidEnterprise.enterprises().setAccount(result.getId(), enterpriseAccount).execute();
    
       } catch (Exception e) {
            e.printStackTrace();
       }
    

    Try like this. I hope this will help you.