本文整理了Java中android.app.Application.getSystemService()
方法的一些代码示例,展示了Application.getSystemService()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Application.getSystemService()
方法的具体详情如下:
包路径:android.app.Application
类名称:Application
方法名:getSystemService
暂无
代码示例来源:origin: robolectric/robolectric
/**
* @deprecated Please use {@link Context#getSystemService(Context.APPWIDGET_SERVICE)} intstead.
*/
@Deprecated
public AppWidgetManager getAppWidgetManager() {
return (AppWidgetManager) realApplication.getSystemService(Context.APPWIDGET_SERVICE);
}
代码示例来源:origin: robolectric/robolectric
private void removeForegroundNotification() {
NotificationManager nm = (NotificationManager)RuntimeEnvironment.application.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel(lastForegroundNotificationId);
lastForegroundNotification = null;
}
代码示例来源:origin: Tencent/tinker
@Override
public Object getSystemService(String name) {
Object service = super.getSystemService(name);
if (applicationLike != null) {
return invokeAppLikeGetSystemService(applicationLike, name, service);
}
return service;
}
代码示例来源:origin: robolectric/robolectric
@Implementation
protected final void startForeground(int id, Notification notification) {
foregroundStopped = false;
lastForegroundNotificationId = id;
lastForegroundNotification = notification;
notification.flags |= Notification.FLAG_FOREGROUND_SERVICE;
NotificationManager nm = (NotificationManager)RuntimeEnvironment.application.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(id, notification);
}
代码示例来源:origin: bumptech/glide
public ConnectivityHarness() {
ConnectivityManager connectivityManager = (ConnectivityManager) RuntimeEnvironment.application
.getSystemService(Context.CONNECTIVITY_SERVICE);
shadowConnectivityManager = Shadow.extract(connectivityManager);
}
代码示例来源:origin: robolectric/robolectric
@Test
@Config(minSdk = JELLY_BEAN_MR1)
public void shouldProvideServicesIntroducedInJellyBeanMr1() throws Exception {
assertThat(context.getSystemService(Context.DISPLAY_SERVICE))
.isInstanceOf(android.hardware.display.DisplayManager.class);
assertThat(context.getSystemService(Context.USER_SERVICE)).isInstanceOf(UserManager.class);
}
代码示例来源:origin: robolectric/robolectric
@Test
@Config(minSdk = O)
public void shouldProvideServicesIntroducedOreo() throws Exception {
// Context.AUTOFILL_MANAGER_SERVICE is marked @hide and this is the documented way to obtain
// this service.
AutofillManager autofillManager = context.getSystemService(AutofillManager.class);
assertThat(autofillManager).isNotNull();
assertThat(context.getSystemService(Context.TEXT_CLASSIFICATION_SERVICE))
.isInstanceOf(TextClassificationManager.class);
}
代码示例来源:origin: robolectric/robolectric
@Test
@Config(minSdk = JELLY_BEAN_MR2)
public void getSystemService_shouldReturnBluetoothAdapter() {
assertThat(context.getSystemService(Context.BLUETOOTH_SERVICE))
.isInstanceOf(BluetoothManager.class);
}
代码示例来源:origin: robolectric/robolectric
@HiddenApi
@Implementation(minSdk = JELLY_BEAN_MR1)
protected boolean switchUser(int userid) {
ShadowUserManager shadowUserManager =
Shadow.extract(RuntimeEnvironment.application.getSystemService(Context.USER_SERVICE));
shadowUserManager.switchUser(userid);
return true;
}
代码示例来源:origin: bumptech/glide
@Before
public void setUp() {
NotificationManager notificationManager =
(NotificationManager)
RuntimeEnvironment.application.getSystemService(Context.NOTIFICATION_SERVICE);
shadowManager = Shadow.extract(notificationManager);
remoteViews = mock(RemoteViews.class);
viewId = 123;
notification = mock(Notification.class);
notificationId = 456;
notificationTag = "tag";
target =
new NotificationTarget(RuntimeEnvironment.application, 100 /*width*/, 100 /*height*/,
viewId, remoteViews, notification, notificationId, notificationTag);
}
代码示例来源:origin: robolectric/robolectric
@Before
public void setUp() {
euiccManager = application.getSystemService(EuiccManager.class);
shadowEuiccManager = Shadows.shadowOf(euiccManager);
}
代码示例来源:origin: robolectric/robolectric
@Before
public void setUp() {
context = ApplicationProvider.getApplicationContext();
jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void removeSystemService_getSystemServiceReturnsNull() {
shadowContext.removeSystemService(Context.WALLPAPER_SERVICE);
assertThat(context.getSystemService(Context.WALLPAPER_SERVICE)).isNull();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void createPackageContext() throws Exception {
Context packageContext = context.createPackageContext(context.getPackageName(), 0);
LayoutInflater inflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.cloneInContext(packageContext);
inflater.inflate(R.layout.remote_views, new FrameLayout(context), false);
}
代码示例来源:origin: google/ExoPlayer
@Before
public void setUp() {
audioManager =
(AudioManager) RuntimeEnvironment.application.getSystemService(Context.AUDIO_SERVICE);
testPlayerControl = new TestPlayerControl();
audioFocusManager = new AudioFocusManager(RuntimeEnvironment.application, testPlayerControl);
}
代码示例来源:origin: bumptech/glide
private void setDisplayDimens(Integer width, Integer height) {
WindowManager windowManager =
(WindowManager) RuntimeEnvironment.application.getSystemService(Context.WINDOW_SERVICE);
Display display = Preconditions.checkNotNull(windowManager).getDefaultDisplay();
if (width != null) {
Shadows.shadowOf(display).setWidth(width);
}
if (height != null) {
Shadows.shadowOf(display).setHeight(height);
}
}
代码示例来源:origin: bumptech/glide
private void setDisplayDimens(Integer width, Integer height) {
WindowManager windowManager =
(WindowManager) RuntimeEnvironment.application.getSystemService(Context.WINDOW_SERVICE);
Display display = Preconditions.checkNotNull(windowManager).getDefaultDisplay();
if (width != null) {
Shadows.shadowOf(display).setWidth(width);
}
if (height != null) {
Shadows.shadowOf(display).setHeight(height);
}
}
代码示例来源:origin: robolectric/robolectric
@Before
public void setUp() {
context = ApplicationProvider.getApplicationContext();
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
shadowLocationManager = shadowOf(locationManager);
}
代码示例来源:origin: robolectric/robolectric
@Test
@Config(minSdk = KITKAT)
public void shouldCorrectlyInstantiatedAccessibilityService() throws Exception {
AccessibilityManager accessibilityManager =
(AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
AccessibilityManager.TouchExplorationStateChangeListener listener = createTouchListener();
assertThat(accessibilityManager.addTouchExplorationStateChangeListener(listener)).isTrue();
assertThat(accessibilityManager.removeTouchExplorationStateChangeListener(listener)).isTrue();
}
代码示例来源:origin: robolectric/robolectric
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
Application context = ApplicationProvider.getApplicationContext();
manager = (WifiP2pManager) context.getSystemService(Context.WIFI_P2P_SERVICE);
shadowManager = shadowOf(manager);
channel = manager.initialize(context, context.getMainLooper(), mockListener);
assertThat(channel).isNotNull();
}
内容来源于网络,如有侵权,请联系作者删除!