- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在研究 NFC,目前正在尝试为 Android 9.0 内置的 Open Mobile API 编写代码,但不了解在 SEService 中传递 Executor 参数的方式。
public class MainActivity extends Activity implements SEService.OnConnectedListener {
final String LOG_TAG = "NfcTest";
private SEService seService;
private Button button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this);
layout.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
button = new Button(this);
button.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
button.setText("Click Me");
button.setEnabled(false);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
Reader[] readers = seService.getReaders();
if (readers.length < 1)
return;
Session session = readers[0].openSession();
Channel channel = session.openLogicalChannel(new byte[]{
(byte) 0xF0, 0x51, (byte) 0xBC, 0x53, 0x54, 0x69, 0x64,
(byte) 0x4D, 0x6F, 0x62, 0x69, (byte) 0x6C,
(byte) 0x65, 0x2D, (byte) 0x49, 0x44});
byte[] respApdu = channel.transmit(new byte[]{
(byte) 0x90, 0x10, 0x00, 0x00, 0x00});
channel.close();
// Parse response APDU and show text but remove SW1 SW2 first
byte[] helloStr = new byte[respApdu.length - 2];
System.arraycopy(respApdu, 0, helloStr, 0, respApdu.length - 2);
Toast.makeText(MainActivity.this, new String(helloStr), Toast.LENGTH_LONG).show();
} catch (Exception e) {
Log.i(LOG_TAG, "Message: " + e.getClass().getCanonicalName());
if(e.getClass().isInstance(new NoSuchElementException()))
Toast.makeText(MainActivity.this, "NFC sim", Toast.LENGTH_LONG).show();
else if (e.getClass().isInstance(new IOException())){
Toast.makeText(MainActivity.this, "No sim found", Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(MainActivity.this, "Normal sim", Toast.LENGTH_LONG).show();
}
}
}
});
layout.addView(button);
setContentView(layout);
try {
seService = new SEService(this, this,this);
} catch (SecurityException e) {
Log.e(LOG_TAG, "Binding not allowed, uses-permission org.simalliance.openmobileapi.SMARTCARD?");
} catch (Exception e) {
Log.e(LOG_TAG, "Exception: " + e.getMessage());
}
}
@Override
protected void onDestroy() {
if (seService != null && seService.isConnected()) {
seService.shutdown();
}
super.onDestroy();
}
public void serviceConnected(SEService service) {
Log.i(LOG_TAG, "seviceConnected()");
button.setEnabled(true);
}
@Override
public void onConnected() {
}
}
问题发生在:
seService = new SEService(this, this,this);
接受了第一个和最后一个参数,中间一个执行器出现错误!
java.util.concurrent.Executor this
如何通过这个?
最佳答案
您收到此错误是因为构造函数 SEService
的第二个参数必须是 java.util.concurrent.Executor
。您的 MainActivity(this
对象)没有实现执行器。
SEService 使用这个执行器来调用回调方法。所以你必须自己创建这样一个执行器,以便将它传递给 SEService
。例如,您可以简单地创建一个带有单个工作线程的 ExecutorService
来处理回调:
ExecutorService pool = Executors.newSingleThreadExecutor();
seService = new SEService(this, pool, this);
但请注意,这些回调随后会在工作线程(而不是应用程序的主线程)上执行。因此,如果您想从回调中执行任何 UI 操作,则需要在 UI 线程上显式运行它们,例如
runOnUiThread(new Runnable() {
void run() {
button.setEnabled(true); // ... or some other UI modifications
}
});
关于java - SEservice中Executor的使用方法(Open Mobile API for Android 9.0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53758380/
Issue 2019/05/09 21:50:07.380 +0800 ERROR [ExecutorManager] [Azkaban] No active executors found
我的问题是:使用 Executors.newFixedThreadPool(1)?? 有意义吗? 。在两个线程(main + oneAnotherThread)场景下使用执行器服务是否高效?正在通过调
我想知道,Executors.newSingleThreadExecutor() 之间有什么区别?和 Executors.newFixedThreadPool(1) 以下摘自javadoc Unlik
我的问题是:使用 Executors.newFixedThreadPool(1) 有意义吗??。在两个线程(main + oneAnotherThread)场景中使用执行器服务是否有效?通过调用 ne
我有一个 Apache Spark 应用程序在集群模式下运行在 YARN 集群上(spark 在这个集群上有 3 个节点)。 当应用程序运行时,Spark-UI 显示 2 个执行程序(每个运行在不同的
我想知道是否有任何理由使用 Executor 而不是 ExecutorService。 据我所知,JDK 中没有实现 Executor 接口(interface),它也不是 ExecutorServi
我有多个使用 Celery Executor 的 dag,但我希望使用 Kubernetes Executor 运行一个特定的 dag。我无法推断出一种良好而可靠的方法来实现这一目标。 我有一个 ai
假设我们的 Controller 中有一个 Action 。在每次请求时,许多用户都会调用 performLogin。 def performLogin( ) = { Async {
创建和管理您自己的 ExecutorService 与使用 Spring Boot 的 @Async 方法和 @Bean 方法创建 Executor 添加一个@Bean来创建一个Executor 手动
问题从无到有,只有我在代码中所做的更改 - 安装了 RaSharper(但删除它并重新安装 Visual Studio 没有帮助)。 所以我使用 NUnit 3 来运行测试。 我有 Visual St
我们知道每个任务当时都在一个核心中执行。 假设我们有这样配置的节点集群: 10 节点。 每个节点 16 个核心。 每个节点 64 GB 内存。 我的问题是 有 1 个 16 核的执行程序和 16 个
我正在从 Jupyter Notebook 中初始化 PySpark,如下所示: from pyspark import SparkContext # conf = SparkConf().setAp
我正在向我的 Web 应用程序添加一个基于 Flask 的 API,以控制某些网络自动化功能的启动和停止。我遇到了一个奇怪的行为,即 Flask-Executor .submit() 方法调用的函数似
单元测试在本地运行良好。 在 Visual Studio 2017 托管生成代理上运行时,VSTest 任务失败并显示: 2018-12-08T10:42:16.3779907Z An excepti
我正在尝试制作一个执行器和线程的简单示例。 当我调用 newSingleThreadExecutor(new CustomThreadFactory) 时,一切顺利,但是当我使用 null 参数调用
对于一个线程,我通过以下代码段捕获未捕获的异常。但是,对于 ExecutorService executor = Executors.newFixedThreadPool(10);,如何捕获未捕获的异
我想创建一个 CompletableFuture,其返回值在 Kotlin 中的特定执行程序上运行。 下面的代码工作得很好。 return CompletableFuture.supplyAsync
考虑基本的固定线程池: Executors.newFixedThreadPool(MaxListeners) 我打算不断提交新任务 - 响应传入的 TCP 套接字服务请求。 然而,当每个任务中的Run
我们可以在定义 ThreadPoolExecutors 时提供 BlockingQueue 实现。但是,如果我使用工厂(执行器)创建单个线程池(如下所示),我想知道使用哪个阻塞队列。我猜它是一个 Li
我编写了一个程序来执行两个在 shell 前台运行的命令,直到在终端上按下 ^c。 外壳命令 ./weed master -mdir=/var/lib/qualebs/weed 上面命令的输出是 qu
我是一名优秀的程序员,十分优秀!