• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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 
17 package com.example.android.apis.nfc;
18 
19 import com.example.android.apis.R;
20 
21 import android.app.Activity;
22 import android.nfc.NdefMessage;
23 import android.nfc.NdefRecord;
24 import android.nfc.NfcAdapter;
25 import android.os.Bundle;
26 import android.widget.TextView;
27 
28 /**
29  * An example of how to use the NFC foreground NDEF push APIs.
30  */
31 public class ForegroundNdefPush extends Activity {
32     private NfcAdapter mAdapter;
33     private TextView mText;
34     private NdefMessage mMessage;
35 
36     @Override
onCreate(Bundle savedState)37     public void onCreate(Bundle savedState) {
38         super.onCreate(savedState);
39 
40         mAdapter = NfcAdapter.getDefaultAdapter(this);
41 
42         // Create an NDEF message a URL
43         mMessage = new NdefMessage(NdefRecord.createUri("http://www.android.com"));
44 
45         setContentView(R.layout.foreground_dispatch);
46         mText = (TextView) findViewById(R.id.text);
47 
48         if (mAdapter != null) {
49             mAdapter.setNdefPushMessage(mMessage, this);
50             mText.setText("Tap another Android phone with NFC to push a URL");
51         } else {
52             mText.setText("This phone is not NFC enabled.");
53         }
54     }
55 }
56