The iCoder
The iCoder

Reputation: 1444

How to open device dock settings programmatically?

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);

enter image description here enter image description here

Upvotes: 7

Views: 4510

Answers (2)

jtt
jtt

Reputation: 13541

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

Upvotes: 1

crazylpfan
crazylpfan

Reputation: 1088

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.

Upvotes: 5

Related Questions