可能性假NFC(近场通信)启动 [英] Possibility for Fake NFC(Near Field Communication) Launch
问题描述
我工作的近场通信从NFC标签读取数据。 我没有 NFC支持的Android手机和NFC标签以测试,我创建的应用程序。
我想知道是否有可能为通过意图过滤器启动我的应用程序(应该承担NFC标签从我的设备被检测到)
我的清单段:
<活动
机器人:ServerActivityNAME =
机器人:标签=@字符串/ APP_NAME
机器人:screenOrientation =画像>
<意向滤光器>
<作用机器人:名称=android.nfc.action.NDEF_DISCOVERED/>
<类机器人:名称=android.intent.category.DEFAULT/>
<数据
机器人:主机=abc.com
机器人:路径preFIX =/ aaap
机器人:计划=HTTP/>
&所述; /意图滤光器>
< /活性GT;
我的活动片段:
@覆盖
保护无效onNewIntent(意向意图){
如果(NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())){
Toast.makeText(getApplicationContext(),ACTION_TAG_DISCOVERED,
Toast.LENGTH_LONG);
标签标记= intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
}
}
一些研究NFC我发现,我们可以读/写NFC标签未启用NFC设备。但答案是如此简单后..它是什么,但有玩意图:
我们必须把这个片断,用于调用NFC:
最终意向意图=新的意图(NfcAdapter.ACTION_TAG_DISCOVERED);
intent.putExtra(NfcAdapter.EXTRA_NDEF_MESSAGES,自定义消息);
startActivity(意向);
另外,我们应该通过清单文件注册我们的活动到Android系统类似如下:
的Manifest.xml
<活动
机器人:名称=TagViewer>
<意向滤光器>
<作用机器人:名称=android.nfc.action.TAG_DISCOVERED/>
<类机器人:名称=android.intent.category.DEFAULT/>
&所述; /意图滤光器>
< /活性GT;
如果您有多个活动使用,我们会越来越选择器,从中我们可以推出我们所期望的活动同样的操作方式相同。
接收内部活动:
TagViewer的.java
如果(NfcAdapter.ACTION_TAG_DISCOVERED.equals(getIntent()的getAction())){
Log.v(NFC推出,NFC推出了);
}
我们在开发示例演示此样本。
I am working on Near Field Communication for reading data from NFC Tags. I don't have NFC supported Android Mobile and NFC Tags to test the Application i created .
I want to know whether it is possible to Launch my App through intent filter(Should assume NFC tag is detected from my device)
My Manifest Snippet :
<activity
android:name=".ServerActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="abc.com"
android:pathPrefix="/aaap"
android:scheme="http" />
</intent-filter>
</activity>
My Activity Snippet :
@Override
protected void onNewIntent(Intent intent) {
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) {
Toast.makeText(getApplicationContext(), "ACTION_TAG_DISCOVERED",
Toast.LENGTH_LONG);
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
}
}
After some research on NFC i found that we can read/write NFC Tags without NFC enabled device.. But answer is so simple.. It's nothing but playing with Intents :
We have to call this snippet for invoking NFC :
final Intent intent = new Intent(NfcAdapter.ACTION_TAG_DISCOVERED);
intent.putExtra(NfcAdapter.EXTRA_NDEF_MESSAGES, "Custom Messages");
startActivity(intent);
Also we should register our Activity to Android System through Manifest file like below :
Manifest.xml
<activity
android:name="TagViewer" >
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Same way if you have more than one Activity using same action we will be getting chooser from which we can launch our Desired Activity.
Receiving inside Activity :
TagViewer .java
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(getIntent().getAction())) {
Log.v("NFC Launched","NFC Launched");
}
We have this sample in Developer Sample Demo.
这篇关于可能性假NFC(近场通信)启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!