- Secondary Display Control via Android Presentation Class
- Display
- Presentation Class
- Emulator: Secondary displays cannot be added #21
- Comments
- MarkoVirtualizer commented Sep 10, 2020
- Behaviour
- Steps to reproduce this issue
- Expected behaviour
- Actual behaviour
- Configuration
- 6 Ways to Use Your Android as Second Monitor For Your Computer
- Use Your Android as a Second Monitor
- 1. Spacedesk
- 2. Splashtop Wired XDisplay
- 4. iDisplay
- 5. Air Display 2
- 6. Duet Display
- Use your Android Tablet as Monitor
- Android emulator secondary display
Secondary Display Control via Android Presentation Class
In this blog, we will learn about Secondary Display Control via Android Presentation Class.
Well, the title line certainly deals with a lot of words that probably most of the developers are not aware of and frankly, even I was not aware of this beauty of Android until last month.
Before we start, let me just tell you a few practical use cases for what you can build after following along.
- POS Hardware Machines & their Dedicated Application –> Have you seen the agents at big retail centers using POS machines?
There you can see what is being added to your cart at the same moment and the agent is processing your order.
If you peek at agent’s screen the content will be a bit(or entirely) different. - Presentation Apps –> Have you seen the applications where whole presentation(ppts, slides) are being controlled by some android device?
If you peek at the Android device screen the slides are bit different (like with notes, descriptions, etc) but on the secondary screen (like a projector ) the presentation is entirely different.
After reading this blog you will also be able to build something similar.
Before we start talking about code let’s just clear what the words in the title are.
Display
A display is referred to as a screen or area which can show the content.
As a result, an Android device can control any number of displays.
The main point to note is that the application’s code should be able to handle each display separately and these are in sync with the main display.
Main Display
This display refers to the actual screen provided by the manufacturer of the Android device.
Hence, this screen listens to all the user interactions, gestures and motions events.
As a result, this display is referred to as Main Display.
Secondary Display
This display refers to a secondary screen which is somehow (Bluetooth, wired connections, RFC) connected to your Android device.
By Default, this screen is not user interactive and hence it is called as Display and not Screen.
Presentation Class
A presentation is a special kind of dialog whose purpose is to present content on a secondary display. A Presentation is associated with the target Display at creation time and configures its context and resource configuration according to the display’s metrics.
For Simple understanding, we need to extend this class to build a view to display on our Secondary Display.
With this understanding, now you can do anything you want on Secondary Display.
Now, in this blog, we will just be making a Welcome TextView on the Secondary Display.
Источник
Emulator: Secondary displays cannot be added #21
Comments
MarkoVirtualizer commented Sep 10, 2020
Behaviour
Circumstances: Emulator is running OK on a PC and functions as a normal, fully interactive Android phone.
Actions: Using the GUI menu: Extended Controls (click the bottom «. » icon on the emulator’s sidebar) — Displays — Add secondary display, does not work. Although the grey schematic simulation on the right side shows the preview of the newly defined additional display(s), clicking the APPLY CHANGES button gives no result in the emulator window (no actual second display is added), and no error message is displayed either.
Steps to reproduce this issue
- Install the «Android Studio™ portable» normally, i.e. using the official portable installer linked from the Portapps page ([https://portapps.io/app/android-studio-portable]).
- Start the program using the android-studio-portable.exe launcher in the main installation directory, and set up everything you need, including virtual devices.
- On the «Welcome to Android Studio» screen, look down and click «Configure», select «AVD Manager».
- This opens a new window «Android Virtual Device Manager», where you can start any existing device of your choice (which opens in a new «Android Emulator» window).
- On the sidebar (right to the running virtual phone), click «. » to open the «Extended Controls» window, where you go to Displays — Add secondary display. Click APPLY CHANGES.
- You will see absolutely no response whatsoever.
- There is a message «Emulator: emulator: ERROR: MultiDisplay.cpp:110: Adb interface unavailable» on the «Welcome to Android Studio» screen, bottom part, the «Events» drop-down menu. This message may or may not be related to the problem described above (there are no other messages in that list, and I have no idea whether there is a causative relationship between the message and software malfunction).
Expected behaviour
In regular local (i.e., non-portable) installations, the above procedure expands the emulator window and adds a new display, predefined or custom, just next to the phone’s Home screen. This can be repeated up to 3 times, resulting in 4 displays neatly arranged next to each other in a single row (the Home screen, and the 3 secondary displays). Each additional display can be individually deleted or freely resized / reconfigured. All changes are remembered and when you stop or restart the Android Studio, the modified virtual device opens with the added displays and with the respective apps open on them running OK.
Actual behaviour
Nothing happens — no secondary displays are created — the button APPLY CHANGES is not reactive. This is a critical failure that prevents users from emulating dual-screen devices (e.g., Microsoft) and hampers testing apps in 2-, 3-, or 4-display settings.
Configuration
App release / arch (ex. 1.0.0-2 win64) :
Android Studio portable v.4.0.14
android-studio-portable-win64-4.0.1-14-setup.exe (installer)
android-studio-portable.exe v.2.4.4.0 (portable launcher)
studio64.exe v.4.0.0.0 (64-bit executable)
studio.exe v.4.0.0.0 (32-bit executable)
Operating system (ex. Windows 10 Pro 64 bits) / Winver screenshot :
Windows 10 Home, v.1909, 64-bit
OS Build: 18363.959
Join the log file log\[appname]-portable.log to this issue. File «android-studio-portable.log» is attached.
android-studio-portable.log
The text was updated successfully, but these errors were encountered:
Источник
6 Ways to Use Your Android as Second Monitor For Your Computer
Attaching a Second display to your existing Computer setup can be a huge productivity boost but before you hit the buy button on Amazon, ask yourself do you need a dedicated Monitor all the time? If your answer is some times, then I have the perfect solution for you.
If you own an iPad, you must have heard Duet Display– a popular second monitor app for iPad. Thankfully, Android has them too. We tested almost every second monitor app for Android on the Google Play store, and here are our top picks. Let’s begin.
Use Your Android as a Second Monitor
Android smartphones and tablets are pretty versatile in terms of features, you can mirror your Android to another Android and as well as a computer. In general, you need need to install a second monitor app on your Android and install the app’s client app on your computer. Once done you can connect your Android to your computer, using a USB cable or WiFi (when both the devices are connected to the same network) and that’s it.
1. Spacedesk
Spacedesk is a popular choice to transform your Android into a second display monitor for Windows PC. You can connect your PC and Android via USB, Wi-Fi or LAN. The resolution is decent and you get touch support.
To get started, you need to install the necessary drivers on your Windows PC. If you need further help, here is a link to the documentation. The app is available for Windows 7 and above. Opening the app will automatically detect and display all PCs on the same server that has the drivers installed. Simply tap to connect. Launch the app on your Android and connect to your PC. The app should detect the IP address and name of your system.
To use your tablet or Android as an extended display, you just have to configure secondary display options in Windows. To do that go to the Control Panel and then Display Settings. Select Extend These Displays and click OK. You should now be able to use your Android as an extended display.
Spacedesk works well if you don’t want your phone to be bounded by a USB. But that’s the only complaint I have. Since it works wirelessly, there is a noticeable amount of lag. It’s good that you can switch to hotspot and USB.
Supported Medium: LAN, Wi-Fi, USB
2. Splashtop Wired XDisplay
Splashtop Wired XDisplay, as the name suggests, will require you to have a USB handy. Unlike Spacedesk, WiredXDisplay allows you to connect your phone only via USB. On the plus side, since you are connected by a wired medium, you get better resolution and frame rate. It supports Full HD resolution at 60 frames per second.
Wired XDisplay can be installed on both Mac and PC, giving it an edge over Air Display. Mobile apps are available for both Android and iOS. Splashtop uses USB over WiFi for one simple reason – it offers a more responsive and real-time experience. There is no lag whatsoever and you get a battery saver mode which drops the frame rate and resolution to save up on processing.
Supported Medium: USB
3. Google Remote Desktop
Like Remote Desktop for Windows, it also allows you to control your PC via your Android device. You can run commands on your PC from your Android phone. Basically, everything that you can do on your desktop can be done from the Android phone as well. Remote Desktop, like all Google products, is easy to use and simple to set up. You just need to have a working Gmail account. The ability to control your PC remotely is where it shines the most though.
Google Remote Desktop works seamlessly but you cannot use separate apps on both the screen. It doesn’t let you use your phone as an extended display.
Supported Medium: Internet
4. iDisplay
iDisplay is another display mirroring app on this list. iDisplay started with the macOS and iOS but quickly expanded to other Operating systems. You have apps for Windows and Android which makes it a good cross-platform solution. It supports 60 fps and plus offers multi-touch on the device you are using it on.
iDisplay has everything that the other app offers, with one caveat; USB support is not available for Android yet. It does support WiFi though and comes with multi-touch support.
Supported Medium: LAN, Wi-Fi, USB (except Android)
5. Air Display 2
Air Display 2 works the same way for Mac the way Spacedesk does for Windows PC but it comes with a price of 14.99$. It turns your Android device into a secondary screen for your Macbooks. You can extend mirroring the screen to up to 4 secondary devices. On top of that, it also supports full HD displays.
It supports all the way back to Mac OS X 10.8 or Lion. You can also use your PC as a secondary screen for your Mac. But it doesn’t work the other way round like you cannot use Mac or any mobile device as a secondary screen for Windows. I read the FAQs section and it says they are working on a solution, but it also says that they are not “close enough” to provide an ETA.
On the plus side, it offers a more responsive experience thanks to the dynamic compression algorithm the team is using. It also supports retina display, something that is missing in Spacedesk. App also features Air Stylus which you can actually use the secondary device to draw designs on directly.
Air Display works seamlessly but the issue is the pricing model. With every major upgrade Avatron Software i.e. the creator of Air Display increases the price. This is something that bothers long-time users like me but hey if money is not a problem then you are good to go. Another thing that bugs me is that you need to install Air Display Host on your iPhones, Androids, and PCs which you want to use as a secondary screen. But, Air Display can only be installed on Macs. So the cross-platform compatibility gets a little limited.
6. Duet Display
Duet Display is a popular iOS app that allows you to mirror and extend your Mac’s display to your iPad or iPhone. And now that Apple is providing this feature natively via Sidecar, Duet Display is expanding its horizons with support for Android smartphones and tablets.
Duet Display invited us to beta test their new app, and it worked fine on my Google Pixel and Windows 10. Although, I did encounter a few bugs such as connection breaks. Also, while you can connect your Android Smartphone wirelessly to a Windows computer, you still need to attach a USB cable if you want to use the Android app with macOS.
The app is competitively priced at $9.99 and offers a lot of features and supports a wide range of devices. You can get the app for both Android and iOS devices.
Use your Android Tablet as Monitor
These were some of the most efficient ways to create an extended display from your Android smartphones and tablets. Let me know how’s your experience with these apps and which one you ended up using for your devices.
Источник
Android emulator secondary display
This application provides display and control of Android devices connected via USB (or over TCP/IP). It does not require any root access. It works on GNU/Linux, Windows and macOS.
- lightness: native, displays only the device screen
- performance: 30
120fps, depending on the device
70ms
low startup time:
1 second to display the first image
Its features include:
The Android device requires at least API 21 (Android 5.0).
Make sure you enabled adb debugging on your device(s).
On some devices, you also need to enable an additional option to control it using keyboard and mouse.
- Linux: apt install scrcpy
- Windows: download
- macOS: brew install scrcpy
On Debian and Ubuntu:
A Snap package is available: scrcpy .
For Fedora, a COPR package is available: scrcpy .
For Gentoo, an Ebuild is available: scrcpy/ .
For Windows, for simplicity, a prebuilt archive with all the dependencies (including adb ) is available:
It is also available in Chocolatey:
The application is available in Homebrew. Just install it:
You need adb , accessible from your PATH . If you don’t have it yet:
It’s also available in MacPorts, which sets up adb for you:
Plug an Android device, and execute:
It accepts command-line arguments, listed by:
Sometimes, it is useful to mirror an Android device at a lower definition to increase performance.
To limit both the width and height to some value (e.g. 1024):
The other dimension is computed to that the device aspect ratio is preserved. That way, a device in 1920×1080 will be mirrored at 1024×576.
The default bit-rate is 8 Mbps. To change the video bitrate (e.g. to 2 Mbps):
Limit frame rate
The capture frame rate can be limited:
This is officially supported since Android 10, but may work on earlier versions.
The device screen may be cropped to mirror only part of the screen.
This is useful for example to mirror only one eye of the Oculus Go:
If —max-size is also specified, resizing is applied after cropping.
Lock video orientation
To lock the orientation of the mirroring:
This affects recording orientation.
Some devices have more than one encoder, and some of them may cause issues or crash. It is possible to select a different encoder:
To list the available encoders, you could pass an invalid encoder name, the error will give the available encoders:
It is possible to record the screen while mirroring:
To disable mirroring while recording:
«Skipped frames» are recorded, even if they are not displayed in real time (for performance reasons). Frames are timestamped on the device, so packet delay variation does not impact the recorded file.
On Linux, it is possible to send the video stream to a v4l2 loopback device, so that the Android device can be opened like a webcam by any v4l2-capable tool.
The module v4l2loopback must be installed:
To create a v4l2 device:
This will create a new video device in /dev/videoN , where N is an integer (more options are available to create several devices or devices with specific IDs).
To list the enabled devices:
To start scrcpy using a v4l2 sink:
(replace N by the device ID, check with ls /dev/video* )
Once enabled, you can open your video stream with a v4l2-capable tool:
For example, you could capture the video within OBS.
It is possible to add buffering. This increases latency but reduces jitter (see #2464).
The option is available for display buffering:
Scrcpy uses adb to communicate with the device, and adb can connect to a device over TCP/IP. The device must be connected on the same network as the computer.
An option —tcpip allows to configure the connection automatically. There are two variants.
If the device (accessible at 192.168.1.1 in this example) already listens on a port (typically 5555) for incoming adb connections, then run:
If adb TCP/IP mode is disabled on the device (or if you don’t know the IP address), connect the device over USB, then run:
It will automatically find the device IP address, enable TCP/IP mode, then connect to the device before starting.
Alternatively, it is possible to enable the TCP/IP connection manually using adb :
Connect the device to the same Wi-Fi as your computer.
Get your device IP address, in Settings → About phone → Status, or by executing this command:
Enable adb over TCP/IP on your device: adb tcpip 5555 .
Unplug your device.
Connect to your device: adb connect DEVICE_IP:5555 (replace DEVICE_IP ).
Run scrcpy as usual.
It may be useful to decrease the bit-rate and the definition:
If several devices are listed in adb devices , you must specify the serial:
If the device is connected over TCP/IP:
You can start several instances of scrcpy for several devices.
Autostart on device connection
To connect to a remote device, it is possible to connect a local adb client to a remote adb server (provided they use the same version of the adb protocol).
Remote ADB server
To connect to a remote ADB server, make the server listen on all interfaces:
Warning: all communications between clients and ADB server are unencrypted.
Suppose that this server is accessible at 192.168.1.2. Then, from another terminal, run scrcpy:
By default, scrcpy uses the local port used for adb forward tunnel establishment (typically 27183 , see —port ). It is also possible to force a different tunnel port (it may be useful in more complex situations, when more redirections are involved):
To communicate with a remote ADB server securely, it is preferable to use a SSH tunnel.
First, make sure the ADB server is running on the remote computer:
Then, establish a SSH tunnel:
From another terminal, run scrcpy:
To avoid enabling remote port forwarding, you could force a forward connection instead (notice the -L instead of -R ):
From another terminal, run scrcpy:
Like for wireless connections, it may be useful to reduce quality:
By default, the window title is the device model. It can be changed:
Position and size
The initial window position and size may be specified:
To disable window decorations:
To keep the scrcpy window always on top:
The app may be started directly in fullscreen:
Fullscreen can then be toggled dynamically with MOD + f .
The window may be rotated:
Possibles values are:
- 0 : no rotation
- 1 : 90 degrees counterclockwise
- 2 : 180 degrees
- 3 : 90 degrees clockwise
The rotation can also be changed dynamically with MOD + ← (left) and MOD + → (right).
Note that scrcpy manages 3 different rotations:
- MOD + r requests the device to switch between portrait and landscape (the current running app may refuse, if it does not support the requested orientation).
- —lock-video-orientation changes the mirroring orientation (the orientation of the video sent from the device to the computer). This affects the recording.
- —rotation (or MOD + ← / MOD + → ) rotates only the window content. This affects only the display, not the recording.
Other mirroring options
To disable controls (everything which can interact with the device: input keys, mouse events, drag&drop files):
If several displays are available, it is possible to select the display to mirror:
The list of display ids can be retrieved by:
The secondary display may only be controlled if the device runs at least Android 10 (otherwise it is mirrored in read-only).
To prevent the device to sleep after some delay when the device is plugged in:
The initial state is restored when scrcpy is closed.
Turn screen off
It is possible to turn the device screen off while mirroring on start with a command-line option:
Or by pressing MOD + o at any time.
To turn it back on, press MOD + Shift + o .
On Android, the POWER button always turns the screen on. For convenience, if POWER is sent via scrcpy (via right-click or MOD + p ), it will force to turn the screen off after a small delay (on a best effort basis). The physical POWER button will still cause the screen to be turned on.
It can also be useful to prevent the device from sleeping:
Power off on close
To turn the device screen off when closing scrcpy:
For presentations, it may be useful to show physical touches (on the physical device).
Android provides this feature in Developers options.
Scrcpy provides an option to enable this feature on start and restore the initial value on exit:
Note that it only shows physical touches (with the finger on the device).
By default, scrcpy does not prevent the screensaver to run on the computer.
Rotate device screen
Press MOD + r to switch between portrait and landscape modes.
Note that it rotates only if the application in foreground supports the requested orientation.
Any time the Android clipboard changes, it is automatically synchronized to the computer clipboard.
Any Ctrl shortcut is forwarded to the device. In particular:
- Ctrl + c typically copies
- Ctrl + x typically cuts
- Ctrl + v typically pastes (after computer-to-device clipboard synchronization)
This typically works as you expect.
The actual behavior depends on the active application though. For example, Termux sends SIGINT on Ctrl + c instead, and K-9 Mail composes a new message.
To copy, cut and paste in such cases (but only supported on Android >= 7):
- MOD + c injects COPY
- MOD + x injects CUT
- MOD + v injects PASTE (after computer-to-device clipboard synchronization)
In addition, MOD + Shift + v allows to inject the computer clipboard text as a sequence of key events. This is useful when the component does not accept text pasting (for example in Termux), but it can break non-ASCII content.
WARNING: Pasting the computer clipboard to the device (either via Ctrl + v or MOD + v ) copies the content into the device clipboard. As a consequence, any Android application could read its content. You should avoid to paste sensitive content (like passwords) that way.
Some devices do not behave as expected when setting the device clipboard programmatically. An option —legacy-paste is provided to change the behavior of Ctrl + v and MOD + v so that they also inject the computer clipboard text as a sequence of key events (the same way as MOD + Shift + v ).
To disable automatic clipboard synchronization, use —no-clipboard-autosync .
To simulate «pinch-to-zoom»: Ctrl +click-and-move.
More precisely, hold Ctrl while pressing the left-click button. Until the left-click button is released, all mouse movements scale and rotate the content (if supported by the app) relative to the center of the screen.
Concretely, scrcpy generates additional touch events from a «virtual finger» at a location inverted through the center of the screen.
Physical keyboard simulation (HID)
By default, scrcpy uses Android key or text injection: it works everywhere, but is limited to ASCII.
On Linux, scrcpy can simulate a physical USB keyboard on Android to provide a better input experience (using USB HID over AOAv2): the virtual keyboard is disabled and it works for all characters and IME.
However, it only works if the device is connected by USB, and is currently only supported on Linux.
To enable this mode:
If it fails for some reason (for example because the device is not connected via USB), it automatically fallbacks to the default mode (with a log in the console). This allows to use the same command line options when connected over USB and TCP/IP.
In this mode, raw key events (scancodes) are sent to the device, independently of the host key mapping. Therefore, if your keyboard layout does not match, it must be configured on the Android device, in Settings → System → Languages and input → Physical keyboard.
This settings page can be started directly:
However, the option is only available when the HID keyboard is enabled (or when a physical keyboard is connected).
Text injection preference
There are two kinds of events generated when typing text:
- key events, signaling that a key is pressed or released;
- text events, signaling that a text has been entered.
By default, letters are injected using key events, so that the keyboard behaves as expected in games (typically for WASD keys).
But this may cause issues. If you encounter such a problem, you can avoid it by:
(but this will break keyboard behavior in games)
On the contrary, you could force to always inject raw key events:
These options have no effect on HID keyboard (all key events are sent as scancodes in this mode).
By default, holding a key down generates repeated key events. This can cause performance problems in some games, where these events are useless anyway.
To avoid forwarding repeated key events:
This option has no effect on HID keyboard (key repeat is handled by Android directly in this mode).
Right-click and middle-click
By default, right-click triggers BACK (or POWER on) and middle-click triggers HOME. To disable these shortcuts and forward the clicks to the device instead:
To install an APK, drag & drop an APK file (ending with .apk ) to the scrcpy window.
There is no visual feedback, a log is printed to the console.
Push file to device
To push a file to /sdcard/Download/ on the device, drag & drop a (non-APK) file to the scrcpy window.
There is no visual feedback, a log is printed to the console.
The target directory can be changed on start:
Audio is not forwarded by scrcpy. Use sndcpy.
In the following list, MOD is the shortcut modifier. By default, it’s (left) Alt or (left) Super .
It can be changed using —shortcut-mod . Possible keys are lctrl , rctrl , lalt , ralt , lsuper and rsuper . For example:
Super is typically the Windows or Cmd key.
Action | Shortcut |
---|---|
Switch fullscreen mode | MOD + f |
Rotate display left | MOD + ← (left) |
Rotate display right | MOD + → (right) |
Resize window to 1:1 (pixel-perfect) | MOD + g |
Resize window to remove black borders | MOD + w | Double-left-click¹ |
Click on HOME | MOD + h | Middle-click |
Click on BACK | MOD + b | Right-click² |
Click on APP_SWITCH | MOD + s | 4th-click³ |
Click on MENU (unlock screen) | MOD + m |
Click on VOLUME_UP | MOD + ↑ (up) |
Click on VOLUME_DOWN | MOD + ↓ (down) |
Click on POWER | MOD + p |
Power on | Right-click² |
Turn device screen off (keep mirroring) | MOD + o |
Turn device screen on | MOD + Shift + o |
Rotate device screen | MOD + r |
Expand notification panel | MOD + n | 5th-click³ |
Expand settings panel | MOD + n + n | Double-5th-click³ |
Collapse panels | MOD + Shift + n |
Copy to clipboard⁴ | MOD + c |
Cut to clipboard⁴ | MOD + x |
Synchronize clipboards and paste⁴ | MOD + v |
Inject computer clipboard text | MOD + Shift + v |
Enable/disable FPS counter (on stdout) | MOD + i |
Pinch-to-zoom | Ctrl +click-and-move |
Drag & drop APK file | Install APK from computer |
Drag & drop non-APK file | Push file to device |
¹Double-click on black borders to remove them.
²Right-click turns the screen on if it was off, presses BACK otherwise.
³4th and 5th mouse buttons, if your mouse has them.
⁴Only on Android >= 7.
Shortcuts with repeated keys are executted by releasing and pressing the key a second time. For example, to execute «Expand settings panel»:
- Press and keep pressing MOD .
- Then double-press n .
- Finally, release MOD .
All Ctrl +key shortcuts are forwarded to the device, so they are handled by the active application.
To use a specific adb binary, configure its path in the environment variable ADB :
To override the path of the scrcpy-server file, configure its path in SCRCPY_SERVER_PATH .
To override the icon, configure its path in SCRCPY_ICON_PATH .
A colleague challenged me to find a name as unpronounceable as gnirehtet.
strcpy copies a string; scrcpy copies a screen.
Источник