Fix NPE on devices that don't have NFC.

We should return null instead of NPE.

Bug: 5622939
Change-Id: I802f4a99ea9f5e73453d5ea30da4e1d9fa279b9c
This commit is contained in:
Nick Pelly
2011-11-16 16:46:27 -08:00
parent 7dc81e06e4
commit a5193b24c1

View File

@@ -360,6 +360,10 @@ public final class NfcAdapter {
/* use getSystemService() instead of just instantiating to take
* advantage of the context's cached NfcManager & NfcAdapter */
NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
if (manager == null) {
// NFC not available
return null;
}
return manager.getDefaultAdapter();
}