更新时间:2022-10-17 17:45:57
您应该意图过滤器分为以下内容:
<意向滤光器>
<作用机器人:名字=android.nfc.action.NDEF_DISCOVERED/>
<类机器人:名字=android.intent.category.DEFAULT/>
<数据机器人:mime类型=text / plain的/>
&所述; /意图滤光器>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.MAIN/>
<类机器人:名字=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
有关的意图过滤器来匹配,动作,类别和数据应该是正确的。当您通过图标来打开应用程序,它会发送与主要的行动和类别LAUNCHER一个意图。因为它不包含数据类型,因为该类别不匹配DEFAULT和行动不符合NDEF_DISCOVERED,Android的认为你的意图过滤器无法处理它。
I created an application on Android. I am developing it on eclipse with ADT.
It is about nfc. For the moment it only reads and writes tag.
I run my application on my mobile device for testing and it works well.
So it compiles well and runs well on my Xperia Z1 Sony, however when i unplug my phone and install the apk on it i have a problem :
The install runs well but then i have two choices "Terminated" or "Open". The open is not clickable... I go to settings->Application->installed and i see my app that is install. I can force stop clear cache but not open it... I can't understand why.
It runs well on my phone when i launch it from eclipse but when i want to run it on my phone unplugged from my computer it doesn't want to be open. No error message during installation...
I activate dev mode and allow installation from unknown sources ect...
Do someone have a clue ??
Here is my manifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mynfc"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.NFC" />
<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.mynfc.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".WriteATagActivity"/>
</application>
</manifest>
You should separate the intent filters into the following:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
For an intent filter to match, action, category and data should be correct. When you open the app via the icon, it will send a intent with MAIN action, and category LAUNCHER. Because it does not contain a data type, and because the category does not match DEFAULT and action does not match NDEF_DISCOVERED, Android thinks your intent filter can not handle it.