@Implements(value=android.app.Application.class) public class ShadowApplication extends ShadowContextWrapper
Modifier and Type | Class and Description |
---|---|
static class |
ShadowApplication.Wrapper |
Constructor and Description |
---|
ShadowApplication() |
Modifier and Type | Method and Description |
---|---|
void |
addWakeLock(android.os.PowerManager.WakeLock wl) |
void |
assertNoBroadcastListenersOfActionRegistered(android.content.ContextWrapper context,
java.lang.String action) |
boolean |
bindService(android.content.Intent intent,
android.content.ServiceConnection serviceConnection,
int i) |
void |
callAttach(android.content.Context context)
Attaches an application to a base context.
|
void |
checkActivities(boolean checkActivities)
Set to true if you’d like Robolectric to strictly simulate the real Android behavior when calling
Context.startActivity(android.content.Intent) . |
int |
checkPermission(java.lang.String permission,
int pid,
int uid) |
void |
clearStartedServices()
Clears all
Intent started by startService(android.content.Intent) |
void |
clearWakeLocks() |
void |
declareActionUnbindable(java.lang.String action) |
void |
denyPermissions(java.lang.String... permissionNames) |
android.content.Context |
getApplicationContext() |
android.appwidget.AppWidgetManager |
getAppWidgetManager() |
Scheduler |
getBackgroundThreadScheduler()
Return the background scheduler.
|
java.lang.Object |
getBluetoothAdapter() |
java.util.List<android.content.ServiceConnection> |
getBoundServiceConnections() |
java.util.List<android.content.Intent> |
getBroadcastIntents() |
Scheduler |
getForegroundThreadScheduler()
Return the foreground scheduler.
|
static ShadowApplication |
getInstance() |
ShadowAlertDialog |
getLatestAlertDialog() |
ShadowDialog |
getLatestDialog() |
android.widget.ListPopupWindow |
getLatestListPopupWindow() |
ShadowPopupMenu |
getLatestPopupMenu() |
android.widget.PopupWindow |
getLatestPopupWindow() |
android.os.PowerManager.WakeLock |
getLatestWakeLock() |
android.view.LayoutInflater |
getLayoutInflater() |
android.content.Intent |
getNextStartedService()
Consumes the most recent
Intent started by startService(android.content.Intent) and returns it. |
android.content.Intent |
getNextStoppedService()
Consumes the
Intent requested to stop a service by stopService(android.content.Intent) from the bottom of the stack of stop requests. |
java.util.List<android.content.BroadcastReceiver> |
getReceiversForIntent(android.content.Intent intent)
Deprecated.
use PackageManager.queryBroadcastReceivers instead
|
java.util.List<ShadowApplication.Wrapper> |
getRegisteredReceivers() |
java.util.List<android.widget.Toast> |
getShownToasts() |
<T> T |
getSingleton(java.lang.Class<T> clazz,
Provider<T> provider) |
java.util.List<android.content.ServiceConnection> |
getUnboundServiceConnections() |
void |
grantPermissions(java.lang.String... permissionNames) |
boolean |
hasReceiverForIntent(android.content.Intent intent)
Deprecated.
use PackageManager.queryBroadcastReceivers instead
|
android.content.Intent |
peekNextStartedService()
Returns the most recent
Intent started by startService(android.content.Intent) without consuming it. |
android.content.Intent |
registerReceiver(android.content.BroadcastReceiver receiver,
android.content.IntentFilter filter)
Always returns
null |
android.content.Intent |
registerReceiver(android.content.BroadcastReceiver receiver,
android.content.IntentFilter filter,
java.lang.String broadcastPermission,
android.os.Handler scheduler) |
static void |
runBackgroundTasks()
Runs any background tasks previously queued by
AsyncTask.execute(Object[]) . |
void |
sendBroadcast(android.content.Intent intent) |
void |
sendBroadcast(android.content.Intent intent,
java.lang.String receiverPermission) |
void |
sendOrderedBroadcast(android.content.Intent intent,
java.lang.String receiverPermission) |
void |
sendOrderedBroadcast(android.content.Intent intent,
java.lang.String receiverPermission,
android.content.BroadcastReceiver resultReceiver,
android.os.Handler scheduler,
int initialCode,
java.lang.String initialData,
android.os.Bundle initialExtras) |
void |
sendStickyBroadcast(android.content.Intent intent) |
void |
setComponentNameAndServiceForBindService(android.content.ComponentName name,
android.os.IBinder service) |
void |
setComponentNameAndServiceForBindServiceForIntent(android.content.Intent intent,
android.content.ComponentName name,
android.os.IBinder service) |
static void |
setDefaultDisplay(android.view.Display display)
Deprecated.
Set up display using
Config.qualifiers() instead. |
static void |
setDisplayMetricsDensity(float densityMultiplier)
Deprecated.
Set screen density using
Config.qualifiers() instead. |
void |
setLatestAlertDialog(ShadowAlertDialog latestAlertDialog) |
void |
setLatestDialog(ShadowDialog latestDialog) |
void |
setLatestListPopupWindow(android.widget.ListPopupWindow latestListPopupWindow) |
void |
setLatestPopupMenu(ShadowPopupMenu latestPopupMenu) |
void |
setLatestPopupWindow(android.widget.PopupWindow latestPopupWindow) |
void |
setSystemService(java.lang.String key,
java.lang.Object service)
Deprecated.
Do not depend on this method to override services as it will be removed in a future update. The preferered method is use the shadow of the corresponding service.
|
void |
setUnbindServiceShouldThrowIllegalArgument(boolean flag) |
android.content.ComponentName |
startService(android.content.Intent intent) |
boolean |
stopService(android.content.Intent name) |
void |
unbindService(android.content.ServiceConnection serviceConnection) |
void |
unregisterReceiver(android.content.BroadcastReceiver broadcastReceiver) |
getNextStartedActivity, peekNextStartedActivity
public static ShadowApplication getInstance()
public static void runBackgroundTasks()
Runs any background tasks previously queued by AsyncTask.execute(Object[])
.
Note: calling this method does not pause or un-pause the scheduler.
@Deprecated public static void setDisplayMetricsDensity(float densityMultiplier)
Config.qualifiers()
instead.@Deprecated public static void setDefaultDisplay(android.view.Display display)
Config.qualifiers()
instead.public void callAttach(android.content.Context context)
Attaches an application to a base context.
application
- The application to attach.context
- The context with which to initialize the application, whose base context will be attached to the applicationpublic java.util.List<android.widget.Toast> getShownToasts()
public Scheduler getForegroundThreadScheduler()
Return the foreground scheduler.
public Scheduler getBackgroundThreadScheduler()
Return the background scheduler.
@Implementation public android.content.Context getApplicationContext()
@Implementation public android.content.ComponentName startService(android.content.Intent intent)
@Implementation public boolean stopService(android.content.Intent name)
public void setComponentNameAndServiceForBindService(android.content.ComponentName name, android.os.IBinder service)
public void setComponentNameAndServiceForBindServiceForIntent(android.content.Intent intent, android.content.ComponentName name, android.os.IBinder service)
@Implementation public boolean bindService(android.content.Intent intent, android.content.ServiceConnection serviceConnection, int i)
public java.util.List<android.content.ServiceConnection> getBoundServiceConnections()
public void setUnbindServiceShouldThrowIllegalArgument(boolean flag)
@Implementation public void unbindService(android.content.ServiceConnection serviceConnection)
public java.util.List<android.content.ServiceConnection> getUnboundServiceConnections()
public android.content.Intent getNextStartedService()
Consumes the most recent Intent
started by startService(android.content.Intent)
and returns it.
getNextStartedService
in class ShadowContextWrapper
Intent
public android.content.Intent peekNextStartedService()
Returns the most recent Intent
started by startService(android.content.Intent)
without consuming it.
peekNextStartedService
in class ShadowContextWrapper
Intent
public void clearStartedServices()
Clears all Intent
started by startService(android.content.Intent)
clearStartedServices
in class ShadowContextWrapper
public android.content.Intent getNextStoppedService()
Consumes the Intent
requested to stop a service by stopService(android.content.Intent)
from the bottom of the stack of stop requests.
getNextStoppedService
in class ShadowContextWrapper
Intent
for the next service requested to be stopped@Implementation public void sendBroadcast(android.content.Intent intent)
@Implementation public void sendBroadcast(android.content.Intent intent, java.lang.String receiverPermission)
@Implementation public void sendOrderedBroadcast(android.content.Intent intent, java.lang.String receiverPermission)
@Implementation public void sendOrderedBroadcast(android.content.Intent intent, java.lang.String receiverPermission, android.content.BroadcastReceiver resultReceiver, android.os.Handler scheduler, int initialCode, java.lang.String initialData, android.os.Bundle initialExtras)
public java.util.List<android.content.Intent> getBroadcastIntents()
getBroadcastIntents
in class ShadowContextWrapper
@Implementation public void sendStickyBroadcast(android.content.Intent intent)
@Implementation public android.content.Intent registerReceiver(android.content.BroadcastReceiver receiver, android.content.IntentFilter filter)
Always returns null
null
@Implementation public android.content.Intent registerReceiver(android.content.BroadcastReceiver receiver, android.content.IntentFilter filter, java.lang.String broadcastPermission, android.os.Handler scheduler)
@Implementation public void unregisterReceiver(android.content.BroadcastReceiver broadcastReceiver)
public void assertNoBroadcastListenersOfActionRegistered(android.content.ContextWrapper context, java.lang.String action)
@Deprecated public boolean hasReceiverForIntent(android.content.Intent intent)
@Deprecated public java.util.List<android.content.BroadcastReceiver> getReceiversForIntent(android.content.Intent intent)
public java.util.List<ShadowApplication.Wrapper> getRegisteredReceivers()
ShadowApplication.Wrapper
s for registered receiverspublic android.view.LayoutInflater getLayoutInflater()
Application
public android.appwidget.AppWidgetManager getAppWidgetManager()
Application
public ShadowAlertDialog getLatestAlertDialog()
public void setLatestAlertDialog(ShadowAlertDialog latestAlertDialog)
public ShadowDialog getLatestDialog()
public void setLatestDialog(ShadowDialog latestDialog)
public java.lang.Object getBluetoothAdapter()
public void declareActionUnbindable(java.lang.String action)
public android.os.PowerManager.WakeLock getLatestWakeLock()
public void addWakeLock(android.os.PowerManager.WakeLock wl)
public void clearWakeLocks()
public <T> T getSingleton(java.lang.Class<T> clazz, Provider<T> provider)
public void checkActivities(boolean checkActivities)
Set to true if you’d like Robolectric to strictly simulate the real Android behavior when calling Context.startActivity(android.content.Intent)
. Real Android throws a ActivityNotFoundException
if given an Intent
that is not known to the PackageManager
By default, this behavior is off (false).
checkActivities
- True to validate activities.public ShadowPopupMenu getLatestPopupMenu()
public void setLatestPopupMenu(ShadowPopupMenu latestPopupMenu)
public android.widget.PopupWindow getLatestPopupWindow()
public void setLatestPopupWindow(android.widget.PopupWindow latestPopupWindow)
public android.widget.ListPopupWindow getLatestListPopupWindow()
public void setLatestListPopupWindow(android.widget.ListPopupWindow latestListPopupWindow)
@Implementation public int checkPermission(java.lang.String permission, int pid, int uid)
public void grantPermissions(java.lang.String... permissionNames)
grantPermissions
in class ShadowContextWrapper
public void denyPermissions(java.lang.String... permissionNames)
denyPermissions
in class ShadowContextWrapper
@Deprecated public void setSystemService(java.lang.String key, java.lang.Object service)