Merge "Throw a nicer error message when using an invalid context to create Nfc"
This commit is contained in:
@@ -357,8 +357,11 @@ public final class NfcAdapter {
|
||||
throw new IllegalArgumentException("context cannot be null");
|
||||
}
|
||||
context = context.getApplicationContext();
|
||||
/* use getSystemService() instead of just instantiating to take
|
||||
* advantage of the context's cached NfcManager & NfcAdapter */
|
||||
if (context == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"context not associated with any application (using a mock context?)");
|
||||
}
|
||||
/* use getSystemService() for consistency */
|
||||
NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
|
||||
if (manager == null) {
|
||||
// NFC not available
|
||||
|
||||
@@ -40,6 +40,10 @@ public final class NfcManager {
|
||||
public NfcManager(Context context) {
|
||||
NfcAdapter adapter;
|
||||
context = context.getApplicationContext();
|
||||
if (context == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"context not associated with any application (using a mock context?)");
|
||||
}
|
||||
try {
|
||||
adapter = NfcAdapter.getNfcAdapter(context);
|
||||
} catch (UnsupportedOperationException e) {
|
||||
|
||||
Reference in New Issue
Block a user