- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Xamarin 编写 C# 代码,并尝试通过 NFC 扫描 MIFARE Classic 1K 卡。
m1card_test 的 intent-filter 工作正常。但我不想选择要启动的 Activity 。所以我正在尝试使用前台调度。
这是我的部分代码 (C#):
创建时
Intent Myintent = new Intent(this, GetType());
Myintent.AddFlags(ActivityFlags.SingleTop);
mPendingIntent = PendingIntent.GetActivity(this, 0, Myintent, 0);
ndefDetected = new IntentFilter(NfcAdapter.ActionTechDiscovered);
ndefDetected.AddDataType("*/*");
intentF = new IntentFilter[] { ndefDetected };
techLists = new string[][] {new string[] {
typeof(Android.Nfc.Tech.NfcA).FullName,
typeof(Android.Nfc.Tech.MifareClassic).FullName}
};
暂停
NfcManager manager = (NfcManager)GetSystemService(NfcService);
manager.DefaultAdapter.DisableForegroundDispatch(this);
恢复时
NfcManager manager = (NfcManager)GetSystemService(NfcService);
manager.DefaultAdapter.EnableForegroundDispatch(this,mPendingIntent,intentF,techLists);
不幸的是,前台调度不起作用(即它不拾取标签)。
如果我将对 EnableForegroundDispatch()
的调用更改为
manager.DefaultAdapter.EnableForegroundDispatch(this,mPendingIntent,null,null);
前台调度工作正常。但它会拾取所有标签,而不仅仅是 MIFARE Classic,我得到一个 Intent Action_Tag_Discovered 而不是 Action_Tech_Discovered。
Action_Tech_Discovered如何配合前台调度系统使用?
我错过了什么吗?
技术列表.xml:
<?xml version="1.0" encoding="utf-8" ?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<tech-list>
<tech>android.nfc.tech.NfcA</tech>
<tech>android.nfc.tech.MifareClassic</tech>
</tech-list>
</resources>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="m1card_test.m1card_test" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="16" />
<application android:label="m1card_test"></application>
<uses-permission android:name="android.permission.NFC" />
</manifest>
我的 C# 代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Nfc;
namespace m1card_test
{
[Activity(Label = "m1_read", Icon = "@drawable/icon", LaunchMode = Android.Content.PM.LaunchMode.SingleTask)]
[IntentFilter(
new[] {NfcAdapter.ActionTechDiscovered},
Categories = new[] {Intent.CategoryDefault,})]
[MetaData("android.nfc.action.TECH_DISCOVERED", Resource = "@xml/tech_list")]
public class m1_read : Activity
{
TextView mTV;
PendingIntent mPendingIntent;
IntentFilter ndefDetected;
IntentFilter[] intentF;
String[][] techLists;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.m1_read);
Intent Myintent = new Intent(this, GetType());
Myintent.AddFlags(ActivityFlags.SingleTop);
mPendingIntent = PendingIntent.GetActivity(this, 0, Myintent, 0);
ndefDetected = new IntentFilter(NfcAdapter.ActionTechDiscovered);
ndefDetected.AddDataType("*/*");
intentF = new IntentFilter[] { ndefDetected };
techLists = new string[][] {new string[] {
typeof(Android.Nfc.Tech.NfcA).FullName,
typeof(Android.Nfc.Tech.MifareClassic).FullName}
};
Button button = FindViewById<Button>(Resource.Id.Back_Button);
mTV = FindViewById<TextView>(Resource.Id.textview);
button.Click += delegate
{
Intent main_intent = new Intent(this, typeof(MainActivity));
this.StartActivity(main_intent);
Finish();
};
}
protected override void OnPause()
{
base.OnPause();
NfcManager manager = (NfcManager)GetSystemService(NfcService);
manager.DefaultAdapter.DisableForegroundDispatch(this);
}
protected override void OnResume()
{
base.OnResume();
NfcManager manager = (NfcManager)GetSystemService(NfcService);
manager.DefaultAdapter.EnableForegroundDispatch(this, mPendingIntent,intentF,techLists);
}
protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
mTV.Text = "OnNewIntent";
}
}
}
最佳答案
TECH_DISCOVERED
Intent 过滤器没有与之关联的数据类型(MIME 类型)。因此,您需要删除该行
ndefDetected.AddDataType("*/*");
此外,我不太确定 typeof(Android.Nfc.Tech.MifareClassic).FullName
是否解析为标签技术的正确名称(完整的 Java 类名称)。因此,您应该对该字符串进行硬编码(就像您在 tech-filter XML 文件中所做的那样):
techLists = new string[][] { new string[] {
"android.nfc.tech.NfcA",
"android.nfc.tech.MifareClassic"
}};
最后,由于 MifareClassic 标签技术总是暗示 NfcA,您可以安全地将技术过滤器减少到仅
techLists = new string[][] { new string[] {
"android.nfc.tech.MifareClassic"
}};
关于c# - NFC Action_Tech_Discovered with foreground dispatch 不会捕获 Mifare 1k 卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38573882/
如何通过 XCTest 在 Swift UI 测试中触发以下行为: 让应用程序进入前台和非事件 (applicationWillResignActive) 并返回“前台和事件” (applicatio
我有一个列表框,其项目模板是一个列表框。我正在尝试将内部列表框的“前景”属性设置为与主列表框的相同。这是失败的。以下是代码片段。在这里 Foreground="{TemplateBinding For
我只想更改控制台应用程序的前景色文本,而不是背景文本颜色或控制台背景颜色。换句话说:我想保持以前的颜色,除了前景文本颜色。 目前我使用下面的代码,但文本下的背景也发生了变化。 #include #i
TextBlock 的 Foreground 的默认值是 SystemColors 之一吗?如果有,是哪一个? 最佳答案 这相当依赖于主题,如果应用主题没有覆盖,DP 系统将使用相应 Dependen
我正在构建一个类似于 Runtastic/Endomondo/Strava 的应用程序,它需要一个获取 GPS 位置的服务,直到用户明确停止它。 我运行了 Runtastic 和我的应用程序来尝试一下
无法在 InstantApp 功能模块中使用前台服务。低于运行时安全异常。 java.lang.RuntimeException: Unable to start activity Component
Android开发中如何设置按钮的android:foregrounddrawable为无边框?就像 android:background="?android:attr/selectableItemB
当应用程序在前台并收到通知时, Activity 上的 fragment 转换会顺利进行,没有任何问题。如果应用程序在后台运行,则应用程序会崩溃,因为在 Activity 进入前台之前会触发 frag
我的应用程序将创建通知以通知用户 当应用程序在后台运行 8 小时 我想要的只是创建通知(后台)的切换进程 到前台,我该怎么办? // PendingIntent pendingIntent =
看看这个小型 Android 应用程序: 主要 Activity .java: package io.github.gsaga.toucheventtest; import android.suppo
我在我的应用程序上使用 Nimbus LAF,我想更改所有按钮的前景色。我做这个设置: UIManager.put("Button.foreground", Color.WHITE); 但这行不通。也
单点触控 当应用程序返回前台时,我需要激活的 ViewController 来了解这一点。 是否有一个事件或覆盖我可以用来确定 View 被带到前台。 我确实找到了“WillEnterForegrou
我有以下按钮: 我想将路径的 Stroke 属性绑定(bind)到按钮的基础内容呈现器的 TextElement.Foreground 属性。这样一来,它始终与任何其他按钮中的任
我正在为我的 ios 应用程序使用解析推送(使用 xcode)。我想跟踪应用程序和推送。后台状态和非事件状态正常工作,但前台故障。当我在前台接收推送时,推送打开统计数据保持为 0。这就是我到目前为止所
如果设备操作系统是 Android 9(Pie),我已调用 Context.startForgroundService() 但有时它会抛出错误,例如“Context.startForgroundSer
如题所示,有没有办法把网格线放到前台(即在图形前面,符号后面)?我现在拥有的是: 我的代码如下(使用Swift 3): let gridLineStyle = CPTMutableLineSt
我知道我可以通过此 list 配置使用 USB 主机模式: 每次连接 USB 设备时,这都会启动我的 Activity 。问题是,如果它已经在前台运
我正在尝试在我的网站上实现 Comodo 信任 Logo 。这是一个图像,当您将鼠标悬停在它上面时,它会弹出一个 iframe,其中包含有关该站点的一些安全信息。执行此操作的代码来自第三方。 当 Lo
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭
每次我尝试运行 Pygame 程序时,我都会收到此错误: TypeError: Invalid foreground RGBA argument 这是我的代码,你知道为什么吗? text = font
我是一名优秀的程序员,十分优秀!