How to open a dialog from Quick settings Tile?

764 views Asked by At

I am developing an app for Quick settings Tile. I want to open a layout or a custom dialog when user click on the tile, whichever is a good option. Assume this as a custom dialog. I tried many examples, but I got no luck!

Thank you in advance.

2

There are 2 answers

0
Mehul Boghra On

You just have to @Override method of Tile service.

@Override
public void onClick() {
    super.onClick();
    Tile tile = getQsTile();
    switch (tile.getState()) {
        case Tile.STATE_INACTIVE:
            // write code for start service or open activity according to your prefrrance 
            StaticUtils.closeNotificationTopPanel(this);
            tile.setLabel(getString(R.string.service_running));
            updateTileState(Tile.STATE_ACTIVE);
            break;
        case Tile.STATE_ACTIVE:
            updateTileState(Tile.STATE_INACTIVE);
            break;
        default:
            updateTileState(Tile.STATE_INACTIVE);
            break;
    }
}
  • when you Click of tile service button you have to close the notification panel below code will help for that.

    public static void closeNotificationTopPanel(Context context) {
       Intent closeIntent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
       context.sendBroadcast(closeIntent);
    }
    
  • below method will help you to change the tile state and name of a button according to state.

     private void updateTileState(int state) {
         Tile tile = getQsTile();
         if (tile != null) {
             tile.setState(state);
             Icon icon = tile.getIcon();
             switch (state) {
                 case Tile.STATE_ACTIVE:
                     icon.setTint(Color.WHITE);
                     break;
                 case Tile.STATE_INACTIVE:
                 case Tile.STATE_UNAVAILABLE:
                 default:
                     icon.setTint(Color.GRAY);
                     break;
             }
             tile.updateTile();
         }
     }
    
0
Nimesh Patel On

Try to use this link: http://wintechtutorials.com/blog/android-customize-quick-setting-tiles-7-0-nougat/

Here in this link they use default Alert dialog. Try to create custom dialog as per need. Hope this will work for you.