[null,null,["最后更新时间 (UTC):2025-07-26。"],[],["To detect a work profile, utilize the `DevicePolicyManager` to check if the app is the profile owner using `isProfileOwnerApp(\"com.google.android.apps.work.clouddpc\")`. To determine if a device *has* a work profile, query for the intent `com.google.android.apps.work.clouddpc.ACTION_DETECT_WORK_PROFILE`. On Android 11+, check if any activity from `queryIntentActivities` has `isCrossProfileIntentForwarderActivity` set. Prior to Android 11, check if the activity name is `com.android.internal.app.ForwardIntentToManagedProfile`.\n"],null,["# Work profile detection\n\nThis guide illustrates how to detect a work profile on a device. It applies only\nto work profiles managed by the Android Device policy app.\n\nDetect if the app is running inside a work profile\n--------------------------------------------------\n\nThe following method checks if the calling app is running within a work profile\nmanaged by the Android Device Policy app. \n\n### Kotlin\n\n fun isInsideWorkProfile(): Boolean {\n val devicePolicyManager = getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager\n\n return devicePolicyManager.isProfileOwnerApp(\"com.google.android.apps.work.clouddpc\")\n }\n\n### Java\n\n boolean isInsideWorkProfile() {\n DevicePolicyManager devicePolicyManager = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);\n\n return devicePolicyManager.isProfileOwnerApp(\"com.google.android.apps.work.clouddpc\");\n }\n\nDetect if the device has a work profile\n---------------------------------------\n\nTo determine if a device has a work profile managed by the Android Device Policy\napp, use the following method. This can be called from any management mode. From\nan app in the *personal* profile, querying for the intent\n`com.google.android.apps.work.clouddpc.ACTION_DETECT_WORK_PROFILE` should\nresolve as a cross-profile intent if a work profile managed by the Android\nDevice Policy app exists. This method will only return `true` when called from\nthe *personal* profile of a device that has such a work profile.\n| **Note:** To determine if the app itself is running inside a work profile, use the method described in the previous section.\n\n### Android 11 and later:\n\n### Kotlin\n\n fun hasWorkProfile(): Boolean {\n val intent = Intent(\"com.google.android.apps.work.clouddpc.ACTION_DETECT_WORK_PROFILE\")\n val activities = context.packageManager.queryIntentActivities(intent, 0)\n return activities.any { it.isCrossProfileIntentForwarderActivity }\n }\n\n### Java\n\n boolean hasWorkProfile() {\n Intent intent = new Intent(\"com.google.android.apps.work.clouddpc.ACTION_DETECT_WORK_PROFILE\");\n List\u003cResolveInfo\u003e activities = context.getPackageManager().queryIntentActivities(intent, 0);\n return activities.stream()\n .anyMatch(\n (ResolveInfo resolveInfo) -\u003e {\n return resolveInfo.isCrossProfileIntentForwarderActivity();\n });\n }\n\n### Prior to Android 11:\n\n### Kotlin\n\n fun hasWorkProfile(): Boolean {\n val intent = Intent(\"com.google.android.apps.work.clouddpc.ACTION_DETECT_WORK_PROFILE\")\n val activities = context.packageManager.queryIntentActivities(intent, 0)\n return activities.any { it.activityInfo.name == \"com.android.internal.app.ForwardIntentToManagedProfile\" }\n }\n\n### Java\n\n boolean hasWorkProfile() {\n Intent intent = new Intent(\"com.google.android.apps.work.clouddpc.ACTION_DETECT_WORK_PROFILE\");\n List\u003cResolveInfo\u003e activities = context.getPackageManager().queryIntentActivities(intent, 0);\n return activities.stream()\n .anyMatch(\n (ResolveInfo resolveInfo) -\u003e {\n return resolveInfo.activityInfo.name.equals(\"com.android.internal.app.ForwardIntentToManagedProfile\");\n });\n }"]]