Créer un bloc "Réglages rapides" pour le paiement par code QR
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Les Réglages rapides sont des blocs qui s'affichent dans le panneau Réglages rapides.
Les utilisateurs peuvent tapoter sur ces vignettes pour effectuer rapidement des tâches récurrentes.
Ce document explique comment créer un bloc "Réglages rapides" personnalisé pour un code QR
paiements.
Pour lancer le paiement par code QR, renseignez la méthode onClick(). Appuyer de manière prolongée
une vignette affiche l'écran Informations
sur l'application pour l'utilisateur. Pour ignorer ce comportement
et lancez à la place une activité permettant de définir des préférences, ajoutez un
<intent-filter> à l'une de vos activités avec
ACTION_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 Activityvalintent=Intent(this,MainActivity::class.java)// Create PendingIntentvalpendingIntent=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.@OverridepublicvoidonClick(){// Create Intent, replace MainActivity.class with QR Code ActivityIntentintent=newIntent(MyQSTileService.this,MainActivity.class);// Create PendingIntentPendingIntentpendingIntent=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);}}
Le contenu et les exemples de code de cette page sont soumis aux licences décrites dans la Licence de contenu. Java et OpenJDK sont des marques ou des marques déposées d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/07/27 (UTC).
[null,null,["Dernière mise à jour le 2025/07/27 (UTC)."],[],[],null,["# Create a QR Code Payment Quick Settings tile\n\nQuick Settings are tiles displayed in the [Quick Settings panel](https://support.google.com/android/answer/9083864).\nUsers can tap these tiles to quickly complete recurring tasks.\nThis document shows you how to create a custom Quick Settings tile for QR Code\npayments.\n\nBefore continuing, be sure you're familiar with general instructions and best\npractices for [creating custom Quick Settings tiles for your app](/develop/ui/views/quicksettings-tiles).\n\nTo [create your tile](/develop/ui/views/quicksettings-tiles#create-tile), follow these steps:\n\n1. [Create your custom icon](/develop/ui/views/quicksettings-tiles#create-custom).\n2. [Create and declare your `TileService`](/develop/ui/views/quicksettings-tiles#create-declare-tileservice).\n\n | **Note:** At this point, your custom tile service will appear in the Quick Settings menu. In order to see your custom tile upon pull down, [edit and\n | rearrange your tiles](https://support.google.com/android/answer/9083864).\n3. To launch the QR Code payment, fill in the `onClick()` method. Long-tapping\n a tile prompts the App Info screen for the user. To override this behavior\n and instead launch an activity for setting preferences, add an\n `\u003cintent-filter\u003e` to one of your activities with\n [`ACTION_QS_TILE_PREFERENCES`](/reference/android/service/quicksettings/TileService.html?utm_campaign=adp_series_quicksettingstiles_092916&utm_source=medium&utm_medium=blog#ACTION_QS_TILE_PREFERENCES).\n\n ### Kotlin\n\n ```kotlin\n import android.service.quicksettings.TileService\n\n // Called when the user taps on your tile in an active or inactive state.\n override fun onClick() {\n // Create Intent, replace MainActivity::class.java with QR Code Activity\n val intent = Intent(this, MainActivity::class.java)\n // Create PendingIntent\n val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE)\n if (android.os.Build.VERSION.SDK_INT \u003e= android.os.Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {\n startActivityAndCollapse(pendingIntent)\n } else {\n intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)\n startActivityAndCollapse(intent)\n }\n }\n ```\n\n ### Java\n\n ```java\n import android.service.quicksettings.TileService;\n\n // Called when the user taps on your tile in an active or inactive state.\n @Override\n public void onClick() {\n // Create Intent, replace MainActivity.class with QR Code Activity\n Intent intent = new Intent(MyQSTileService.this, MainActivity.class);\n // Create PendingIntent\n PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE);\n if (VERSION.SDK_INT \u003e= VERSION_CODES.UPSIDE_DOWN_CAKE) {\n startActivityAndCollapse(pendingIntent);\n } else {\n intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);\n startActivityAndCollapse(intent);\n }\n }\n ```\n4. To protect users' sensitive payment information, [perform only safe actions\n on securely-locked devices](/develop/ui/views/quicksettings-tiles#perform-only).\n\n ### Kotlin\n\n ```kotlin\n import android.service.quicksettings.TileService\n\n override fun onClick() {\n val intent = Intent(this, MainActivity::class.java)\n val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE)\n\n // ...\n\n if (isSecure()) {\n startActivityAndCollapse(pendingIntent)\n } else {\n unlockAndRun {\n startActivityAndCollapse(pendingIntent)\n }\n }\n // ...\n }\n ```\n\n ### Java\n\n ```java\n import android.service.quicksettings.TileService;\n\n @Override\n public void onClick() {\n Intent intent = new Intent(MyQSTileService.this, MainActivity.class);\n PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE);\n ...\n if (isSecure()) {\n startActivityAndCollapse(pendingIntent);\n } else {\n unlockAndRun(new Runnable() {\n @Override\n public void run() {\n startActivityAndCollapse(pendingIntent);\n }\n });\n }\n ...\n }\n ```\n5. When first introducing this feature, [prompt the user to add your\n tile](/develop/ui/views/quicksettings-tiles#prompt-user)."]]