1 Public classMainactivityextendsActionbaractivityImplements2 Createbeamuriscallback {3 PrivateNfcadapter Mnfcadapter;4 Privatependingintent mpendingintent;5 Private FinalString TargetFileName = "/sdcard/temp_icon.png";6 7 @Override8 protected voidonCreate (Bundle savedinstancestate) {9 Super. OnCreate (savedinstancestate);Ten Setcontentview (r.layout.fragment_main); OneMnfcadapter = Mnfcadapter.getdefaultadapter ( This); AMpendingintent = Pendingintent.getactivity ( This, 0,NewIntent ( This, -GetClass ()), 0); - the //Copy the picture of the resource file to SDcard - Try { -InputStream Isstream = Getresources (). Getassets (). Open ("Icon.png"); -FileOutputStream fos =NewFileOutputStream (targetfilename); + byte[] buffer =New byte[10000]; - intn =isstream.read (buffer); +Fos.write (buffer, 0, n); A isstream.close (); at -}Catch(Exception e) { - //Todo:handle Exception - } -Mnfcadapter.setbeampushuriscallback ( This, This); - } in - @Override to Publicuri[] Createbeamuris (nfcevent arg0) { + //TODO auto-generated Method Stub -uri[] URIs =NewUri[1]; theUri uri = uri.parse ("file://" +targetfilename); *Uris[0] =URI; $ Panax Notoginseng returnURIs; - } the +}
NFC Technology: Transfer files using Android Beam technology (ii)