Capture screenshot in GenyMotion - android-emulator

I am using Genymotion for running android application.
Could any one tell me how to capture screen shot in Genymotion ?

If you are using Android Studio or Eclipse, you can just click the button "Screen Capture" in the Android DDMS:

You can use adb to get the screenshot from command line:
adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screen.png
This article has the details:
http://blog.shvetsov.com/2013/02/grab-android-screenshot-to-computer-via.html
To make my life easier, I made an alias in .bash_profile:
alias screenshot="adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > ~/Downloads/android_screenshot.png"
Now I can type screenshot in Terminal and get a screenshot of currently running emulator in my Downloads directory.

Disclaimer : I'm part of the same company as the Genymotion team.
This feature is included in the product. It is one of the paid feature of the screencast widget. Look at the pricing page here.
Two ways to access it:
pay for the pro or indie licence
use the trial version, it offers you the indie features. Be careful, there is only one trial day left :-/
Once your VM is started, open the screencast widget
Then take a picture with the dedicated button
UPDATE: You have bellow another ways to take a screenshot using Android Device Monitor or the command line

Use this commands:
Windows:
C:\"Program Files"\Genymobile\Genymotion\tools\adb shell screencap -p "/mnt/sdcard/output.png" && C:\"Program Files"\Genymobile\Genymotion\tools\adb pull "/mnt/sdcard/output.png" "C:\output.png" && C:\"Program Files"\Genymobile\Genymotion\tools\adb shell rm "/mnt/sdcard/output.png"
Note: Make sure you have permission to write to C:\output.png; otherwise, change it to whatever path you like.
OS X:
/Applications/Genymotion.app/Contents/MacOS/tools/adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > ~/Desktop/Android_Screenshot_$(date +%Y-%m-%d-%H-%M-%S).png

Select genymotion simulator
Hit shortcut key describe below
Windows : Ctrl+Shift+S
Mac : Cmd+Shift+S
You can find your screenshots at desktop

I think you can also take videos for free. Genymotion uses VirtualBox to do almost all the heavy lifting, so you should open VirtualBox and look at what you can do in it.
You will find options in Virtualbox to capture video!

adb shell screencap -p /sdcard/screen.png

If your Mac is slow and you hate running Eclipse and the emulator together here is a quicker way.
Export your apk.
Start Genymotion.
Drag the apk to the emulator, in order to install it.
Go to 'android-sdk-macosx>tools>ddms'.
Run that file.
A new instance of ddms will be started. Unlike Eclipse, it doesn't slow down your system.
Use the 'Menu>Device>Screenshot' option to take screenshot.
This is a good option for those using slow computers.

If you are using Eclipse, then follow the steps for any type of emulator:
1. Select DDMS
2. In Devices window of DDMS select Genymotion device
3. Click on Camera icon then save it to specific location.

For Linux and Windows (I used gitbash on windows)
adb shell screencap -p | sed 's/\r$//' > screen.png
For Mac
adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screen.png

#Reck says there's a bug in the Genymotion implementation so we can't take screenshots on 2.3.7. This means that Android Studio / DDMS can't get the proper pixels. adb shell screencap says there's no screencap command.
Assuming you have access to the code you can simply call this method:
public static void screenshot(View view) {
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
view.draw(new Canvas(bitmap));
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
try {
File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
storageDir.mkdirs();
File file = File.createTempFile(timeStamp, ".png", storageDir);
bitmap.compress(Bitmap.CompressFormat.PNG, 0, new FileOutputStream(file));
Log.i("SCREENSHOT", "adb pull " + file);
} catch (IOException e) {
Log.e("SCREENSHOT", "Cannot save screenshot of " + view, e);
}
}
In Activity:
screenshot(getWindow().getDecorView());
In Fragment:
screenshot(getActivity().getWindow().getDecorView());
The only limitation I know is that it won't include the status bar.

if you use Mac, sometimes CMD + Shift + 4 (screenshot of a selected portion in OSX ) and then selecting the simulator region is enough :)

