NFC技术(使用Android Beam技术传输文件)

笛里谁知壮士心,沙头空照征人骨。这篇文章主要讲述NFC技术:使用Android Beam技术传输文件相关的知识,希望能为你提供帮助。

NFC技术(使用Android Beam技术传输文件)

文章图片

1 public class MainActivity extends ActionBarActivity implements 2CreateBeamUrisCallback { 3private NfcAdapter mNfcAdapter; 4private PendingIntent mPendingIntent; 5private final String targetFilename = "/sdcard/temp_icon.png"; 6 7@Override 8protected void onCreate(Bundle savedInstanceState) { 9super.onCreate(savedInstanceState); 10setContentView(R.layout.fragment_main); 11mNfcAdapter = mNfcAdapter.getDefaultAdapter(this); 12mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, 13getClass()), 0); 14 15// 把资源文件的图片拷到sdcard 16try { 17InputStream isStream = getResources().getAssets().open("icon.png"); 18FileOutputStream fos = new FileOutputStream(targetFilename); 19byte[] buffer = new byte[10000]; 20int n = isStream.read(buffer); 21fos.write(buffer, 0, n); 22isStream.close(); 23 24} catch (Exception e) { 25// TODO: handle exception 26} 27mNfcAdapter.setBeamPushUrisCallback(this, this); 28} 29 30@Override 31public Uri[] createBeamUris(NfcEvent arg0) { 32// TODO Auto-generated method stub 33Uri[] uris = new Uri[1]; 34Uri uri = Uri.parse("file://" + targetFilename); 35uris[0] = uri; 36 37return uris; 38} 39 40 }

【NFC技术(使用Android Beam技术传输文件)】 

    推荐阅读