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
Related
Is there a way to programatically set to read all views on talkback when certain action is fired (ex. button click) like it is when you tap with 3 fingers at once?
Thanks in advance.
Option 1 - if you just want to read some text: Use speech to text
please refer this answer
Text to speech is built into Android 1.6+. Here is a simple example of how to do it.
TextToSpeech tts = new TextToSpeech(this, this);
tts.setLanguage(Locale.US);
tts.speak("Text to say aloud", TextToSpeech.QUEUE_ADD, null);
More info: http://android-developers.blogspot.com/2009/09/introduction-to-text-to-speech-in.html
Option 2 - If you are particulate about using talkback
refer to this answer
Settings.Secure.putString(getContentResolver(),
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "pkgname/classname");
Settings.Secure.putString(getContentResolver(),
Settings.Secure.ACCESSIBILITY_ENABLED, "1");
Where the pkgname is your package name and the classname is the class name of your accessibility service.
If you need to enable several services or you don't want to destory the previous settings you might want to use : to seperate other services.
Also you might need to run as a system application and you might need the following permissions
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
this might not work on some versions of Android.
Also refer other answers to this question
PS. If it doesn't work, maybe you could find some luck in /data/data/com.android.providers.settings/databases/settings.db/secure, that's where Android stores secure settings.
I am writing an Android application to control a Nest thermostat. I was able to connect to it just fine and I can read the correct target temperature (turning the nob on the thermostat updates my TextView).
However, when I try to write the target temperature like this, nothing happens:
String thermostatID = mThermostat.getDeviceId();
mNest.thermostats.setTargetTemperatureF(thermostatID, 70);
I tried setting the HVAC mode first, in case I needed that, but this didn't work either:
String thermostatID = mThermostat.getDeviceId();
mNest.thermostats.setHVACMode(thermostatID, "cool");
mNest.thermostats.setTargetTemperatureF(thermostatID, 70);
The Textview flashes 70 for a brief second, but then shoots back up to 77 which is the target temperature that was set by the actual thermostat. Is this an issue with the SDK code for setTargetTemperatureF, or am I missing something simple here?
The permissions for the Nest thermostat are set on the Nest website. Visit https://developer.nest.com/products and sign in. You will be given a list of your products, all you need to do is select one and scroll down to permissions.
Note that after you change permissions, your mobile (or various platform) application will need to rerun authentication for this change to take place.
Try to modify your code as following, then you can set the target temperature.
mNest.setTargetTemperatureF(thermostatID, 70L, null);
I am using android settings inside my app(Launcher), so i can able to set a password protection, but far from that some tabs/device can able to access settings in different methods, so i am trying to create a password protection to the whole"system(Device)settings", how i can do it, is it possible ,
From my search i found this Android, Detect when other apps are launched
Can any one tell me how it works..
And it says that will not work from JellyBean and above. READ_LOGS permission is now reserved for system apps only, Is there any way for JellyBean.
If the solution proposed in the comment is ok with you, here I found this:
AlertDialog.Builder alert = new AlertDialog.Builder(MyFeedActivity.this);
LayoutInflater inflater=MyFeedActivity.this.getLayoutInflater();
//this is what I did to added the layout to the alert dialog
View layout=inflater.inflate(R.layout.dialog,null);
alert.setView(layout);
final EditText usernameInput=(EditText)layout.findViewById(R.id.dialogusername);
final EditText passwordInput=(EditText)layout.findViewById(R.id.dialogpassword);
I hope it will fit your needs.
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.
Background:
I recently purchased a Motorola XOOM Tablet along with the Desktop Dock and Bluetooth Keyboard accessories.
The dock and keyboard work great, but when I take the tablet off the dock to move away from my desk, the keyboard still remains paired with the device and I have to manually change the settings to use the soft keyboard. The same goes for when I set it back on the dock, I need to manually switch it back. It's not a huge problem, but it would be nice not to have to think about it.
So I tried downloading an app from the market that simply toggled Bluetooth on and off when connected or disconnected from a power source, which worked well for a while, but the background service would die after period and become useless until I manually restarted that.
TO THE POINT: I'm trying to write a little app/service for my tablet that will recognize when it has been docked/undocked and switch the "Use Physical Keyboard" setting accordingly.
I have started with a BroadcastReciever to recognize the Dock State:
public class DockBroadcastReciever extends BroadcastReceiver {
private final String DOCK_STATE_LABEL = "android.intent.extra.DOCK_STATE";
#Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
String message = (extras.getInt(DOCK_STATE_LABEL) == Intent.EXTRA_DOCK_STATE_UNDOCKED) ? "Undocked" : "Docked";
Toast toast = Toast.makeText(context, message, Toast.LENGTH_LONG);
toast.show();
}
}
But I'm having trouble figuring out the best way to update the setting after the event is fired. I've poked around some examples using InputMethodManager, but all the methods seem to need a specific EditText or some other input to bind to.
Furthermore, I can't seem to find a corresponding constant that represents that setting anywhere in the docs, but graphically, it is located here: http://i.stack.imgur.com/esFaw.png
Can anyone help me out with this?
I would like for there to be a solution for changing the setting, but I am open to other ideas as well.
I have an app that does something similar. It can toggle wifi and bluetooth based on power.
You'll need to register some of this stuff in the AndroidManifest.xml file.
http://code.google.com/p/futonic-wifioncall/source/browse/AndroidManifest.xml
Project Open Source Site: http://code.google.com/p/futonic-wifioncall/
This isn't the solution but hopefully will give guidance on what you're trying to accomplish.