zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    1052. 卖个萌 (20)
    1051. 复数乘法 (15)
    1050. 螺旋矩阵(25)
    1049. 数列的片段和(20)
    1048. 数字加密(20)
    1047. 编程团体赛(20)
    1046. 划拳(15)
    怎么用js代码改变单选框的选中状态
    Dom操作--全选反选
    Scoket简介
  • 原文地址:https://www.cnblogs.com/my334420/p/6915791.html
Copyright © 2011-2022 走看看