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

下面列出了怎么用android.nfc.cardemulation.CardEmulation的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: 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");
    }
}
 
源代码2 项目: NFC-EMV-Reader   文件: HostPaycardActivity.java
@Override
protected void onResume() {
    super.onResume();
    LogUtil.d(TAG, "\"" + TAG + "\": Activity resume");

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (mCardEmulation != null && mCardEmulation.categoryAllowsForegroundPreference(CardEmulation.CATEGORY_PAYMENT)) {
            mCardEmulation.setPreferredService(this, new ComponentName(this, PaymentHostApduService.class));
        }
    }
}
 
源代码3 项目: NFC-EMV-Reader   文件: HostPaycardActivity.java
@Override
protected void onPause() {
    super.onPause();
    LogUtil.d(TAG, "\"" + TAG + "\": Activity pause");

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (mCardEmulation != null && mCardEmulation.categoryAllowsForegroundPreference(CardEmulation.CATEGORY_PAYMENT)) {
            mCardEmulation.unsetPreferredService(this);
        }
    }
}
 
源代码4 项目: 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()));

}
 
源代码5 项目: 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);
    }
}
 
源代码6 项目: 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);
    }
}
 
源代码7 项目: 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);
  }
}
 
源代码8 项目: external-nfc-api   文件: EchoHostApduService.java
@Override
public void onCreate() {
	super.onCreate();
	Log.d(TAG, "HCE service created");
	
	CardEmulation cardEmulation = CardEmulation.getInstance(NfcAdapter.getDefaultAdapter(this));
	
	boolean defaultService = cardEmulation.isDefaultServiceForAid(new ComponentName(this, EchoHostApduService.class), AID);
	
	if(!defaultService) {
		throw new IllegalArgumentException("Expected default service for AID " + AID);
	}
	Log.d(TAG, "HCE service AID is " + AID);
}
 
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

	setContentView(R.layout.activity_main);

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

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

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

	enableBroadcast();

	showHelpfulDialog();

	Intent intent = getIntent();

	hostCardEmulationBroadcastReceiver.onReceive(this, getIntent());
}