Google Play 管理版 iframe

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

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。如上所述,您可以透過「attributes」選項設定要套用至 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 管理員選取、核准及取消核准應用程式。
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);