How do I detect if Samsung Pay or Google Pay are the default Payment apps?

1.8k views Asked by At

I'm looking for a way to understand if the user is using Samsung Pay or Google Pay as the default payment app.

Reading from Tap and Pay documentation, you can use

override suspend fun isDefaultWallet(packageName: String, fullClassName: String): Boolean {
        val nfcManager = context.getSystemService(Context.NFC_SERVICE) as NfcManager
        val emulation = CardEmulation.getInstance(nfcManager.defaultAdapter)
        val componentName = ComponentName(packageName, fullClassName)
        return emulation.isDefaultServiceForCategory(componentName, CardEmulation.CATEGORY_PAYMENT)
}

For Google Pay:

  • package name: com.google.android.apps.walletnfcrel
  • class name: com.google.android.gms.tapandpay.hce.service.TpHceService

What are the values for Samsung Pay?

2

There are 2 answers

0
Otacon On

For Samsung Pay:

  • package name: com.samsung.android.spayfw
  • class name: com.samsung.android.spayfw.core.hce.SPayHCEService
0
Harinder Pal On

Try this, it worked for me:

@RequiresApi(api = Build.VERSION_CODES.R)
private boolean isGoogleWalletDefaultPaymentMethod(){
    NfcManager manager = (NfcManager) this.getSystemService(Context.NFC_SERVICE);
    CardEmulation cardEmulation = CardEmulation.getInstance(manager.getDefaultAdapter());
    if (cardEmulation.getDescriptionForPreferredPaymentService().equals("Google Pay"))
        return true;
    else
        return false;
}

Plus if you want to know the package name of Samsung pay it's this: com.samsung.android.spay