I'm trying to add a quick settings toggle to my app in Android N. The quick tile shows up, but it doesn't do anything when clicked. I can see the visible feedback when touched, so I know that it is recognizing the click, but it doesn't do anything when clicked.
Here's my service code:
public class QuickSettingTileService extends TileService {
public QuickSettingTileService()
{
}
@Override
public IBinder onBind(Intent intent)
{
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startID)
{
//some setup code is here
return START_STICKY;
}
@Override
public void onClick()
{
Context context = getApplicationContext();
Toast.makeText(context, "Quick Setting Clicked", Toast.LENGTH_SHORT).show();
//Toggle code is here
}
}
My manifest has the code almost directly copied from the documentation. Only slight modifications have been made:
<service
android:name=".QuickSettingTileService"
android:label="@string/app_name"
android:icon="@drawable/quick_toggle_off"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
</service>
The service is started upon opening the app:
Intent serviceIntent = new Intent(this, QuickSettingTileService.class);
startService(serviceIntent);
Just remove these lines from your QuickSettingTileService class
@Override
public IBinder onBind(Intent intent)
{
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startID)
{
//some setup code is here
return START_STICKY;
}
There is no need to override onBind() or onStartCommand() on a TileService.
Also, you don't need to explicitly start this service. The permission and intent-filter in the manifest will make sure Android OS will start your service when your tile is added to the Notification bar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With