זיהוי מקרים שבהם משתמשים מצלמים צילומי מסך של המכשיר
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
איור 1. דוגמה להודעת טוסט שמוצגת על ידי המערכת כשהמשתמש מצלם צילום מסך של אפליקציה שתומכת ב-API לזיהוי צילומי מסך.
כדי ליצור חוויה סטנדרטית יותר לזיהוי צילומי מסך, ב-Android 14 מוצג API לזיהוי צילומי מסך ששומר על הפרטיות. ה-API הזה מאפשר לאפליקציות לרשום קריאות חוזרות על בסיס כל פעילות. הקריאות החוזרות האלה מופעלות, והמשתמש מקבל הודעה, כשהמשתמש מצלם צילום מסך בזמן שהפעילות הזו גלויה.
תרחישים נתמכים
ב-Android 14, ממשק ה-API של המערכת מזהה צילום מסך רק אם המשתמש מבצע שילוב ספציפי של לחיצות על לחצני החומרה. ממשק ה-API לא מזהה צילומי מסך שצולמו כשמריצים פקודות בדיקה שקשורות לצילומי מסך, כולל ADB, או בבדיקות מכשור שמצלמות את התוכן הנוכחי של המסך במכשיר.
שלבי ההטמעה
כדי להוסיף זיהוי של צילומי מסך, צריך להצהיר על הרשאת זמן ההתקנה החדשה DETECT_SCREEN_CAPTURE:
לאחר מכן, מבצעים את השלבים הבאים לכל פעילות באפליקציה שבה המשתמשים עשויים לצלם צילומי מסך:
כדי להטמיע קריאה חוזרת, מבטלים את ההגדרה של הפונקציה onScreenCapture(). ב-callback הזה, האפליקציה יכולה לבצע פעולות, כמו אזהרת משתמש אחר שמישהו צילם מסך של שיחה.
Kotlin
valscreenCaptureCallback=Activity.ScreenCaptureCallback{// Add logic to take action in your app.}
Java
finalActivity.ScreenCaptureCallbackscreenCaptureCallback=newActivity.ScreenCaptureCallback(){@OverridepublicvoidonScreenCaptured(){// Add logic to take action in your app.}};
בשיטה onStart() של הפעילות, רושמים את הקריאה החוזרת (callback) של צילום המסך.
Kotlin
overridefunonStart(){super.onStart()// Pass in the callback created in the previous step // and the intended callback executor (e.g. Activity's mainExecutor).registerScreenCaptureCallback(mainExecutor,screenCaptureCallback)}
Java
@OverrideprotectedvoidonStart(){super.onStart();// Pass in the callback created in the previous step // and the intended callback executor (e.g. Activity's mainExecutor).registerScreenCaptureCallback(executor,screenCaptureCallback);}
בשיטת הפעילות onStop(), מבטלים את הרישום של הקריאה החוזרת של צילום המסך:
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-08-27 (שעון UTC).
[null,null,["עדכון אחרון: 2025-08-27 (שעון UTC)."],[],[],null,["**Figure 1.** An example of the system-provided toast message that appears when the user takes a screenshot of an app that supports the screenshot detection API.\n\nTo create a more-standardized experience for detecting screenshots,\nAndroid 14 introduces a privacy-preserving screenshot detection\nAPI. This API lets apps register callbacks on a per-activity basis. These\ncallbacks are invoked, and the user is notified, when the user takes a\nscreenshot while that activity is visible.\n| **Note:** The callback doesn't provide an image of the actual screenshot. It's up to your app to determine what appeared on the screen when the user took a screenshot.\n\nSupported use cases\n\nIn Android 14, the system API only detects a screenshot if the user performs a\nspecific combination of hardware button presses. The API doesn't detect\nscreenshots that are taken when running test commands related to screenshots,\nincluding [ADB](/studio/command-line/adb), or within instrumentation tests that [capture the device's\ncurrent screen contents](/reference/androidx/test/core/app/DeviceCapture).\n\nImplementation steps\n\nTo add screenshot detection, declare the new [`DETECT_SCREEN_CAPTURE`](/reference/android/Manifest.permission#DETECT_SCREEN_CAPTURE)\ninstall-time permission: \n\n \u003cuses-permission android:name=\"android.permission.DETECT_SCREEN_CAPTURE\" /\u003e\n\nThen, complete these steps for each activity in your app where users might\ncapture screenshots:\n\n1. Implement a callback by overriding the `onScreenCapture()` function. In this\n callback, your app can take action, such as warning another user that\n someone took a screenshot of a messaging conversation.\n\n Kotlin \n\n ```kotlin\n val screenCaptureCallback = Activity.ScreenCaptureCallback {\n // Add logic to take action in your app.\n }\n ```\n\n Java \n\n ```java\n final Activity.ScreenCaptureCallback screenCaptureCallback =\n new Activity.ScreenCaptureCallback() {\n @Override\n public void onScreenCaptured() {\n // Add logic to take action in your app.\n }\n };\n ```\n2. In the activity's `onStart()` method, register the screenshot callback.\n\n **Note:** Given that a notice is shown with every screenshot detection signal, developers should provide in-context notices to the user when they are starting an activity that uses screenshot detection APIs so the system notice does not come as a surprise to users. \n\n Kotlin \n\n ```kotlin\n override fun onStart() {\n super.onStart()\n // Pass in the callback created in the previous step \n // and the intended callback executor (e.g. Activity's mainExecutor).\n registerScreenCaptureCallback(mainExecutor, screenCaptureCallback)\n }\n ```\n\n Java \n\n ```java\n @Override\n protected void onStart() {\n super.onStart();\n // Pass in the callback created in the previous step \n // and the intended callback executor (e.g. Activity's mainExecutor).\n registerScreenCaptureCallback(executor, screenCaptureCallback);\n }\n ```\n3. In the activity's `onStop()` method, unregister the screenshot callback:\n\n Kotlin \n\n ```kotlin\n override fun onStop() {\n super.onStop()\n unregisterScreenCaptureCallback(screenCaptureCallback)\n }\n ```\n\n Java \n\n ```java\n @Override\n protected void onStop() {\n super.onStop();\n unregisterScreenCaptureCallback(screenCaptureCallback);\n }\n ```\n\nControl ability to capture screenshots\n\nIf you don't want the contents of an app's activity to appear in screenshots, or\non non-secure displays, set the [`FLAG_SECURE`](/reference/android/view/Display#FLAG_SECURE) display flag.\n**Note:** To provide transparency and user control, consider adding a setting in your app that allows users to toggle this flag. \n\nKotlin \n\n```kotlin\nactivity.getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE)\n```\n\nJava \n\n```java\nactivity.getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);\n```"]]