1

I'm able to add quick settings tile to my app statically using service and declaring it in manifest by

<service android:name=".QuickSettingsService"
            android:icon="@drawable/ic_qt_24dp"
            android:label="@string/qt_label"
            android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
            <intent-filter>
                <action android:name="android.service.quicksettings.action.QS_TILE" />
            </intent-filter>
 </service>

And I'm able to add the above tile to quick settings and interact with it. But I need to allow them to be added dynamically. Like, I provide setting in my app to turn certain tiles on or off and the tile reflects the availability in available tiles in quick tiles edit menu.How do I do that?

pRaNaY
  • 24,642
  • 24
  • 96
  • 146
Vijai
  • 1,067
  • 2
  • 11
  • 25
  • "But I need to add them dynamically" -- the user adds tiles. You simply offer them to the user. "I provide setting in my app to turn certain tiles on or off" -- the user can use the system UI to add and remove tiles. – CommonsWare Aug 28 '16 at 12:57
  • @CommonsWare What I meant is, dynamically bind the available tiles for the user to add/remove from the quick settings drawer. So If the user disables the tile in the app, it is not shown on the quick settings dropdown for them to be added. Question edited – Vijai Aug 28 '16 at 13:03
  • So unless the tile is enabled in your app it won't even appear in the system settings for showing/hiding tiles? I haven't tested it but try disabling your tile service http://stackoverflow.com/questions/17409907/how-to-enable-and-disable-a-component – Eugen Pechanec Aug 28 '16 at 13:07
  • 3
    You are welcome to try enabling and disabling each individual `TileService` subclass using `PackageManager`. That being said, I would not be surprised if Android does not handle this well, and I am skeptical that this behavior is in the users' best interests. – CommonsWare Aug 28 '16 at 13:07
  • @CommonsWare I guess what you are suggesting is same as what Eugen is suggesting? Also, if I go about toggling the service, how about it surviving the reboot? Or I should be adding bootreceiver to handle that? – Vijai Aug 28 '16 at 13:17
  • "I guess what you are suggesting is same as what Eugen is suggesting?" -- yes. "how about it surviving the reboot?" -- a component's enabled status should survive a reboot. – CommonsWare Aug 28 '16 at 13:30

1 Answers1

2

Solved this issue by enabling and disabling the service via package manager.

if (state) {
   pm.setComponentEnabledSetting(componentName,
   PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
   PackageManager.DONT_KILL_APP);
} else
   pm.setComponentEnabledSetting(componentName,
   PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
   PackageManager.DONT_KILL_APP);

Where state is a boolean representing the switch for the service

Vijai
  • 1,067
  • 2
  • 11
  • 25