把字节流转换成bitmap对象
public static Bitmap getPicFromBytes(byte[] bytes, BitmapFactory.Options opts) { if (bytes != null) if (opts != null) return BitmapFactory.decodeByteArray(bytes, 0, bytes.length,opts); else return BitmapFactory.decodeByteArray(bytes, 0, bytes.length); return null; }从 Intent中获取Ndef对象,获得了byte数据转换成bitmap对象
Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); // only one message sent during the beam NdefMessage msg = (NdefMessage) rawMsgs[0]; // record 0 contains the MIME type, record 1 is the AAR, if present Bitmap bitmap = getPicFromBytes(msg.getRecords()[0].getPayload(),null);
向手机根目录写入文件
InputStream is = getResources().getAssets().open("ic_launcher.png"); FileOutputStream fos = new FileOutputStream(targetFilename); buffer = new byte[10000]; int n = is.read(buffer); fos.write(buffer,0,n);
此处有一个共同,File类与FileOutputStream类在new的时候,如果参数中的路劲所代表的文件存在就指向它,如果不存在,就创建