【发布时间】:2014-09-12 18:15:47
【问题描述】:
我试图让我的应用程序在运行时忽略 nfc 命令 - 它由带有 Android 应用程序记录 (AAR) 的 NFC 标签启动,我不希望它能够在它已经运行时启动.. 我已尝试仔细关注其他人examples,但该应用程序仍然可以在运行时由 AAR 启动(在前台)。
Manifest.xml:
<application>
<activity>
<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.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="application/com.MyApp.frontcam" />
</intent-filter>
</activity>
</application>
Activity.java:
private NfcAdapter mAdapter;
private PendingIntent mPendingIntent;
private IntentFilter[] mFilters;
private String[][] mTechLists;
@Override
public void onCreate(Bundle savedInstanceState) {
mAdapter = NfcAdapter.getDefaultAdapter(this);
mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
try {
ndef.addDataType("*/*");
}
catch (MalformedMimeTypeException e) {
throw new RuntimeException("fail", e);
}
mFilters = new IntentFilter[] {ndef, };
mTechLists = new String[][] {
new String[] { NfcA.class.getName() },
new String[] { Ndef.class.getName() },
new String[] { NdefFormatable.class.getName() }
};
}
@Override
protected void onResume() {
super.onResume();
mAdapter.enableForegroundDispatch(this, mPendingIntent, null, null); //ended up setting mFilters and mTechLists to null
}
【问题讨论】:
标签: android nfc android-applicationrecord