gpt4 book ai didi

java - "New Tag Collected"而不是读取应用程序的标签 - NFC android

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:09:47 26 4
gpt4 key购买 nike

我有一个类,它创建与 NFC 的连接和两个 Activity 。他们都创建了该类的对象,以便他们可以连接到 NFC。早些时候它以某种方式工作但现在我遇到了问题 - 我的应用程序没有对 NewIntent 执行任何操作,即使是在第一个 Activity 中也是如此。而不是它,我可以从名为“标签”(Nexus S)的内置应用程序中看到“收集的新标签”。

我该怎么办?

类(class):

public NFCForegroundUtil(Activity activity)
{
super();
this.activity = activity;
mAdapter = NfcAdapter.getDefaultAdapter(activity
.getApplicationContext());

mPendingIntent = PendingIntent.getActivity(activity, 0, new Intent(
activity, activity.getClass())
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
IntentFilter ndef2 = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
IntentFilter ndef3 = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);

try
{
ndef2.addDataType("*/*");
}
catch (MalformedMimeTypeException e)
{
throw new RuntimeException("fail", e);
}

mFilters = new IntentFilter[] {ndef, ndef2, ndef3 };

mTechLists = new String[][] { new String[] {
// android.nfc.tech.NfcV.class.getName(),
android.nfc.tech.NfcA.class.getName(),
android.nfc.tech.IsoDep.class.getName() } };

mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists);

}

Activity 1:

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

nfcForegroundUtil = new NFCForegroundUtil(this);

}

@Override
protected void onNewIntent(Intent intent)
{

super.onNewIntent(intent);
Intent i = new Intent(this, NfcDisplayLabelActivity2.class);
startActivity(i);

}

最佳答案

转到设置 -> 应用程序 -> 所有 -> 标签(在我的例子中) -> 禁用

关于java - "New Tag Collected"而不是读取应用程序的标签 - NFC android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12620880/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com