Condividi tramite


MediaStore.GetGeneration(Context, String) Method

Definition

Return the latest generation value for the given volume.

[Android.Runtime.Register("getGeneration", "(Landroid/content/Context;Ljava/lang/String;)J", "", ApiSince=30)]
public static long GetGeneration (Android.Content.Context context, string volumeName);
[<Android.Runtime.Register("getGeneration", "(Landroid/content/Context;Ljava/lang/String;)J", "", ApiSince=30)>]
static member GetGeneration : Android.Content.Context * string -> int64

Parameters

context
Context
volumeName
String

specific volume to obtain an generation value for. Must be one of the values returned from #getExternalVolumeNames(Context).

Returns

Attributes

Remarks

Return the latest generation value for the given volume.

Generation numbers are useful for apps that are attempting to quickly identify exactly which media items have been added or changed since a previous point in time. Generation numbers are monotonically increasing over time, and can be safely arithmetically compared.

Detecting media changes using generation numbers is more robust than using MediaColumns#DATE_ADDED or MediaColumns#DATE_MODIFIED, since those values may change in unexpected ways when apps use File#setLastModified(long) or when the system clock is set incorrectly.

Note that before comparing these detailed generation values, you should first confirm that the overall version hasn't changed by checking MediaStore#getVersion(Context, String), since that indicates when a more radical change has occurred. If the overall version changes, you should assume that generation numbers have been reset and perform a full synchronization pass.

Java documentation for android.provider.MediaStore.getGeneration(android.content.Context, java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to