7

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

The iCoder
  • 1,414
  • 3
  • 19
  • 39

2 Answers2

5

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.

crazylpfan
  • 1,038
  • 7
  • 9
1

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
JoxTraex
  • 13,423
  • 6
  • 32
  • 45
  • Can you just explain briefly how can i open that settings on button click or something so that user can set it. – The iCoder Mar 11 '13 at 07:56
  • Since you cannot go to the screen there is no way to go there, but you can write the setting you need via the dialog by executing the putInt method. @PavanMore – JoxTraex Mar 11 '13 at 08:05
  • This is only for enabling the "dock sound" though. If you need your application to react to the user docking the device, you'll have to have to listen for the appropriate broadcast. – crazylpfan Mar 11 '13 at 08:09
  • This should be implied, as in order to enable car dock mode you have to be selected to handle that Intent Action during the broadcast. @crazylpfan – JoxTraex Mar 11 '13 at 08:11
  • If this solved your initial problem then don't forget to accept it :) @PavanMore – JoxTraex Mar 12 '13 at 01:35