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);}}
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 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)."]]