1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.nfc;
18
19import android.annotation.SystemService;
20import android.content.Context;
21
22/**
23 * High level manager used to obtain an instance of an {@link NfcAdapter}.
24 * <p>
25 * Use {@link android.content.Context#getSystemService(java.lang.String)}
26 * with {@link Context#NFC_SERVICE} to create an {@link NfcManager},
27 * then call {@link #getDefaultAdapter} to obtain the {@link NfcAdapter}.
28 * <p>
29 * Alternately, you can just call the static helper
30 * {@link NfcAdapter#getDefaultAdapter(android.content.Context)}.
31 *
32 * <div class="special reference">
33 * <h3>Developer Guides</h3>
34 * <p>For more information about using NFC, read the
35 * <a href="{@docRoot}guide/topics/nfc/index.html">Near Field Communication</a> developer guide.</p>
36 * </div>
37 *
38 * @see NfcAdapter#getDefaultAdapter(android.content.Context)
39 */
40@SystemService(Context.NFC_SERVICE)
41public final class NfcManager {
42    private final NfcAdapter mAdapter;
43
44    /**
45     * @hide
46     */
47    public NfcManager(Context context) {
48        NfcAdapter adapter;
49        context = context.getApplicationContext();
50        if (context == null) {
51            throw new IllegalArgumentException(
52                    "context not associated with any application (using a mock context?)");
53        }
54        try {
55            adapter = NfcAdapter.getNfcAdapter(context);
56        } catch (UnsupportedOperationException e) {
57            adapter = null;
58        }
59        mAdapter = adapter;
60    }
61
62    /**
63     * Get the default NFC Adapter for this device.
64     *
65     * @return the default NFC Adapter
66     */
67    public NfcAdapter getDefaultAdapter() {
68        return mAdapter;
69    }
70}
71