# RatingCompat

Artifact: [androidx.media:media](https://developer.android.com/jetpack/androidx/releases/media) [View Source](https://cs.android.com/search?q=file:android/support/v4/media/RatingCompat.java+class:android.support.v4.media.RatingCompat) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

*** ** * ** ***


```
public final class RatingCompat implements Parcelable
```

<br />

*** ** * ** ***

> [!CAUTION]
> **This class is deprecated.**   
>
> androidx.media is deprecated. Please migrate to [androidx.media3](https://developer.android.com/media/media3).

A class to encapsulate rating information used as content metadata. A rating is defined by its rating style (see `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_HEART()`, `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_THUMB_UP_DOWN()`, `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_3_STARS()`, `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_4_STARS()`, `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_5_STARS()` or `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_PERCENTAGE()`) and the actual rating value (which may be defined as "unrated"), both of which are defined when the rating instance is constructed through one of the factory methods.

## Summary

| ### Constants |
|---|---|
| `static final https://developer.android.com/reference/android/os/Parcelable.Creator.html<https://developer.android.com/reference/android/support/v4/media/RatingCompat>` | `https://developer.android.com/reference/android/support/v4/media/RatingCompat#CREATOR()` **This field is deprecated.** Deprecated in Java |
| `static final int` | `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_3_STARS() = 3` **This field is deprecated.** Deprecated in Java |
| `static final int` | `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_4_STARS() = 4` **This field is deprecated.** Deprecated in Java |
| `static final int` | `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_5_STARS() = 5` **This field is deprecated.** Deprecated in Java |
| `static final int` | `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_HEART() = 1` **This field is deprecated.** Deprecated in Java |
| `static final int` | `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_NONE() = 0` **This field is deprecated.** Deprecated in Java |
| `static final int` | `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_PERCENTAGE() = 6` **This field is deprecated.** Deprecated in Java |
| `static final int` | `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_THUMB_UP_DOWN() = 2` **This field is deprecated.** Deprecated in Java |

| ### Public methods |
|---|---|
| `int` | `[describeContents](https://developer.android.com/reference/android/support/v4/media/RatingCompat#describeContents())()` **This method is deprecated.** Deprecated in Java |
| `static https://developer.android.com/reference/android/support/v4/media/RatingCompat` | `[fromRating](https://developer.android.com/reference/android/support/v4/media/RatingCompat#fromRating(java.lang.Object))(https://developer.android.com/reference/java/lang/Object.html ratingObj)` **This method is deprecated.** Deprecated in Java |
| `float` | `[getPercentRating](https://developer.android.com/reference/android/support/v4/media/RatingCompat#getPercentRating())()` **This method is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/java/lang/Object.html` | `[getRating](https://developer.android.com/reference/android/support/v4/media/RatingCompat#getRating())()` **This method is deprecated.** Deprecated in Java |
| `int` | `[getRatingStyle](https://developer.android.com/reference/android/support/v4/media/RatingCompat#getRatingStyle())()` **This method is deprecated.** Deprecated in Java |
| `float` | `[getStarRating](https://developer.android.com/reference/android/support/v4/media/RatingCompat#getStarRating())()` **This method is deprecated.** Deprecated in Java |
| `boolean` | `[hasHeart](https://developer.android.com/reference/android/support/v4/media/RatingCompat#hasHeart())()` **This method is deprecated.** Deprecated in Java |
| `boolean` | `[isRated](https://developer.android.com/reference/android/support/v4/media/RatingCompat#isRated())()` **This method is deprecated.** Deprecated in Java |
| `boolean` | `[isThumbUp](https://developer.android.com/reference/android/support/v4/media/RatingCompat#isThumbUp())()` **This method is deprecated.** Deprecated in Java |
| `static https://developer.android.com/reference/android/support/v4/media/RatingCompat` | `[newHeartRating](https://developer.android.com/reference/android/support/v4/media/RatingCompat#newHeartRating(boolean))(boolean hasHeart)` **This method is deprecated.** Deprecated in Java |
| `static https://developer.android.com/reference/android/support/v4/media/RatingCompat` | `[newPercentageRating](https://developer.android.com/reference/android/support/v4/media/RatingCompat#newPercentageRating(float))(float percent)` **This method is deprecated.** Deprecated in Java |
| `static https://developer.android.com/reference/android/support/v4/media/RatingCompat` | `[newStarRating](https://developer.android.com/reference/android/support/v4/media/RatingCompat#newStarRating(int,float))(int starRatingStyle, float starRating)` **This method is deprecated.** Deprecated in Java |
| `static https://developer.android.com/reference/android/support/v4/media/RatingCompat` | `[newThumbRating](https://developer.android.com/reference/android/support/v4/media/RatingCompat#newThumbRating(boolean))(boolean thumbIsUp)` **This method is deprecated.** Deprecated in Java |
| `static https://developer.android.com/reference/android/support/v4/media/RatingCompat` | `[newUnratedRating](https://developer.android.com/reference/android/support/v4/media/RatingCompat#newUnratedRating(int))(int ratingStyle)` **This method is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/java/lang/String.html` | `[toString](https://developer.android.com/reference/android/support/v4/media/RatingCompat#toString())()` **This method is deprecated.** Deprecated in Java |
| `void` | `[writeToParcel](https://developer.android.com/reference/android/support/v4/media/RatingCompat#writeToParcel(android.os.Parcel,int))(https://developer.android.com/reference/android/os/Parcel.html dest, int flags)` **This method is deprecated.** Deprecated in Java |

### Inherited Constants

From [android.os.Parcelable](https://developer.android.com/reference/android/os/Parcelable.html) `static final int` `https://developer.android.com/reference/android/os/Parcelable.html#CONTENTS_FILE_DESCRIPTOR = 1`

**This field is deprecated.** Deprecated in Java
`static final int` `https://developer.android.com/reference/android/os/Parcelable.html#PARCELABLE_WRITE_RETURN_VALUE = 1`

**This field is deprecated.** Deprecated in Java

## Constants

### CREATOR

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static final Parcelable.Creator<RatingCompat> CREATOR
```

> [!CAUTION]
> **This field is deprecated.**   
> Deprecated in Java

### RATING_3_STARS

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static final int RATING_3_STARS = 3
```

> [!CAUTION]
> **This field is deprecated.**   
> Deprecated in Java

A rating style with 0 to 3 stars.

### RATING_4_STARS

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static final int RATING_4_STARS = 4
```

> [!CAUTION]
> **This field is deprecated.**   
> Deprecated in Java

A rating style with 0 to 4 stars.

### RATING_5_STARS

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static final int RATING_5_STARS = 5
```

> [!CAUTION]
> **This field is deprecated.**   
> Deprecated in Java

A rating style with 0 to 5 stars.

### RATING_HEART

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static final int RATING_HEART = 1
```

> [!CAUTION]
> **This field is deprecated.**   
> Deprecated in Java

A rating style with a single degree of rating, "heart" vs "no heart". Can be used to indicate the content referred to is a favorite (or not).

### RATING_NONE

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static final int RATING_NONE = 0
```

> [!CAUTION]
> **This field is deprecated.**   
> Deprecated in Java

Indicates a rating style is not supported. A Rating will never have this type, but can be used by other classes to indicate they do not support Rating.

### RATING_PERCENTAGE

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static final int RATING_PERCENTAGE = 6
```

> [!CAUTION]
> **This field is deprecated.**   
> Deprecated in Java

A rating style expressed as a percentage.

### RATING_THUMB_UP_DOWN

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static final int RATING_THUMB_UP_DOWN = 2
```

> [!CAUTION]
> **This field is deprecated.**   
> Deprecated in Java

A rating style for "thumb up" vs "thumb down".

## Public methods

### describeContents

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public int [describeContents](https://developer.android.com/reference/android/support/v4/media/RatingCompat#describeContents())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

### fromRating

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static RatingCompat [fromRating](https://developer.android.com/reference/android/support/v4/media/RatingCompat#fromRating(java.lang.Object))(Object ratingObj)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Creates an instance from a framework `https://developer.android.com/reference/android/media/Rating.html` object.

This method is only supported on API 19+.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/Object.html ratingObj` | A `https://developer.android.com/reference/android/media/Rating.html` object, or null if none. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/support/v4/media/RatingCompat` | An equivalent `https://developer.android.com/reference/android/support/v4/media/RatingCompat` object, or null if none. |

### getPercentRating

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public float [getPercentRating](https://developer.android.com/reference/android/support/v4/media/RatingCompat#getPercentRating())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Return the percentage-based rating value.

| Returns |
|---|---|
| `float` | a rating value greater or equal to 0.0f, or a negative value if the rating style is not percentage-based, or if it is unrated. |

### getRating

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public Object [getRating](https://developer.android.com/reference/android/support/v4/media/RatingCompat#getRating())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Gets the underlying framework `https://developer.android.com/reference/android/media/Rating.html` object.

This method is only supported on API 19+.

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/Object.html` | An equivalent `https://developer.android.com/reference/android/media/Rating.html` object, or null if none. |

### getRatingStyle

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public int [getRatingStyle](https://developer.android.com/reference/android/support/v4/media/RatingCompat#getRatingStyle())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Return the rating style.

| Returns |
|---|---|
| `int` | one of `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_HEART()`, `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_THUMB_UP_DOWN()`, `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_3_STARS()`, `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_4_STARS()`, `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_5_STARS()`, or `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_PERCENTAGE()`. |

### getStarRating

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public float [getStarRating](https://developer.android.com/reference/android/support/v4/media/RatingCompat#getStarRating())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Return the star-based rating value.

| Returns |
|---|---|
| `float` | a rating value greater or equal to 0.0f, or a negative value if the rating style is not star-based, or if it is unrated. |

### hasHeart

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public boolean [hasHeart](https://developer.android.com/reference/android/support/v4/media/RatingCompat#hasHeart())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Return whether the rating is "heart selected".

| Returns |
|---|---|
| `boolean` | true if the rating is "heart selected", false if the rating is "heart unselected", if the rating style is not `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_HEART()` or if it is unrated. |

### isRated

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public boolean [isRated](https://developer.android.com/reference/android/support/v4/media/RatingCompat#isRated())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Return whether there is a rating value available.

| Returns |
|---|---|
| `boolean` | true if the instance was not created with `https://developer.android.com/reference/android/support/v4/media/RatingCompat#newUnratedRating(int)`. |

### isThumbUp

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public boolean [isThumbUp](https://developer.android.com/reference/android/support/v4/media/RatingCompat#isThumbUp())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Return whether the rating is "thumb up".

| Returns |
|---|---|
| `boolean` | true if the rating is "thumb up", false if the rating is "thumb down", if the rating style is not `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_THUMB_UP_DOWN()` or if it is unrated. |

### newHeartRating

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static RatingCompat [newHeartRating](https://developer.android.com/reference/android/support/v4/media/RatingCompat#newHeartRating(boolean))(boolean hasHeart)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Return a Rating instance with a heart-based rating. Create and return a new Rating instance with a rating style of `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_HEART()`, and a heart-based rating.

| Parameters |
|---|---|
| `boolean hasHeart` | true for a "heart selected" rating, false for "heart unselected". |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/support/v4/media/RatingCompat` | a new Rating instance. |

### newPercentageRating

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static RatingCompat [newPercentageRating](https://developer.android.com/reference/android/support/v4/media/RatingCompat#newPercentageRating(float))(float percent)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Return a Rating instance with a percentage-based rating. Create and return a new Rating instance with a `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_PERCENTAGE()` rating style, and a rating of the given percentage.

| Parameters |
|---|---|
| `float percent` | the value of the rating |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/support/v4/media/RatingCompat` | null if the rating is out of range, a new Rating instance otherwise. |

### newStarRating

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static RatingCompat [newStarRating](https://developer.android.com/reference/android/support/v4/media/RatingCompat#newStarRating(int,float))(int starRatingStyle, float starRating)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Return a Rating instance with a star-based rating. Create and return a new Rating instance with one of the star-base rating styles and the given integer or fractional number of stars. Non integer values can for instance be used to represent an average rating value, which might not be an integer number of stars.

| Parameters |
|---|---|
| `int starRatingStyle` | one of `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_3_STARS()`, `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_4_STARS()`, `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_5_STARS()`. |
| `float starRating` | a number ranging from 0.0f to 3.0f, 4.0f or 5.0f according to the rating style. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/support/v4/media/RatingCompat` | null if the rating style is invalid, or the rating is out of range, a new Rating instance otherwise. |

### newThumbRating

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static RatingCompat [newThumbRating](https://developer.android.com/reference/android/support/v4/media/RatingCompat#newThumbRating(boolean))(boolean thumbIsUp)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Return a Rating instance with a thumb-based rating. Create and return a new Rating instance with a `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_THUMB_UP_DOWN()` rating style, and a "thumb up" or "thumb down" rating.

| Parameters |
|---|---|
| `boolean thumbIsUp` | true for a "thumb up" rating, false for "thumb down". |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/support/v4/media/RatingCompat` | a new Rating instance. |

### newUnratedRating

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static RatingCompat [newUnratedRating](https://developer.android.com/reference/android/support/v4/media/RatingCompat#newUnratedRating(int))(int ratingStyle)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Return a Rating instance with no rating. Create and return a new Rating instance with no rating known for the given rating style.

| Parameters |
|---|---|
| `int ratingStyle` | one of `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_HEART()`, `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_THUMB_UP_DOWN()`, `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_3_STARS()`, `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_4_STARS()`, `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_5_STARS()`, or `https://developer.android.com/reference/android/support/v4/media/RatingCompat#RATING_PERCENTAGE()`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/support/v4/media/RatingCompat` | null if an invalid rating style is passed, a new Rating instance otherwise. |

### toString

```
public String [toString](https://developer.android.com/reference/android/support/v4/media/RatingCompat#toString())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

### writeToParcel

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public void [writeToParcel](https://developer.android.com/reference/android/support/v4/media/RatingCompat#writeToParcel(android.os.Parcel,int))(Parcel dest, int flags)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java