Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Hinweis zur Einstellung: Kontextsignale für Orte und Wetter
Mit der Snapshot API können Sie Informationen zur aktuellen Umgebung des Nutzers abrufen. Mit der Snapshot API können Sie auf eine Vielzahl von Kontextsignalen zugreifen:
Erkannte Nutzeraktivitäten, z. B. wenn sie gehen oder fahren.
Beacons in der Nähe, die Sie registriert haben.
Status der Kopfhörer, ob sie angeschlossen sind oder nicht.
Standort, einschließlich Breiten- und Längengrad
Das System speichert diese Werte im Cache, damit sie schnell zurückgegeben werden können. Wenn keine Daten vorhanden sind, werden Sensoren und Inferenzen verwendet, um aktuelle Statuswerte zurückzugeben.
Die Awareness API gibt den vorhandenen Datentyp für Kontexttypen zurück, die eine öffentliche API haben.
Für jedes Kontextsignal gibt es eine entsprechende Snapshot API-Methode. Wenn Sie beispielsweise die aktuell erkannte Aktivität abrufen möchten, rufen Sie getDetectedActivity() auf, verwenden ein SuccessListener, um ein DetectedActivityResponse abzurufen, und rufen dann getActivityRecognitionResult() auf, um ein ActivityRecognitionResult zurückzugeben, aus dem Sie die tatsächlichen Anfragedaten abrufen können.
Im folgenden Beispiel wird gezeigt, wie Sie die zuletzt erkannte Aktivität abrufen:
[null,null,["Zuletzt aktualisiert: 2025-08-31 (UTC)."],[[["\u003cp\u003eThe Places and Weather contextual signals within the Awareness API are deprecated and have been turned off, with existing implementations restricted until specified dates.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers should utilize the Places SDK for Android instead of the Places contextual signal for new implementations.\u003c/p\u003e\n"],["\u003cp\u003eGoogle does not offer alternative functionality for the Weather contextual signal, impacting existing implementations relying on it.\u003c/p\u003e\n"],["\u003cp\u003eThe Awareness API continues to provide other contextual signals through the Snapshot API, including user activity, nearby beacons, headphone state, and location.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can access these signals using corresponding Snapshot API methods and retrieve relevant data for their applications.\u003c/p\u003e\n"]]],[],null,["# Snapshot API overview\n\n**Deprecation notice: Places and Weather contextual signals** **Warning:**\n| The Places and Weather contextual signals, exposed by the\n| [`getPlaces()`](/android/reference/com/google/android/gms/awareness/SnapshotClient#getPlaces()), and\n| [`getWeather()`](/android/reference/com/google/android/gms/awareness/SnapshotClient#getWeather())\n| methods, were deprecated.\n|\n| - The Places contextual signal was turned off. Continued use of this signal was restricted to customers with existing implementations, through October 30, 2019. New implementations must use the [Places SDK for Android](/places/android-sdk) instead of the Places contextual signal.\n| - The Weather contextual signal has also been turned off. Continued use of this signal has been restricted to customers with existing implementations, through January 31, 2020. Google doesn't offer alternative functionality for the Weather contextual signal.\n\nYou can use the [Snapshot API](/android/reference/com/google/android/gms/awareness/Awareness#getSnapshotClient(android.app.Activity))\nto get information about the user's current environment. With the Snapshot API,\nyou can access a variety of [context signals](/awareness/overview#context-types):\n\n- Detected user activity, such as when they walk or drive.\n- Nearby beacons that you've registered.\n- Headphone state, plugged in or not.\n- Location, which includes latitude and longitude.\n\nThe system caches these values so that they can be returned quickly. If there's\nno data, sensing and inference are performed to return fresh state values.\nThe Awareness API returns the existing data type for context types that have a\npublic API.\n\nEach context signal has a corresponding Snapshot API method. For example, to\nget the current detected activity, you call\n[`getDetectedActivity()`](/android/reference/com/google/android/gms/awareness/SnapshotClient#getDetectedActivity()),\nuse a `SuccessListener` to get a [`DetectedActivityResponse`](/android/reference/com/google/android/gms/awareness/snapshot/DetectedActivityResponse),\nthen call [`getActivityRecognitionResult()`](/android/reference/com/google/android/gms/awareness/snapshot/DetectedActivityResponse#getActivityRecognitionResult())\nto return an [`ActivityRecognitionResult`](/android/reference/com/google/android/gms/location/ActivityRecognitionResult)\nfrom which you can get the actual request data.\n\nThe following example shows how to get the latest detected activity: \n\n Awareness.getSnapshotClient(this).getDetectedActivity()\n .addOnSuccessListener(new OnSuccessListener\u003cDetectedActivityResponse\u003e() {\n @Override\n public void onSuccess(DetectedActivityResponse dar) {\n ActivityRecognitionResult arr = dar.getActivityRecognitionResult();\n }\n })\n\nFor more information about what you can do with the request data, see\n[Get Snapshot data](/awareness/android-api/snapshot-get-data)."]]