Android 需要SecurityException NFC权限
我在安卓上做了一些NFC开发,我遇到了麻烦。我启动应用程序,它立即失败,并发出“不幸的是,……已停止工作” 一些快速的谷歌搜索显示我需要把许可证放在舱单上。我这么做了,但你瞧,我还是犯了同样的错误 以下是我清单的开始:Android 需要SecurityException NFC权限,android,permissions,nfc,Android,Permissions,Nfc,我在安卓上做了一些NFC开发,我遇到了麻烦。我启动应用程序,它立即失败,并发出“不幸的是,……已停止工作” 一些快速的谷歌搜索显示我需要把许可证放在舱单上。我这么做了,但你瞧,我还是犯了同样的错误 以下是我清单的开始: <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:the
<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 --->
我做错了什么?将这些添加到您使用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>
此外,您还必须在应用程序标记之前定义权限。将这些添加到您使用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>
此外,您还必须在应用程序标记之前定义权限。部分
<uses-permission android:name="android.permission.NFC" />
<uses-sdk android:minSdkVersion="10"/>
<uses-feature android:name="android.hardware.nfc" android:required="true" />
需要在应用程序标记之外
像
本节
<uses-permission android:name="android.permission.NFC" />
<uses-sdk android:minSdkVersion="10"/>
<uses-feature android:name="android.hardware.nfc" android:required="true" />
需要在应用程序标记之外
像
,和超出),和超出)我认为您必须在清单顶部,在应用程序标记之外声明uses权限。我认为您必须在清单顶部声明uses权限,在应用程序标签之外。有一些注释,Opiatefuchs是第一个在注释中,然后是Burak。因为我只能对评论进行投票并接受答案。我接受这个。另一个都是正确的。@Gerrie我不明白你对这个问题的解释,接受吗??你能说清楚吗?有一些评论,阿派特弗克斯是第一个在评论中,其次是布拉克。因为我只能对评论进行投票并接受答案。我接受这个。另一个都是正确的。@Gerrie我不明白你对这个问题的解释,接受吗??你能说清楚吗??
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.commonsware.android.jimmyb"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.NFC"/>
<uses-feature
android:name="android.hardware.nfc"
android:required="true"/>
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="15"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter android:label="@string/app_name">
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<data android:mimeType="vnd.secret/agent.man"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
</manifest>