Quick Settings are tiles displayed in the Quick Settings panel. Users can tap these tiles to quickly complete recurring tasks. This document shows you how to create a custom Quick Settings tile for QR Code payments.
Before continuing, be sure you're familiar with general instructions and best practices for creating custom Quick Settings tiles for your app.
To create your tile, follow these steps:
- Create your custom icon.
To launch the QR Code payment, fill in the
onClick()
method. Long-tapping a tile prompts the App Info screen for the user. To override this behavior and instead launch an activity for setting preferences, add an<intent-filter>
to one of your activities withACTION_QS_TILE_PREFERENCES
.Kotlin
import android.service.quicksettings.TileService // Called when the user taps on your tile in an active or inactive state. override fun onClick() { // Create Intent, replace MainActivity::class.java with QR Code Activity val intent = Intent(this, MainActivity::class.java) // Create PendingIntent val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE) if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { startActivityAndCollapse(pendingIntent) } else { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) startActivityAndCollapse(intent) } }
Java
import android.service.quicksettings.TileService; // Called when the user taps on your tile in an active or inactive state. @Override public void onClick() { // Create Intent, replace MainActivity.class with QR Code Activity Intent intent = new Intent(MyQSTileService.this, MainActivity.class); // Create PendingIntent PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE); if (VERSION.SDK_INT >= VERSION_CODES.UPSIDE_DOWN_CAKE) { startActivityAndCollapse(pendingIntent); } else { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivityAndCollapse(intent); } }
To protect users' sensitive payment information, perform only safe actions on securely-locked devices.
Kotlin
import android.service.quicksettings.TileService override fun onClick() { val intent = Intent(this, MainActivity::class.java) val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE) // ... if (isSecure()) { startActivityAndCollapse(pendingIntent) } else { unlockAndRun { startActivityAndCollapse(pendingIntent) } } // ... }
Java
import android.service.quicksettings.TileService; @Override public void onClick() { Intent intent = new Intent(MyQSTileService.this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE); ... if (isSecure()) { startActivityAndCollapse(pendingIntent); } else { unlockAndRun(new Runnable() { @Override public void run() { startActivityAndCollapse(pendingIntent); } }); } ... }
When first introducing this feature, prompt the user to add your tile.