Create a QR Code Payment Quick Settings tile

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:

  1. Create your custom icon.
  2. Create and declare your TileService.

  3. 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 with 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 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);
    }
    }
  4. 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);
    }
    });
    }
    ...
    }
  5. When first introducing this feature, prompt the user to add your tile.

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2024年05月09日 UTC.