TL;DR: how do I remove support for touchscreen in the emulator, in the new ADT 21? Basically, I want to simulate a (dpad and qwerty)-only device. Details below.
Neither the new "Device Definitions" nor the "Android Virtual Devices" show a way to edit the hardware, as the old dialog is not available anymore.
Aware of that, I edited the virtual device config.ini file myself, before starting the emulator, to include the hw.touchscreen line. It had no effect, and this code:
Toast.makeText(getActivity(),
String.valueOf(getActivity().getPackageManager().hasSystemFeature("android.hardware.touchscreen")),
Toast.LENGTH_SHORT).show();
shows true. I suspected this has something to do with the new (to me) hw.device.name option, which is related to the new Device Definitions tab. And there is a devices.xml file, which includes a touchscreen definition (relevant lines):
<d:device>
<d:name>3.5 nHD</d:name>
<d:manufacturer>User</d:manufacturer>
<d:meta/>
<d:hardware>
<d:screen>
<d:screen-size>normal</d:screen-size>
<d:diagonal-length>3.50</d:diagonal-length>
<d:pixel-density>mdpi</d:pixel-density>
<d:screen-ratio>long</d:screen-ratio>
<d:dimensions>
<d:x-dimension>360</d:x-dimension>
<d:y-dimension>640</d:y-dimension>
</d:dimensions>
<d:xdpi>209.80</d:xdpi>
<d:ydpi>209.80</d:ydpi>
<d:touch>
<d:multitouch>jazz-hands</d:multitouch>
<d:mechanism>finger</d:mechanism>
<d:screen-type>capacitive</d:screen-type>
</d:touch>
</d:screen>
(...)
I've tried just removing the d:touch section. Still, no effect. Any ideas?
Related
Good morning. I need to test my application in Chrome OS, but without the "touch screen"
I used this guide to run a emulation of Chrome OS:
https://www.groovypost.com/howto/chrome-os-android-studio/
Ok, I succeeded to run it, I activated the debugging mode and I activated the adb debugging....finally everything is working and I can run my application on it.
The problem is, I want to test it without touchscreen.
I found the hw.screen property inside
~/.android/avd/<machine-name>.avd/hardware-qemu.ini
that was set to hw.screen = multi-touch.
WOW, exactly what I want, let's change it to no-touch.
Inside ~/Android/Sdk/emulator/lib/hardware-properties.ini you can see
# Touch screen type
name = hw.screen
type = string
enum = touch, multi-touch, no-touch
default = multi-touch
abstract = Touch screen type
description = Defines type of the screen.
so, no-touch is a valid option.
The problem is, even if I change it, every time I restart the emulator, it is set back to multi-touch.
I also tried to change the option directly in ~/Android/Sdk/emulator/lib/hardware-properties.ini, that should contain the default option, but no luck...
Someone can tell me who is overwriting this property each time I start the emulation?
How can I remove the touch screen in the emulation?
Launch the emulator from the command line and use the flag -screen no-touch. This is because the emulator overrides the config in the .ini file. That gives no touch screen but the mouse wasn't usable, at least on Windows.
See the docs for more details
When creating an avd, starting it for the first time and then trying to close the emulator, the user will be prompted with a dialog reading:
Do you want to save the current state for the next quick boot?
Note: Saving the snapshot may take longer because free RAM is low.
I would like to save this parameter, before starting the emulated device, within its config.ini file.
However I'm not clear on which option it is.
Things I tried:
Adding these lines to the config.ini
fastboot.chosenSnapshotFile=
fastboot.forceChosenSnapshotBoot=no
fastboot.forceColdBoot=no
fastboot.forceFastBoot=yes
Creating an additional file within the config.ini directory of the avd called quickbootChoice.ini that simply reads:
saveOnExit = true
Non of which helped, on every first shutdown of the emulated device this dialog pops up...
Thanks in advance
According to https://android.googlesource.com/platform/external/qemu/+/refs/heads/emu-master-dev/android/android-emu/android/skin/qt/tool-window.cpp the popup does not appear if the method returns based on this:
if (saveOnExitChoice == SaveSnapshotOnExit::Always &&
(fc::isEnabled(fc::QuickbootFileBacked) ||
(!savesWereSlow && !hasLowRam))) {
return true;
}
Setting QuickbootFileBacked = on in .android/advancedFeatures.ini fixed it for me. See https://androidstudio.googleblog.com/2018/08/android-emulator-28.html.
You can configure this setting in Android Studio, see this answer for instructions: Android emulator - Don't save state by default
If you are starting the emulator from the command line. Then provide the -no-snapshot-save parameter, to prevent it from saving.
emulator #Nexus_5X_API_23 -no-snapshot-save
reference: https://developer.android.com/studio/run/emulator-commandline
Downloaded Xamarin Camera2Basic project
Initially all works correctly as it's begin tested in Visual Studio 2017 emulator.
Commented out code inside "CameraCaptureStillPictureSessionCallback.cs" as shown below to allow the still image captured to be displayed on the emulator screen after clicking the "Take Picture" button:
public override void OnCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result)
{
//Owner.ShowToast("Saved: " + Owner.mFile);
//Log.Debug(TAG, Owner.mFile.ToString());
//Owner.UnlockFocus();
}
Clicking the "Take Picture" button hides itself, and shows another button labeled "Retake Picture" on the screen (which I added after the fact and the code is located in the Camera2BasicFragment.cs file, but the code is inconsequential to the issue).
Clicking the now visible "Retake Picture" button does the following:
Hides itself
Shows the "Take Picture" button
Calls UnlockFocus()
UnlockFocus() allows the camera's stream to display continuously on the screen instead of the still image captured previously.
Now, when I click the "Take Picture" button again (to attempt to capture a new still image), the app crashes.
Visual studio does not provide any meaningful error messages. The closest useful bit of information are the error messages displayed int the Device Log:
07-26 23:29:03.201 10.1" Marshmallow (6.0.0) XHDPI Tablet Error 6987 BufferQueueProducer [ImageReader-640x480f100m2-6987-0] dequeueBuffer: can't dequeue multiple buffers without setting the buffer count
07-26 23:29:07.174 10.1" Marshmallow (6.0.0) XHDPI Tablet Error 6987 RequestThread-0 Hit timeout for jpeg callback!
07-26 23:29:03.201 10.1" Marshmallow (6.0.0) XHDPI Tablet Error 6987 Legacy-CameraDevice-JNI LegacyCameraDevice_nativeProduceFrame: Error while producing frame Function not implemented (-38).
I'm not sure what to make of these errors, or which settings/code to change to allow the "Retake Picture" functionality to work without crashing the app.
Any suggestions?
EDIT 1:
Per request, where is a link to the project as I currently have it.
https://drive.google.com/file/d/0B7OSuA_ybXcFb081T210UlQzZkE/view?usp=sharing
Here is some other seemingly pertinent information:
This code was run using:
a. Windows 10 Pro, Visual Studio 2017 Community, Android Emulator
For Visual Studio, Hyper-v Virtual Manager, Android 6.0
(Marshamallow SDK 23), Tablet sized template
b. 2013 Macbook Pro, Visual Studio For Mac (latest version), default
emaulator, Android 6.0 (Marshmallow SDK 23), Tablet sized template.
The failure to take snapshot after second "LockFocus" call is observed in both environments.
The Mac made it easier to find some more meaninful errors:
a. The error I saw happened on method "produceFrame" inside
LegacyCameraDevice.java
I've the problem with this demo also, The real problem behind this is about the IOnImageAvailableListener, it will not trigger the OnImageAvailable method to save the picture...
After read the code, i found out that the demo is broken, it missing some piece.
In the Camera2BasicFragment.cs, in the OnCreateMethod, you will need to add this line
mCaptureCallback = new CameraCaptureListener() { Owner = this};
The entire method should look like this:
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
mStateCallback = new CameraStateListener() { owner = this };
mSurfaceTextureListener = new Camera2BasicSurfaceTextureListener(this);
// fill ORIENTATIONS list
ORIENTATIONS.Append((int)SurfaceOrientation.Rotation0, 90);
ORIENTATIONS.Append((int)SurfaceOrientation.Rotation90, 0);
ORIENTATIONS.Append((int)SurfaceOrientation.Rotation180, 270);
ORIENTATIONS.Append((int)SurfaceOrientation.Rotation270, 180);
}
The interesting thing is, if you run this on emulator, nothing will happened, because in the CameraCaptureListener.cs file, this will always return 0, not ControlAFState.FocusedLocked or ControlAFState.InActivate
Integer afState = (Integer)result.Get(CaptureResult.ControlAfState);
Event if i hack the If method to be able to run jump into next step, the method OnImageAvaiable of ImageAvailableListener.cs will never be triggered by emulator. But if i run on the real device, it ran fine ?!
So the fix is:
1. Add the code above like i explained on the onCreate function.
2. Don't use emulator to run Camera2, it's buggy.
Hope it help :)
If you are still interested; IOnImageAvailableListener not trigger OnImageAvailable method in Visual Studio Emulator For Android.
Code is correct but Visual Studio Emulator For Android have a bug. I hope they fix it as soon as possible. On the other hand you can try your code in Xamarin by using Android Studio Emulator without any bug. It is easy and you dont need to know anything about Java or Android Studio Just follow the below steps
Install Android Studio with virtual device
Close Hper-v on your pc (windows -> control panel -> programs -> programs and features -> Turn windows features on or off)
Open android studio -> Tools -> Avd Manager -> Create Virtual Device
Visual studio detect the virtual device just use it on Visual Studio Xamarin
hope it help
I developed a simple javafx application to be ported in Android Environment, however I cant type any characters in the TextField. I guess its a bug, how to fix this one?
Th problem on galaxy S5 android 5.0.1 is not present but on galaxy tab 4 android 5.0.2 it doesn't work i type but none is displyed.
Tried with normal textfield. And the problem persist also I have added the properties .
Another strange rhig is that the space where recognizer. And the del button . The text not
THe code by example is very easy
Rectangle2D visualBounds = Screen.getPrimary().getVisualBounds();
double width = visualBounds.getWidth();
double height = visualBounds.getHeight();
TextField tt= new TextField();
tt.setTranslateY(-150);
StackPane stackPane = new StackPane();
stackPane.getChildren().addAll(tt);
borderpane.setCenter(stackPane);
Scene scene = new Scene(borderpane, width, height);
stage.setScene(scene);
Assuming that CustomTextField is just a custom TextField, this is a known issue, not related to the CustomTextField itself, given that it works in other device.
If you debug it:
./adb logcat -v threadtime
you surely find an exception that explains the issue: a StackOverFlow exception.
On older devices it can be solved adding this: create a java.custom.properties file, and include in it this property:
monocle.stackSize=128000
You may also include this one:
monocle.platform=Android
(it will be soon included by default in the next version)
Put the file at the root of your classpath, e.g. in the folder src/android/resources of your project.
Build and deploy the project on your mobile and check again.
I have to open device dock setting through code. I searched but not got proper solution. In samsung galaxy s-3 it goes through settings->Accessory. I tried following code but didn't work
startActivityForResult(new Intent(Settings.System.getString(getContentResolver(), DOCK_SETTING)), 0);
Correct me if I'm wrong, but I believe the reason this doesn't work, (and why you weren't able to find the appropriate Activity Action in the Android Settings), is because Accessory appears to be provided by Samsung for its Galaxy devices. Therefore, you won't be able to find it in the standard Android SDK (yet?).
I'm currently trying to figure out a workaround, so I'll edit this post if I find a solution.
EDIT: Looks like JoxTraex found a way for you to edit the settings via:
Settings.System.putInt(getContentResolver(), "dock_sounds_enabled", 1);
In addition, if you need to modify these settings when the user has docked their device, you should create a BroadcastReceiver to listen for the ACTION_DOCK_EVENT broadcast.
I was able to achieve this through looking at the settings and configuring the setting programatically:
android.provider.Settings.System.putInt(getContentResolver(), "dock_sounds_enabled", 1);
You need the permission:
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
The code above will write to the settings that enables the dock sound settings on the samsung s3. However; instead of just writing it you should tell the user that the setting is disabled and you need it enabled and allow the user to confirm they want to enable it via a dialog.
On another note, I don't think its possible to go directly to the settings->accessory screen because its was a custom settings added by Samsung. This action is not provided in the Android SDK, so it would take a while to derive what is the actual action or even if it exists.
And if you want to confirm it just query it:
String where = "name = 'dock_sounds_enabled'";
Cursor c = getContentResolver().query(android.provider.Settings.System.CONTENT_URI, null, where, null, null);
Update
Steps for how to handle the dialog's response for configuring the dock setting:
Grab the setting.. if it's 0, bring up the dialog to enable it, otherwise continue with your processing
Once the dialog is up and the user confirms they want to enable it:
Confirm: Put a 1 into the dock sounds then close the dialog
Deny: Don't set the dock setting then close dialog