Java 类android.nfc.cardemulation.CardEmulation 实例源码

项目:external-nfc-api    文件:MainActivity.java   
@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);

CardEmulation cardEmulation = CardEmulation.getInstance(NfcAdapter.getDefaultAdapter(this));

boolean defaultService = cardEmulation.isDefaultServiceForAid(new ComponentName(this, ExternalNFCHostApduService.class), ExternalNFCHostApduService.AID);

if(!defaultService) {
    Log.d(TAG, "Expected default service for AID " + ExternalNFCHostApduService.AID);
}
Log.d(TAG, "Service AID is " + ExternalNFCHostApduService.AID);

enableBroadcast();

showHelpfulDialog();
  }
项目:SwipeYours    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    activityLog = (TextView) findViewById(R.id.activity_log);

    CardEmulation cardEmulationManager = CardEmulation.getInstance(NfcAdapter.getDefaultAdapter(this));
    ComponentName paymentServiceComponent =
            new ComponentName(getApplicationContext(), PaymentService.class.getCanonicalName());

    if (!cardEmulationManager.isDefaultServiceForCategory(paymentServiceComponent, CardEmulation.CATEGORY_PAYMENT)) {
        Intent intent = new Intent(CardEmulation.ACTION_CHANGE_DEFAULT);
        intent.putExtra(CardEmulation.EXTRA_CATEGORY, CardEmulation.CATEGORY_PAYMENT);
        intent.putExtra(CardEmulation.EXTRA_SERVICE_COMPONENT, paymentServiceComponent);
        startActivityForResult(intent, 0);
        log(TAG, "onCreate: Requested Android to make SwipeYours the default payment app");
    } else {
        log(TAG, "onCreate: SwipeYours is the default NFC payment app");
    }
}
项目:HandstandPay    文件:PayActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    this.context = getApplicationContext();
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pay);
    ButterKnife.bind(this);
    cardEmulation = CardEmulation.getInstance(NfcAdapter.getDefaultAdapter(getApplicationContext()));

}
项目:HandstandPay    文件:PayActivity.java   
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void setAsPreferredHceService() {
    boolean allowsForeground = cardEmulation.categoryAllowsForegroundPreference(CardEmulation.CATEGORY_PAYMENT);
    if (allowsForeground) {
        ComponentName hceComponentName = new ComponentName(context, HandstandApduService.class);
        cardEmulation.setPreferredService(PayActivity.this, hceComponentName);
    }
}
项目:HandstandPay    文件:PayActivity.java   
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void unsetAsPreferredHceService() {
    boolean allowsForeground = cardEmulation.categoryAllowsForegroundPreference(CardEmulation.CATEGORY_PAYMENT);
    if (allowsForeground) {
        ComponentName hceComponentName = new ComponentName(context, HandstandApduService.class);
        cardEmulation.unsetPreferredService(PayActivity.this);
    }
}
项目:HandstandPay    文件:DefaultPaymentAppUtil.java   
public static void ensureSetAsDefaultPaymentApp(Activity context) {
  NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(context);
  CardEmulation cardEmulation = CardEmulation.getInstance(nfcAdapter);
  ComponentName componentName = new ComponentName(context, HandstandApduService.class);
  boolean isDefault = cardEmulation.isDefaultServiceForCategory(componentName, CardEmulation.CATEGORY_PAYMENT);

  if (!isDefault) {
    Intent intent = new Intent(CardEmulation.ACTION_CHANGE_DEFAULT);
    intent.putExtra(CardEmulation.EXTRA_CATEGORY, CardEmulation.CATEGORY_PAYMENT);
    intent.putExtra(CardEmulation.EXTRA_SERVICE_COMPONENT, componentName);
    context.startActivityForResult(intent, REQUEST_CODE_DEFAULT_PAYMENT_APP);
  }
}
项目:MasterTap    文件:MainActivity.java   
/**
 * Check if PaymentService is the default NFC payment app, and if not request user to set it.
 */
private void checkDefaultPaymentApp() {
    CardEmulation cardEmulationManager = CardEmulation.getInstance(NfcAdapter.getDefaultAdapter(this));
    ComponentName paymentServiceComponent = new ComponentName(getApplicationContext(), PaymentService.class.getCanonicalName());
    boolean isPaymentServiceDefault = cardEmulationManager.isDefaultServiceForCategory(paymentServiceComponent, CardEmulation.CATEGORY_PAYMENT);
    if (!isPaymentServiceDefault) {
        Intent intent = new Intent(CardEmulation.ACTION_CHANGE_DEFAULT);
        intent.putExtra(CardEmulation.EXTRA_CATEGORY, CardEmulation.CATEGORY_PAYMENT);
        intent.putExtra(CardEmulation.EXTRA_SERVICE_COMPONENT, paymentServiceComponent);
        startActivityForResult(intent, 0);
    }
}
项目:external-nfc-api    文件:ExternalNFCHostApduService.java   
@Override
public void onCreate() {
    super.onCreate();
    Log.d(TAG, "Service created");

    CardEmulation cardEmulation = CardEmulation.getInstance(NfcAdapter.getDefaultAdapter(this));

    boolean defaultService = cardEmulation.isDefaultServiceForAid(new ComponentName(this, ExternalNFCHostApduService.class), AID);

    if(!defaultService) {
        throw new IllegalArgumentException("Expected default service for AID " + AID);
    }
    Log.d(TAG, "Service AID is " + AID);
}