Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Hướng dẫn này minh hoạ cách phát hiện hồ sơ công việc trên thiết bị. Chế độ này chỉ áp dụng cho các hồ sơ công việc do ứng dụng Android Device Policy quản lý.
Phát hiện xem ứng dụng có đang chạy trong hồ sơ công việc hay không
Phương thức sau đây sẽ kiểm tra xem ứng dụng gọi có đang chạy trong hồ sơ công việc do ứng dụng Android Device Policy quản lý hay không.
Phát hiện xem thiết bị có hồ sơ công việc hay không
Để xác định xem một thiết bị có hồ sơ công việc do ứng dụng Android Device Policy quản lý hay không, hãy sử dụng phương thức sau. Bạn có thể gọi phương thức này từ bất kỳ chế độ quản lý nào. Từ một ứng dụng trong hồ sơ cá nhân, việc truy vấn ý định com.google.android.apps.work.clouddpc.ACTION_DETECT_WORK_PROFILE sẽ phân giải dưới dạng ý định trên nhiều hồ sơ nếu có hồ sơ công việc do ứng dụng Android Device Policy quản lý. Phương thức này sẽ chỉ trả về true khi được gọi từ hồ sơ cá nhân của một thiết bị có hồ sơ công việc như vậy.
[null,null,["Cập nhật lần gần đây nhất: 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 }"]]