Take a screenshot
On many Android devices, you can capture a screenshot with a key-combination: Simultaneously press-and-hold Power and Volume-down. You can also capture a screenshot with Android Studio as follows:
Run your app on a connected device or emulator. If using a connected device, be sure you have enabled USB debugging.
In Android Studio, select View > Tool Windows > Logcat to open Logcat.
Select the device and a process from the drop-down at the top of the window.
Click Screen Capture on the left side of the window.
The screenshot appears in a Screenshot Editor window
It Works for even Genymotion Emulator
Check here for further information

Related

Flutter cannot connect to emulator in VSCode. Waiting for a connection from Flutter

I can see the device list on VSCode in Windows.
And I can select any one.
And the emulator is opening.
But I can see a single message. "Waiting for a connection from Flutter.."
Application does not open.
It doesn't get any errors either. Waiting like this.
Make sure that your API level you're running your device on is the
same as what you have installed on Android Studio.
1.1 Click on the SDK Manager button around the top right corner of AS (The icon is a box with a down arrow next to it).
1.2 Choose the same API level as your device, (When I didn't do this I had a partial install and it took some time to compile), then
click apply and wait for it to install.
We're going to run the project to our avd or mobile device from the directory of ourproject.
2.1 Open up the Command Prompt (preferably as Admin), and chage the directoy to where your project is, the command should look something
like this:
cd Documents/flutterprojects/yourflutterproject.
2.2 Finally type the command flutter run.
Restart the Emulator by holding the power Button and Selecting restart and then try again.
if that failed to work, simply restart your computer.

Chrome remote connection connects but then drops out

I am really struggling to get Google Chrome Remote Debugging to work! I have the phone setup and confirmed:
Then below are what I see in chrome://inspect/#devices and also F12 (both open at the same time);
It flashes with the "Connected" for about 3 seconds, and then goes to:
Offline
ZX1G324RSV Pending authentication: please accept debugging session on the device.
It's driving me nuts, as it should be simple to do, but it just doesn't want to play ball :/ Do I need to do anything special? I've used it before on this PC and although I had some fun and games with it the first time around, it worked after that.
There seems to be a ton of posts/articles about how to fix it, but none of them are working for me. https://bugs.chromium.org/p/chromium/issues/detail?id=450492 for example.
Download Android SDK here ("SDK Tools Only" section) and unzip the content.
Run SDK Manager.exe and install Android SDK platform tools
Open up the Command prompt (simply by pressing the windows button and type in cmd.exe)
Enter the path with ex: cd c:/downloads/sdk/platform-tools
Open ADB by typing in adb.exe
Run the following command by typing it and pressing enter: adb devices
Check if you get the prompt on your device, if you still can't see your phone in Inspect Devices run the following commands one by one (excluding the ") "adb kill-server" "adb start-server" "adb devices"
Here are the things that you can try:
Try different USB cable(s)
Try different USB ports on your machine(for some people using 2.0 port worked out)
Try the same process, with unchecked 'Discover USB Devices' in chrome://inspect (then Chrome will connect through the ADB server, not directly) ==> This solution worked in my scenario.

Mac Terminal - How to start Android Virtual Device Manager on CLI?

I am currently developing a mobile web application and I don't have a test device yet so I'm using the android-emulator to check the site. On my mac, I have installed the stand-alone Android SDK. Every time I want to use the AVD Manager, I have to execute the following on my terminal:
monitor
This command (being executed on the installed android sdk path) will open the Android Device Monitor and from here, I go to its menu bar and select Window Virtual Device Manager just to open the AVD Manager. So, is there a shortcut for that? I mean, i want to directly open the AVD manager via cli.
I was able to open it from terminal with:
android avd
You may need to navigate to your SDK tools/ first. Here is reference I used:
AVD Manager
Go to tools directory inside your android sdk like:
cd ~/Android/Sdk/tools
and enter run your avd as
./emulator -avd <your-avd>
You can find your avd name by running:
./emulator -list-avds
You can start emulator use terminal shell
emulator -avd <avd_name> [<options>]
options can be special -http-proxy, -dns-server setting. Get more options here
And to list all avd you can use:
emulator -list-avds
result like following:
4.7_WXGA_API_23
Nexus_5X_Edited_API_23
Example when I start Nexus_5X_Edited_API_23 emulator in OS X 10.11 with proxy setting
~/Library/Android/sdk/tools/emulator -netdelay none -netspeed full -avd Nexus_5X_Edited_API_23 -http-proxy http://username:password#local_server:8080
this is just a small addon to previous solutions presented. What is probably handy to do is to just jam this as a alias into your bash_profile like so:
Open your bash_profile:
nano ~/.bash_profile
Add this:
alias avd='cd /path-to-sdk/tools; ./android avd'
Source it again:
source ~/.bash_profile
In the CLI type:
avd
Now you can open up the AVD by just using avd in the command line. The only thing i haven't figured out how to make it stay alive after closing the terminal. Maybe somebody has tips on that.
Use the Android SDK Tools:
avdmanager
Or you can also start it by using the command below but it's deprecated though on newer version. Before executing it, make sure to export your Android SDK's tools directory in your ~/.bash_profile (i.e. export PATH="/Users/user/Software/android-sdk-macosx/tools:$PATH")
android avd
Old answer:
In order to open the avd manager on terminal, execute the following:
/usr/bin/java -Xmx256M -XstartOnFirstThread \
-Dcom.android.sdkmanager.toolsdir=/path/of/android-sdk-macosx/tools \
-classpath /path/of/android-sdk-macosx/tools/lib/sdkmanager.jar:/path/of/android-sdk-macosx/tools/lib/swtmenubar.jar:/path/of/android-sdk-macosx/tools/lib/x86_64/swt.jar \
com.android.sdkmanager.Main avd
emulator -avd <nameOfYourAvdEmulator>
Find the names of your emulators using avdmanager list avd:
avdmanager list avd
Name: Nexus_5X_API_23_Android_6.0
Device: Nexus 5X (Google)
Path: /Users/edward3/.android/avd/Nexus_5X_API_23_Android_6.0.avd
Target: Google APIs (Google Inc.)
Based on: Android 6.0 (Marshmallow) Tag/ABI: google_apis/x86
Skin: nexus_5x
Sdcard: 512M
Add to your ~/.profile if missing:
# Add to your ~/.profile PATH to easily run emulator and avdmanager commands
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
# Create alias to run your favorite Android emulator
alias avd-run='emulator -avd Nexus_5X_API_23_Android_6.0 &'
Open a new terminal or use source ~/.profile to reload changes made to your ~/.profile
Start your favorite emulator using the alias you created:
avd-run

Frozen Android emulator due to audio problems?

Today I installed the latest version of Eclipse, Android SDK and AVD plugin. But I have a tedious problem. When I want to quit the emulator (with the X button), the emulator freezes and I can't click anything there anymore. Obviously it has something to do with the sound, because when I execute "pulseaudio -k" in console, the emulator quits.
Due to this fact, I tried the following to let the emulator at least run properly:
In Preferences->Android->Launch -> Default Emulator option -> -noaudio
and
Run Configuration -> Android Application -> [Application] -> Target -> Addidtional Emulator Command Line Options -> -noaudio
But nothing helps. Emulator stays frozen. Actually I want audio to run, but switching it off doesn't work either. So what can I do?
I replied on the issue, but just if interested:
you may need to disable audio output instead, this is not desirable for me, so just select alsa (or esd/oss) by setting environment variable
QEMU_AUDIO_DRV=alsa
Looks like there is no way to specify audio drivers in hardware.ini so the best solution is going to sdk tools directory, rename emulator in emulator.real and make a shell script named emulator containing:
#!/bin/sh
export QEMU_AUDIO_DRV=alsa
exec $(dirname $0)/emulator.real $*
then chmod 755 emulator
It's this problem described here:
http://code.google.com/p/android/issues/detail?id=17294
There is a workaround so that you can quit the emulator:
Set in your virtual devices "Audio Playback Support" and "Audio recording support" to "no".

Android Emulator sdcard push error: Read-only file system

I am developing under Android 1.6 (Android SDK 2.1).
I create a avd by using avd manager in Eclipse.
When I launch this avd, I found that the /sdcard directory's permisson is "d---------".
So I can't push file to the sdcard.
Does anyone know how to solve this problem?
I found this works
$./adb shell
$su
mount -o rw,remount rootfs /
chmod 777 /mnt/sdcard
exit
Source: http://www.coderanch.com/t/611842/Android/Mobile/Android-emulator-sdcard-writable
Once you started the Emulator from one shell, login to another shell & type
adb shell
You should see # prompt displayed, this is your device(emulator) shell. Now , type following command at adb shell.
mount -o remount rw /sdcard
This will now remount /sdcard with rw(read-write) permission & now you can push your files into /sdcard by using following command from your host shell.
`adb push filename.mp3 /sdcard,`
where filename.mp3 could be any file that you want to push into Android Emulator.
Hope this helps :)
Ensure two things in the AVD manager utility for the emulator:
SD Card size is mentioned e.g. 512.
From the Hardware tag, press New and select "SD Card Support" from the drop down menu.
Now, start the emulator. SD Card shall now support writing as well.
Android studio version 0.8.9 and above has a bug creating AVDs.
See Issue 78434.
Workaround
go to your ADV folder in .android folder and find your AVD config.ini
open it with a text editor that can handle unix newlines. (Notepad will run the lines together since they don't have CR-LFs.)
change hw.sdCard=no to hw.sdCard=yes
this should work for everyone in new builds
Maybe it sounds stupid but it worked for me when I had the same problem: delete the created avd and create one again through AVD Manager with a sd card of, for example, 512MB.
Check that both have the correct permissions and if not, try to change them with chmod.
And if everything still fails, repeat the process but creating both avd and sd card manually via terminal:
android create avd -n my_avd -t 7
mksdcard -l e 512M mysdcard.img
emulator -avd my_avd -sdcard mysdcard.img
Hope that helps!
I think the problem here is that you forgot to set SD card size
Follow these steps to make it work:
step1: close running emulator
step2: open Android Virtual Device Manager(eclipse menu bar)
step3: choose your emulator -> Edit -> then set SD card size
This works well in my emulator!
Make sure that you had given a value which is greater than zero for SD Card size in the Create AVD Window for that particular emulator.
mount -o remount, rw /sdcard
this is the correct way to remount your sdcard using your emulator.
I tried #user2002993 great help but it one place it need to be a little edit so I edited and here what worked for me on Android Studio, emulator android 5.
Go to your adb folder right click on blank area and select "open command window here" or if you installed adb by adb-installer open cmd and type these commands:
adb devices
It should show your emulator number and detail. Then followed command here:
adb shell
Now it should show you prompt #
su
mount -o rw,remount rootfs
chmod 777 /mnt/sdcard
exit
exit
Yeah double exit needed, now your prompt of adb shell is gone. Put a file in to your adb folder and give this command and see if it got fixed.
adb push "your file name like : 1.jpg" /sdcard/
or
adb push "your file name like : 1.jpg" /storage/sdcard/
Now in cmd it shoudl show you transfer time instead of creepy read-only thing 😊
I increased the virtual memory of sdcard up to 512 MB for the emulator and that was enough
I guess, you didn't insert memory size at the time of creating avd. you can do that by editing the avd.
make sure that you have the correct permissions.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Windows uses backward slashes, linux uses forward slashes.
sometimes this can cause of a very simple reason,
go to your list in eclipse and check whether you have set SDCard size
I had this problem on Android L developer preview, and, at least for this version, I solved it by creating an sdcard with a size that had square 2 size (e.g 128M, 256M etc)
In adb version 1.0.32 and Eclipse Luna (v 4.4.1).
I found a directory in the avd /mnt/media_rw/sdcard that you can write to using the adb command.
adb push {source} /mnt/media_rw/sdcard
There appears to be rw access to this directory.
Hope this helps :-)
Alternate way:
Dismount the drive (from settings/storage) and re-mount the sdcard
also fixes the problem. (verify by moving a file from internal storage to sdcard)
In any case, this simple method saved my butt this time :)
Give any size to Sdcard in Emulator
unchecked the read only option from c:\user...android\avd -> properties
push a file through file explorer
restart the Emulator
It will definitely works
With me in the end helped
In the emulator to run applications manager
and setting permissions for storage.
Try this in a Terminal Emulator as root:
restorecon -v -R /data/media