我真的讀了10或20個話題,不幸的是我沒有使它工作。我的接收器可以捕獲廣播,但只能通過我的應用程序通過sendBroadcast(intent)
發送。我希望它捕捉NFC適配器的廣播。有人將NFC標籤放在我的設備附近,然後我的應用程序應該在瀏覽菜單中啓動或顯示,但這種情況不會發生。即使我的應用程序啓動,並且我將NFC標籤放在設備附近,也無法捕獲它,而在瀏覽菜單中,我會看到其他應用程序,這可以。 我的接收器:NFC廣播問題
public class SomeBroadcastReceiver extends BroadcastReceiver {
private final String TAG = "SomeBroadcastReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "Got intent: " + intent);
}
}
我的清單文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.nfc">
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/icon"
android:label="@string/app_name">
<receiver android:enabled="true" android:name=".broadcast.SomeBroadcastReceiver">
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED" android:resource="@xml/technologies"/>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
</intent-filter>
</receiver>
<activity android:name=".simulator.FakeTagsActivity"
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="TagViewer"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="10" />
<uses-feature android:name="android.hardware.nfc" android:required="true" />
在FakeActivity我有這樣的臺詞:
Intent exampleIntent = new Intent("android.nfc.action.NDEF_DISCOVERED"); sendBroadcast(exampleIntent);
當應用reches他們,我接收器捕捉意圖,所以我瘦了k接收器是好的,但也許我錯過了清單中的某些東西?是否有獲得全球廣播的特別許可?或者我應該開始服務還是應該?
您是否找到了解決此問題的解決方案? – Antonio