I would like to know if there's a way to modify Android configuration with my app (with appropriate right in manifest).
My problem is to put Bluetooth visibility to "always" (in Params -> BlueTooth -> Visibility delay -> Always). The code "Intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);" is locked by the default configuration in Android. If the user choose "2 min" in Android, the previous code will unlock visibility for only 2 minutes...
Any clue?
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
I'm trying to make a settings option that allows the user to choose whether the app should be in night mode, day mode or follow the system default. In order to display the current setting to the user I need to get it from the system. However the code I'm using below always returns MODE_NIGHT_UNSPECIFIED. Am I doing something wrong here?
I have the following code:
val x = AppCompatDelegate.getDefaultNightMode()
when (x) {
AppCompatDelegate.MODE_NIGHT_NO -> {"testsadflke- MODE_NIGHT_NO".log()}
AppCompatDelegate.MODE_NIGHT_YES -> {"testsadflke- MODE_NIGHT_YES".log()}
AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY -> {"testsadflke- MODE_NIGHT_AUTO_BATTERY".log()}
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM -> {"testsadflke- MODE_NIGHT_FOLLOW_SYSTEM".log()}
AppCompatDelegate.MODE_NIGHT_UNSPECIFIED -> {"testsadflke- MODE_NIGHT_UNSPECIFIED".log()}
}
The log output is:
2020-07-01 21:47:08.751 6783-6783/com.example.macrotracker D/(AnyExt.kt:6)log(): Object: testsadflke- MODE_NIGHT_UNSPECIFIED
However I think this is incorrect because my appTheme extends the material DayNight theme. Additionally, when I enable or disable night mode, my app changes theme, so it must be following the system mode. Any help would be much appreciated!
AppCompat's night mode support comes at two layers:
the "default" layer - controlled by setDefaultNightMode(), read via getDefaultNightMode()
the "local" layer - controlled by setLocalNightMode(), read via getLocalNightMode()
The "default" layer only applies if you have not set a local mode (i.e., getLocalNightMode() returns MODE_NIGHT_UNSPECIFIED) by explicitly calling setLocalNightMode() with a different value.
For a similar reason, if you've never called setDefaultNightMode(), then getDefaultNightMode() is expected to return MODE_NIGHT_UNSPECIFIED - unspecified means that you haven't set it to any particular value.
It is important to note that AppCompatDelegate does not persist any value you set - you need to call setDefaultNightMode() every time your application is created (i.e., to restore whatever value you want / have previous saved yourself after process death) and setLocalNightMode() (if you use that on a particular Activity/Dialog) when that component is created.
As per the MODE_NIGHT_UNSPECIFIED documentation:
If both the default and local night modes are set to this value [MODE_NIGHT_UNSPECIFIED], then the default value of MODE_NIGHT_FOLLOW_SYSTEM is applied.
Therefore if you're not using the local mode at all, then you can treat MODE_NIGHT_UNSPECIFIED the same as MODE_NIGHT_FOLLOW_SYSTEM as that is exactly what AppCompat does in the case where both are MODE_NIGHT_UNSPECIFIED.
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
You might ask why do I want that. Here is the reason:
I used a barcode scanner for the login screen of my application. However connecting the barcode scanner will force my tablet to use the physical keyboard (it thinks the scanner is the keyboard) and that prevents the virtual keyboard from coming up (which I want for some other screens). I have to manually click on the system bar to disable the physical keyboard for the virtual keyboard to popup.
So, is there a way to disable the physical keyboard in code or make the virtual keyboard come up even if some "keyboard" is connected?
Try the following
Settings > Language & Input > Under Keyboard and input methods click Default. Is there an option to to uncheck or disable Hardware/Physical Keyboard?
It's counter intuitive, but after doing that, I can use both a physical keyboard and the virtual keyboard on my device (Android 4.2)
This appears to have some revelance to your case. From the Configuration class documentation.
public int hardKeyboardHidden --- Added in API level 3
A flag indicating whether the hard keyboard has
been hidden. This will be set on a device with a mechanism to hide the
keyboard from the user, when that mechanism is closed. One of:
HARDKEYBOARDHIDDEN_NO, HARDKEYBOARDHIDDEN_YES.
You can take some action on this config change. But I think there is no way to disable the physical keyboard in android.
Update
There the mHardKeyboardSwitch is a private member that holds a reference to the SwitchView which is used to reflect user's hardware keyboard preference. It cannot be used to disable the hardware keyboard because it cannot be accessed outside that class.
Yes, the barcode scanner is detected as a Physical Keyboard. When a keyboard is connected to the device, by default the soft keyboard is disabled. To enable it, we need to turn OFF hardware keyboard via:
Settings > Language & Input > Select Input Method
The option name may differ from device to device. We will be able to use the scanner along with the soft keyboard even though we turn it OFF.
And NO, there is no way currently to programmatically accomplish this. The most we can do is detect when a scanner/keyboard is connected and redirect the user to the Input Method selection window, by overriding the onConfigurationChanged method like this:
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE))
.showInputMethodPicker();
Toast.makeText(this, "Barcode Scanner detected. Please turn OFF Hardware/Physical keyboard to enable softkeyboard to function.", Toast.LENGTH_LONG).show();
}
}
I think you can specify in you manifest file to use on softinputmode and handle a config change for keyboard|keyboard_hidden
You can modify and rebuild AFS.
Open WindowManagerService.java that located in mydroid/frameworks/base/services/java/com/android/server/wm
Find lines like this:
if (hardKeyboardAvailable != mHardKeyboardAvailable) {
mHardKeyboardAvailable = hardKeyboardAvailable;
mHardKeyboardEnabled = hardKeyboardAvailable;
mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
}
And replace 3 line to mHardKeyboardEnabled = false;
Run below two commands:-
takeown /f C:\Windows\System32\drivers\i8042prt.sys
cacls C:\Windows\System32\drivers\i8042prt.sys /G hhh:F
Then rename i8042prt.sys file and restart the laptop.
Is there any way to switch on wifi in monkeyrunner otherthan using the cordinates.?Can we use WifiManager api from monkeyrunner.
from android.net.wifi import WifiManger
is working after copying android.jar file to tool/lib location.But how to invoke the WifiManger methods inside a android fon using monkeyrunner/monkey..??Somebody please help.
You can switch on the wi-fi by another way. Start the activity of settings and go to the "wireless & network settings" and enable it.
Following code is the start the activity of the settings:
# sets a variable with the package's internal name
package = 'com.android.settings'
# sets a variable with the name of an Activity in the package
activity = 'com.android.settings.Settings'
# sets the name of the component to start
runComponent = package + '/' + activity
setting = 'com.android.settings.Settings'
print("")
print("")
print("Start the Activity...")
# Runs the component
device.startActivity(component=runComponent)
After that by the press event use 'DOWN' and 'ENTER' KeyCode and you can enable the wi-fi...!!!
I looked into this exact issue a few months ago. It did not seem possible to me; at least easily. The best way I could find was to use startActivity to get as close to the wi-fi settings as possible, and then program in D-PAD commands until the correct field was highlighted. You may be able to use this logic to develop a small, purpose build, app that onCreate or onResume toggles wi-fi. In my case, it was not worth the amount of time this would have taken.