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


     1 public class MainActivity extends ActionBarActivity implements
     2         CreateBeamUrisCallback {
     3     private NfcAdapter mNfcAdapter;
     4     private PendingIntent mPendingIntent;
     5     private final String targetFilename = "/sdcard/temp_icon.png";
     6 
     7     @Override
     8     protected void onCreate(Bundle savedInstanceState) {
     9         super.onCreate(savedInstanceState);
    10         setContentView(R.layout.fragment_main);
    11         mNfcAdapter = mNfcAdapter.getDefaultAdapter(this);
    12         mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this,
    13                 getClass()), 0);
    14 
    15         // 把资源文件的图片拷到sdcard
    16         try {
    17             InputStream isStream = getResources().getAssets().open("icon.png");
    18             FileOutputStream fos = new FileOutputStream(targetFilename);
    19             byte[] buffer = new byte[10000];
    20             int n = isStream.read(buffer);
    21             fos.write(buffer, 0, n);
    22             isStream.close();
    23 
    24         } catch (Exception e) {
    25             // TODO: handle exception
    26         }
    27         mNfcAdapter.setBeamPushUrisCallback(this, this);
    28     }
    29 
    30     @Override
    31     public Uri[] createBeamUris(NfcEvent arg0) {
    32         // TODO Auto-generated method stub
    33         Uri[] uris = new Uri[1];
    34         Uri uri = Uri.parse("file://" + targetFilename);
    35         uris[0] = uri;
    36 
    37         return uris;
    38     }
    39 
    40 }
  • 相关阅读:
    6.Java中的链表数据结构ListNode
    5.把字符串转换成整数
    vue-cli3预设preset记录
    vue2.0用法技巧汇总
    typeof
    js对象注意
    本地搭建sass运行环境
    安卓手机移动端Web开发调试之Chrome远程调试(Remote Debugging)
    Vue中引入jquery方法
    移动端开发问题及技巧汇总
  • 原文地址:https://www.cnblogs.com/my334420/p/6915791.html
Copyright © 2020-2023  润新知