Android 12 Developer Preview is here! Try it out, and give us your feedback!

FakeHost

public class FakeHost
extends Object

java.lang.Object
   ↳ com.google.android.libraries.car.app.testing.FakeHost


A fake that simulates the behavior of the host of a car app.

This fake allows sending a PendingIntent as if the user clicked on a notification action.

It will also perform expected host behaviors such as calling Screen.getTemplate() after AppManager.invalidate() is called.

Summary

Public methods

static FakeHost getFakeHost(TestCarContext testCarContext)

Returns the FakeHost that is associated with the provided TestCarContext.

void performNotificationActionClick(PendingIntent pendingIntent)

Sends the given pending intent as if the user clicked on a notification action.

Inherited methods

Public methods

getFakeHost

public static FakeHost getFakeHost (TestCarContext testCarContext)

Returns the FakeHost that is associated with the provided TestCarContext.

Parameters
testCarContext TestCarContext

Returns
FakeHost

performNotificationActionClick

public void performNotificationActionClick (PendingIntent pendingIntent)

Sends the given pending intent as if the user clicked on a notification action.

You can retrieve the sent Intent using:

   Shadows.shadowOf(TestCarContext.getCarContext()).getBroadcastIntents()
 

You can then test your BroadcastReceiver by calling BroadcastReceiver.onReceive(Context, Intent) with the Intent that was fired.

Parameters
pendingIntent PendingIntent