Create a QR Code Payment Quick Settings tile
Stay organized with collections
Save and categorize content based on your preferences.
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
importandroid.service.quicksettings.TileService // Called when the user taps on your tile in an active or inactive state. overridefunonClick(){ // Create Intent, replace MainActivity::class.java with QR Code Activity valintent=Intent(this,MainActivity::class.java) // Create PendingIntent valpendingIntent=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
importandroid.service.quicksettings.TileService; // Called when the user taps on your tile in an active or inactive state. @Override publicvoidonClick(){ // Create Intent, replace MainActivity.class with QR Code Activity Intentintent=newIntent(MyQSTileService.this,MainActivity.class); // Create PendingIntent PendingIntentpendingIntent=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
importandroid.service.quicksettings.TileService overridefunonClick(){ valintent=Intent(this,MainActivity::class.java) valpendingIntent=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_IMMUTABLE) // ... if(isSecure()){ startActivityAndCollapse(pendingIntent) }else{ unlockAndRun{ startActivityAndCollapse(pendingIntent) } } // ... }
Java
importandroid.service.quicksettings.TileService; @Override publicvoidonClick(){ Intentintent=newIntent(MyQSTileService.this,MainActivity.class); PendingIntentpendingIntent=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_IMMUTABLE); ... if(isSecure()){ startActivityAndCollapse(pendingIntent); }else{ unlockAndRun(newRunnable(){ @Override publicvoidrun(){ startActivityAndCollapse(pendingIntent); } }); } ... }
When first introducing this feature, prompt the user to add your tile.