Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
In dieser Anleitung wird gezeigt, wie Sie ein Arbeitsprofil auf einem Gerät erkennen. Sie gilt nur für Arbeitsprofile, die über die Android Device Policy App verwaltet werden.
Erkennen, ob die App in einem Arbeitsprofil ausgeführt wird
Bei der folgenden Methode wird geprüft, ob die anrufende App in einem Arbeitsprofil ausgeführt wird, das von der Android Device Policy App verwaltet wird.
So können Sie feststellen, ob ein Gerät ein Arbeitsprofil hat, das von der Android Device Policy App verwaltet wird: Diese Funktion kann in jedem Verwaltungsmodus aufgerufen werden. Wenn Sie von einer App im privaten Profil eine Abfrage für den Intent com.google.android.apps.work.clouddpc.ACTION_DETECT_WORK_PROFILE stellen, sollte dieser als profilübergreifender Intent aufgelöst werden, wenn ein Arbeitsprofil vorhanden ist, das von der Android Device Policy App verwaltet wird. Diese Methode gibt nur dann true zurück, wenn sie über das private Profil eines Geräts mit einem solchen Arbeitsprofil aufgerufen wird.
[null,null,["Zuletzt aktualisiert: 2025-07-26 (UTC)."],[],["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 }"]]