Google Play 管理版 iframe

透過 Google Play 管理版 iframe,您可以在 EMM 控制台中直接嵌入 Google Play 管理版,為客戶提供整合式行動管理體驗。

Google Play 管理版 iframe
圖 1.Google Play 管理版 iframe 顯示「搜尋應用程式」頁面。

iframe 包含標題列和可展開的側邊選單。使用者可以透過選單前往不同頁面:

  • 搜尋應用程式:允許 IT 管理員搜尋及瀏覽 Google Play 應用程式、查看應用程式詳細資料及選取應用程式。
  • 私人應用程式:允許 IT 管理員發布及管理所屬企業的私人應用程式。
  • 網頁應用程式:允許 IT 管理員以應用程式的形式發布及發布網站捷徑。
  • 整理應用程式:允許 IT 管理員設定如何在使用者裝置上的 Play 商店應用程式中整理應用程式。

所有頁面都會預設為在 iframe 中啟用,但您也可以個別停用 (請參閱「在主控台中新增 iframe」一節)。


功能與特色

本節將說明 Google Play 管理版 iframe 的功能。如要瞭解如何嵌入 iframe 並實作這些功能,請參閱「將 iframe 新增至主控台」一文。


在控制台中新增 iframe

步驟 1:產生網路權杖

如要產生用於識別企業的網頁權杖,請呼叫 Enterprises.createWebToken。下列範例說明如何使用 Java 適用的 Google Play EMM API 用戶端程式庫擷取權杖。

iframe 中的所有網頁都會預設為啟用。產生網路權杖時,您可以指定要停用的頁面。以下範例會停用私人應用程式、網頁應用程式和整理應用程式。

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。如上所述,您可以使用「屬性」選項設定要套用至 iframe 標記的屬性。

網址參數

下表列出 iframe 的所有可用參數,可加入網址中做為網址參數,例如:

'url': 'https://play.google.com/work/embedded/search?token=web_token&mode=SELECT&showsearchbox=TRUE',
參數 頁面 需要 說明
token 不適用 步驟 1 傳回的權杖。
iframehomepage 不適用 iframe 轉譯後顯示的起始頁面。可能的值包括 PLAY_SEARCHWEB_APPSPRIVATE_APPSSTORE_BUILDER (整理應用程式)。如未指定,系統會依下列優先順序決定要顯示的網頁:1. PLAY_SEARCH,2. PRIVATE_APPS、3.WEB_APPS,4. STORE_BUILDER.
locale 不適用 使用格式正確的 BCP 47 語言標記,將 iframe 中的內容本地化。如未指定,則預設值為 en_US
mode 搜尋應用程式 SELECT:讓 IT 管理員能夠選取應用程式。
APPROVE (預設):IT 管理員可選取、核准及取消核准應用程式。這個模式已淘汰,請改用 SELECT。只有當網頁權杖中的 PlaySearch.ApproveApps 設為 true 時,核准模式才能正常運作。
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);