Monday, 15 June 2015

android - NFC read TAGS in differents Activities automaticly without ask where process the TAGS -



android - NFC read TAGS in differents Activities automaticly without ask where process the TAGS -

i want read in different activites tag without appear in display, activity best read tag? think should automatic. code manifest this:

<application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="com.iprocuratio.strim.loginactivity" android:label="@string/title_activity_login" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name="com.iprocuratio.strim.temperatureactivity" android:label="@string/title_activity_temperature" > </activity> <activity android:name="com.iprocuratio.strim.constantsactivity" android:label="@string/title_activity_constants" > </activity> <activity android:name="com.iprocuratio.strim.fc" android:label="@string/title_activity_fc" > </activity> <activity android:name="com.iprocuratio.strim.fr" android:label="@string/title_activity_fr" > </activity> <activity android:name="com.iprocuratio.strim.sato2" android:label="@string/title_activity_sat_o2" > </activity> <activity android:name="com.iprocuratio.strim.mainactivity" android:label="@string/app_name" > </activity> <activity android:name="com.iprocuratio.strim.prescriptionsactivity" android:label="@string/title_activity_prescriptions"> <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="com.iprocuratio.strim.medicamentosactivity" android:label="@string/title_activity_medicamentos" > </activity> <activity android:name="com.iprocuratio.strim.identificacion" android:label="@string/title_activity_identificacion" > <intent-filter > <action android:name="com.google.zxing.client.android.scan" /> <category android:name="android.intent.category.default" /> </intent-filter> </activity> <activity android:name="com.iprocuratio.strim.pantallaleer" android:label="@string/title_activity_pantallaleer" > <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="com.iprocuratio.strim.identificacionfinal" android:label="@string/title_activity_identificacion_final" > </activity> </application>

i have implemented read tag in 2 activities: prescriptionsactivity , pantallaleer. example, when want read tag in prescriptionsactivity appear next image:

i when read tag doesn't show window , automaticly take right activity. know, how can do? code correct?

let me know. thanks.

regards.

both activities sensitive on same intent (i.e. both trigger on tags contain text record (or mime type record of type text/plain):

<intent-filter> <action android:name="android.nfc.action.ndef_discovered" /> <category android:name="android.intent.category.default" /> <data android:mimetype="text/plain" /> </intent-filter>

it's impossible android tell activity improve fit needs specific tag if both contain same info type , both filters match same info type. consequently android shows intent chooser allow user select.

if want avoid intent chooser, should utilize different info types each activity (insead of using unspecific text/plain info type). instance, if tag should launch prescriptionsactivity, write next ndef message tag:

+-------------------------------------------------+ | ext:iprocuratio.com:prescriptions | <your data> | +-------------------------------------------------+

you create ndef message on android using

ndefmessage msg = new ndefmessage( ndefrecord.createexternal("iprocuratio.com", "prescriptions", yourdata), );

the intent filter prescriptionsactivity this:

<intent-filter> <action android:name="android.nfc.action.ndef_discovered" /> <category android:name="android.intent.category.default" /> <data android:scheme="vnd.android.nfc" android:host="ext" android:pathprefix="/iprocuratio.com:prescriptions"/> </intent-filter>

similarly, pantallaleer activity, use:

+-------------------------------------------------+ | ext:iprocuratio.com:pantallaleer | <your data> | +-------------------------------------------------+

you create ndef message on android using

ndefmessage msg = new ndefmessage( ndefrecord.createexternal("iprocuratio.com", "pantallaleer", yourdata), );

the intent filter pantallaleer activity this:

<intent-filter> <action android:name="android.nfc.action.ndef_discovered" /> <category android:name="android.intent.category.default" /> <data android:scheme="vnd.android.nfc" android:host="ext" android:pathprefix="/iprocuratio.com:pantallaleer"/> </intent-filter>

android android-activity tags android-manifest nfc

No comments:

Post a Comment