Google Play 企业版 iframe

借助 Google Play 企业版 iframe,您可以直接在 EMM 控制台中嵌入 Google Play 企业版,为客户提供统一的移动管理体验。

Google Play 企业版 iframe
图 1.显示“搜索应用”页面的 Google Play 企业版 iframe。

iframe 包含一个标题栏和一个可展开的侧边菜单。用户可通过该菜单导航到不同的页面:

  • 搜索应用:允许 IT 管理员搜索和浏览 Google Play 应用、查看应用详情以及选择应用。
  • 专用应用:允许 IT 管理员发布和管理企业专用应用。
  • Web 应用:允许 IT 管理员以应用的形式发布和分发网站快捷方式。
  • 整理应用:允许 IT 管理员配置应用在用户设备上的 Play 商店应用中的整理方式。

默认情况下,所有网页都会在 iframe 中启用,但您可以单独停用(请参阅将 iframe 添加到控制台)。


特性

本部分介绍了 Google Play 企业版 iframe 中提供的功能。 如需了解如何嵌入 iframe 并实现这些功能,请参阅将 iframe 添加到控制台


将 iframe 添加到您的控制台

第 1 步:生成网络令牌

如需生成用于标识企业的网络令牌,请调用 Enterprises.createWebToken。以下示例展示了如何使用 Java 版 Google Play EMM API 客户端库检索令牌。

iframe 中的所有网页在默认情况下均处于启用状态。生成网络令牌时,您可以指定要停用的页面。以下示例会停用专用应用、Web 应用和整理应用。

public AdministratorWebToken getAdministratorWebToken(
        String enterpriseId) throws IOException {
    AdministratorWebTokenSpec tokenSpec = new AdministratorWebTokenSpec();
    tokenSpec.setParent("https://my-emm-console.com");
    tokenSpec.setPlaySearch(new AdministratorWebTokenSpecPlaySearch());
    tokenSpec.setPrivateApps(new AdministratorWebTokenSpecPrivateApps().setEnabled(false));
    tokenSpec.setWebApps(new AdministratorWebTokenSpecWebApps().setEnabled(false));
    tokenSpec.setStoreBuilder(new AdministratorWebTokenSpecStoreBuilder().setEnabled(false));
    return androidEnterprise
        .enterprise()
        .createWebToken(enterpriseId, tokenSpec)
        .execute();
}

在控制台中呈现 iframe 时,您需要添加返回的令牌以及其他参数。

第 2 步:呈现 iframe

以下示例展示了如何呈现 Google Play 企业版 iframe:

<script src="https://apis.google.com/js/api.js"></script>
<div id="container"></div>
<script>
  gapi.load('gapi.iframes', function() {
    var options = {
      'url': 'https://play.google.com/work/embedded/search?token=web_token&mode=SELECT',
      'where': document.getElementById('container'),
      'attributes': { style: 'width: 600px; height:1000px', scrolling: 'yes'}
    }

    var iframe = gapi.iframes.getContext().openChild(options);
  });
</script>

此代码会在容器 div 内生成一个 iframe。如上所述,可以使用“attributes”选项设置要应用于 iframe 代码的属性。

网址参数

下表列出了可作为网址参数添加到网址中的所有 iframe 参数,例如:

'url': 'https://play.google.com/work/embedded/search?token=web_token&mode=SELECT&showsearchbox=TRUE',
参数 网页 必需 说明
token N/A 第 1 步返回的令牌。
iframehomepage N/A 不支持 呈现 iframe 时显示的初始页面。可能的值包括 PLAY_SEARCHWEB_APPSPRIVATE_APPSSTORE_BUILDER(整理应用)。如果未指定,则按照以下优先顺序确定显示哪个页面:1. PLAY_SEARCH、2. PRIVATE_APPS、3. WEB_APPS、4. STORE_BUILDER.
locale N/A 不支持 一个格式正确的 BCP 47 语言标记,用于在 iframe 中本地化内容。如果未指定,则默认值为 en_US
mode 搜索应用 不支持 SELECT:允许 IT 管理员选择应用。
APPROVE(默认):允许 IT 管理员选择、批准和取消批准应用。
showsearchbox 搜索应用 不支持 TRUE(默认):显示搜索框,并从 iframe 中发起搜索查询。
FALSE: 不会显示搜索框。
search 搜索应用 不支持 搜索字符串。如果已指定,iframe 会将 IT 管理员定向到包含指定字符串的搜索结果。

第 3 步:处理 iframe 事件

您还应该在集成过程中处理以下事件。

事件说明
onproductselect 用户选择或批准应用。这会返回一个包含以下内容的对象:
{
    "packageName": The package name of the app, e.g. "com.google.android.gm",
    "productId": The product ID of the app, e.g. "app:com.google.android.gm",
    "action": The type of action performed on the document. Possible values are:
    "approved", "unapproved" or "selected." If you implement the iframe in SELECT
    mode, the only possible value is "selected".
}
    
以下示例展示了如何监听 onproductselect
iframe.register('onproductselect', function(event) {
  console.log(event);
}, gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER);