SecurityException NFC permission required - android

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!
Here is the start of my manifest:
<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 --->
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.
What am I doing wrong here?

The section
<uses-permission android:name="android.permission.NFC" />
<uses-sdk android:minSdkVersion="10"/>
<uses-feature android:name="android.hardware.nfc" android:required="true" />
Needs to be outside of your application tag.
Like
<uses-permission android:name="android.permission.NFC" />
<uses-sdk android:minSdkVersion="10"/>
<uses-feature android:name="android.hardware.nfc" android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
...
Read Structure of the Manifest File

<uses-permission>, <uses-sdk>, and <uses-feature> go outside the <application> element:
<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>
(from this sample project)

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.

Related

Nfc not required in app(Google Play)

I have an application that may or may not work with NFC. I have added these lines to manifest:
<manifest ...>
<uses-feature android:name="android.hardware.nfc" android:required="false"/>
<uses-permission android:name="android.permission.NFC" />
</manifest>
When I search for the application in google play, the message continues: "Your device is not compatible with this version"
I have verified that the NFCAdapter is not null, I have requested the pertinent permissions directly in execution ... but that message continues to come out.
APORTACION:
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.app.app">
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-feature android:name="android.hardware.nfc" android:required="false"/>
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"
tools:ignore="ProtectedPermissions" />
<application
android:name=".App"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<service
android:name=".timer.UploadService"
android:enabled="true"
android:exported="true">
</service>
<service
android:name=".services.uploaddata.ui.UploadDataService"
android:enabled="true"
android:exported="true">
</service>
<activity android:name=".main.ui.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:launchMode="singleTask"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".p1.ui.class1"
android:label="#string/title_activity_class1"
android:screenOrientation="portrait"
android:launchMode="singleTask">
</activity>
<activity
android:name=".p2.ui.class2"
android:label="#string/title_activity_class2"
android:screenOrientation="portrait"
android:theme="#style/class2ActivityTheme"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<activity
android:name=".p3.ui.class3"
android:theme="#style/AppTheme.ActionBar"
android:label="#string/title_activity_class3"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".p4.ui.class4"
android:label="#string/title_activity_class4"
android:theme="#style/AppTheme.ActionBar"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".p5.ui.class5"
android:label="#string/title_activity_class5"
android:screenOrientation="portrait">
</activity>
</application>
</manifest>
my problem is not a bad code. I waited for one to two days and the problem was solved. It is possible that google servers did not resolve the request well and took a little longer to update. I really do not know what the reason was but my app is already working :)

Element type "activity" must be followed by either attribute specifications, ">" or "/>"

My manifest gives me this error:
Element type "activity" must be followed by either attribute
specifications, ">" or "/>"
I have however opened and closed the activity tag as expected. I've also cleaned the project in an attempt to solve this problem but to no avail.
Here is my manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
`enter code here` package="com.TeamX.shuttle_app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<uses-permission android:name = "com.TeamX.shuttle_App.permission.MAPS_RECEIVE"/>
<uses-permission android:maxSdkVersion="21" android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:maxSdkVersion="21" android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:maxSdkVersion="21" android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:maxSdkVersion="21" android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/shuttapplogo"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyA7SnyyG2IZ4flWaZelTOWKcrFVnsrLCck" />
<activity
android:name="com.TeamX.shuttle_app.ShuttleSplash"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.TeamX.shuttle_App.Main"
android:label="#string/app_name"
</activity>
</application>
</manifest>
your
<activity
android:name="com.TeamX.shuttle_App.Main"
android:label="#string/app_name"
</activity>
should be
<activity
android:name="com.TeamX.shuttle_App.Main"
android:label="#string/app_name" />
Instead of:
<activity
android:name="com.TeamX.shuttle_App.Main"
android:label="#string/app_name"
</activity>
Do this:
<activity
android:name="com.TeamX.shuttle_App.Main"
android:label="#string/app_name">
</activity>

how do i read mifare classic tag first sector value?

On my Main Activity i have to show the first sector block value of Mi-fare classic tag. when i hold new tag at mobile at that time app also show tag information.
In my app i have to show only one activity.so please tell me how it is possible.
Yet i tried all the tutorial but not getting proper info.
My manifest code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.samplecode"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature
android:name="android.hardware.nfc"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.samplecode.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
</intent-filter>
<meta-data
android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="#xml/nfc_tech_filter"/>
</activity>
</application>
</manifest>

getRunningTasks() causing error even with get permission

Android studio , is giving me some issues. I clearly declared android. permission.GET_TASKS in the manifest. But it still closes the app.
Error:
Caused by: java.lang.SecurityException: Permission Denial: getTasks() from pid=1010, uid=10046 requires android.permission.GET_TASKS
AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.epiclapser.noprocrastinate" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<uses-sdk
android:maxSdkVersion="18"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.GET_TASKS"/>
>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity2"
android:label="#string/title_activity_main_activity2"></activity>
<activity
android:name=".LockScreen"
android:label="#string/title_activity_lock_screen"
>
</activity>
</application>
Move your permission Tag outside of Application Tag
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.GET_TASKS"/>
<application
android:icon="#drawable/ic_launcher"
<!--Elements inside application Tag-->
</application>

ERROR getting 'android:icon' attribute: attribute is not a string value while uploading apk to playstore

I've receive that message :
My AndroidManifest :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="..."
android:versionCode="1"
android:versionName="1.0" >
<uses-feature
android:glEsVersion="0x00020000"
android:required="true">
</uses-feature>
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="21" />
<uses-feature android:name="android.hardware.camera"
android:required="true" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name="..."
android:allowBackup="true"
android:hardwareAccelerated="true"
android:label="#string/app_name"
android:icon="#drawable/launcher"
android:largeHeap="true"
android:theme="#style/AppTheme" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name="..."
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="..."
android:label="#string/label_add_new_object"
android:screenOrientation="portrait"
android:icon="#drawable/ic_arrow"
android:theme="#style/MyFancyTheme"
android:configChanges="orientation|screenSize">
</activity>
<activity
android:name="..."
android:label="#string/label_settings_activity"
android:screenOrientation="portrait"
android:icon="#drawable/ic_arrow"
android:theme="#style/Theme.AppCompat.Light"
>
</activity>
<activity
android:name="..."
android:screenOrientation="portrait"
android:label="#string/app_name"
android:icon="#android:color/transparent"
android:theme="#style/CustomActionBarStyle">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
</application>
As I've read here, here and here, I've done :
1) copied all the drawables from #android/drawable to my corresponding folders hdpi, mdpi, e.t.c -
so I havn't any icon from #android/drawable folder in the project
2) put the icon drawable to the drawable folder of the res
3) cleaned the project
What can be solution for this ?
I think it is linked to having the icon attribute setting to a color #android:color/transparent. Maybe try a transparent drawable rather than a color.
I've found the solution - it was in
<activity
....
android:icon="#android:color/transparent" - the problem string
...
</activity>
when I removed that string, everythins worked fine

Categories

Resources