跳转到正文

Android 配置

GitHub

在应用项目的根目录 android/build.gradle中,将 Intune Gradle 插件 JAR 添加到 buildscript classpath。该插件包包含:

  • android/ms-intune-app-sdk-android/GradlePlugin/com.microsoft.intune.mam.build.jar

同时,请包含 Ionic 文档中针对当前 Intune Android SDK 版本所要求的 Duo Maven feed:

maven {
url 'https://pkgs.dev.azure.com/MicrosoftDeviceSDK/DuoSDK-Public/_packaging/Duo-SDK-Feed/maven/v1'
name 'Duo-SDK-Feed'
}

在 android/app/build.gradle:

apply plugin: 'com.microsoft.intune.mam'

并保持禁用资源优化:

android.enableResourceOptimizations=false

创建 android/app/src/main/res/raw/auth_config.json:

{
"client_id": "YOUR_CLIENT_ID",
"authorization_user_agent": "BROWSER",
"redirect_uri": "msauth://YOUR_PACKAGE/YOUR_SIGNATURE_HASH",
"broker_redirect_uri_registered": true,
"account_mode": "MULTIPLE",
"authorities": [
{
"type": "AAD",
"audience": {
"type": "AzureADMyOrg"
}
}
]
}

该插件在运行时需要该文件,以支持 MSAL 和 Intune 认证回调。

如果你的应用尚未定义自定义 Application,请设置:

<application
android:name="app.capgo.intune.IntuneApplication"
android:enableOnBackInvokedCallback="false">

如果你已经有自定义 Application,请扩展 MAMApplication 并注册 IntuneMamServiceAuthenticationCallback 中的 onMAMCreate().

添加 Ionic 文档中针对以下内容提供的包可见性查询:

  • com.azure.authenticator
  • com.microsoft.windowsintune.companyportal
  • 浏览器检测 Intent

同时添加 BrowserTabActivity 使用你的 msauth:// 重定向 URI 主机/路径,以便 MSAL 完成登录往返流程。

应用层原生配置完成后,Capacitor API 的用法与 iOS 端一致:

import { IntuneMAM } from '@capgo/capacitor-intune';
const auth = await IntuneMAM.acquireToken({
scopes: ['https://graph.microsoft.com/.default'],
});
await IntuneMAM.registerAndEnrollAccount({
accountId: auth.accountId,
});

如果你正在使用 Android 配置 要规划原生插件工作,请将其与 使用 @capgo/capacitor-intune 用于“使用 @capgo/capacitor-intune”中的原生能力, Capgo 插件目录 查看 Capgo 插件目录中的产品工作流, Capgo 提供的 Capacitor 插件 查看由 Capgo 提供的 Capacitor 插件中的实现细节, 添加或更新插件 关于“添加或更新插件”中的实现细节,以及 Ionic Enterprise 插件替代方案 关于“Ionic Enterprise 插件替代方案”中的产品工作流。