需要 SecurityException NFC 权限 [英] SecurityException NFC permission required
本文介绍了需要 SecurityException NFC 权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在 Android 上进行一些 NFC 开发,但遇到了麻烦.我启动了应用程序,但它立即失败,并显示不幸的是,..... 已停止工作".
I have been doing some NFC development on android, and I have hit a brick wall. I launch the app and it immediatly fails with a "Unfortunately,..... has stopped working".
一些快速的谷歌搜索表明我需要将权限放在清单中.我这样做了,但是你瞧,我仍然遇到同样的错误!
Some quick googling showed I need the put the permission in the manifest. I did that, but lo and behold, I still get the same error!
这是我的清单的开始:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-permission android:name="android.permission.NFC" />
<uses-sdk android:minSdkVersion="10"/>
<uses-feature android:name="android.hardware.nfc" android:required="true" />
<activity
android:name=".MainActivity"
<!-- rest of the file --->
以及 logcat 中的输出:
And the output in logcat:
java.lang.RuntimeException: Unable to resume activity {za.co.fnb.ms.nfcreader/za.co.fnb.ms.nfcreader.MainActivity}: java.lang.SecurityException: NFC permission required: Neither user 10253 nor current process has android.permission.NFC.
我在这里做错了什么?
推荐答案
将这些添加到您使用 nfc 的活动中:
Add these to activities which you use nfc:
<activity
android:name="com.example.example.CLASSNAME"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<data android:mimeType="mime/type" />
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/nfc_type"/>
</activity>
并且您还必须在应用程序标签之前定义权限.
And also you have to define permissions before application tag.
这篇关于需要 SecurityException NFC 权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文