• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java CardEmulation类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中android.nfc.cardemulation.CardEmulation的典型用法代码示例。如果您正苦于以下问题:Java CardEmulation类的具体用法?Java CardEmulation怎么用?Java CardEmulation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

CardEmulation类属于android.nfc.cardemulation包,在下文中一共展示了CardEmulation类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: onCreate

点赞 4

import android.nfc.cardemulation.CardEmulation; //导入依赖的package包/类
@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();
  }
 

开发者ID:skjolber,
项目名称:external-nfc-api,
代码行数:19,
代码来源:MainActivity.java

示例2: onCreate

点赞 3

import android.nfc.cardemulation.CardEmulation; //导入依赖的package包/类
@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");
    }
}
 

开发者ID:dimalinux,
项目名称:SwipeYours,
代码行数:22,
代码来源:MainActivity.java

示例3: checkDefaultPaymentApp

点赞 3

import android.nfc.cardemulation.CardEmulation; //导入依赖的package包/类
/**
 * 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);
    }
}
 

开发者ID:jthuraisamy,
项目名称:MasterTap,
代码行数:15,
代码来源:MainActivity.java

示例4: onCreate

点赞 2

import android.nfc.cardemulation.CardEmulation; //导入依赖的package包/类
@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()));

}
 

开发者ID:handstandsam,
项目名称:HandstandPay,
代码行数:10,
代码来源:PayActivity.java

示例5: setAsPreferredHceService

点赞 2

import android.nfc.cardemulation.CardEmulation; //导入依赖的package包/类
@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);
    }
}
 

开发者ID:handstandsam,
项目名称:HandstandPay,
代码行数:9,
代码来源:PayActivity.java

示例6: unsetAsPreferredHceService

点赞 2

import android.nfc.cardemulation.CardEmulation; //导入依赖的package包/类
@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);
    }
}
 

开发者ID:handstandsam,
项目名称:HandstandPay,
代码行数:9,
代码来源:PayActivity.java

示例7: ensureSetAsDefaultPaymentApp

点赞 2

import android.nfc.cardemulation.CardEmulation; //导入依赖的package包/类
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);
  }
}
 

开发者ID:handstandsam,
项目名称:HandstandPay,
代码行数:14,
代码来源:DefaultPaymentAppUtil.java

示例8: onCreate

点赞 2

import android.nfc.cardemulation.CardEmulation; //导入依赖的package包/类
@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);
}
 

开发者ID:skjolber,
项目名称:external-nfc-api,
代码行数:15,
代码来源:ExternalNFCHostApduService.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)