Reputation: 21
If there are multiple services(apps) capable of NFC HCE payments are installed. Those application services are visible under settings NFC Tap and Pay.
There are two AID group defined, one for payment and second for other cateogy.
How to programmatically change your application to be the default 'other category'service if it's not?
Below is the code that I'm executing, but dialog is not invoked to select running application for 'other category'. However for 'payment category' dialog is opened successfully. Below is the code:
CardEmulation cardEmulation = CardEmulation.getInstance(NfcAdapter.getDefaultAdapter(this));
boolean isDefaultCategorySelected = cardEmulation.isDefaultServiceForAid(new ComponentName(this, MyOffHostApduService.class), "F4100000040001");
if(!isDefaultCategorySelected(CardEmulation.CATEGORY_OTHER)){
Intent intent = new Intent(CardEmulation.ACTION_CHANGE_DEFAULT);
intent.putExtra(CardEmulation.EXTRA_CATEGORY, CardEmulation.CATEGORY_OTHER);
intent.putExtra(CardEmulation.EXTRA_SERVICE_COMPONENT, new ComponentName(this, MyOffHostApduService.class));
startActivityForResult(intent, REQUEST_CODE_SET_DEFAULT_TRANSIT_SERVICE);
return;
}
Upvotes: 2
Views: 2232
Reputation: 40849
You can't.
Global defaults are currently only supported for CATEGORY_PAYMENT. The resolution strategy for CATEGORY_OTHER is always set to SELECTION_MODE_ASK_IF_CONFLICT. Hence, your application must either be the only application that registers a certain AID group in CATEGORY_OTHER or Android will ask the user upon a transaction which app should be used.
You may be able to use CardEmulation.setPreferredService()
though in order to set your HCE service as the default while one of your activities is in the foreground.
Upvotes: 2