本文整理汇总了Java中android.content.res.AssetFileDescriptor.createInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java AssetFileDescriptor.createInputStream方法的具体用法?Java AssetFileDescriptor.createInputStream怎么用?Java AssetFileDescriptor.createInputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.res.AssetFileDescriptor
的用法示例。
在下文中一共展示了AssetFileDescriptor.createInputStream方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveVideoFile
import android.content.res.AssetFileDescriptor; //导入方法依赖的package包/类
private void saveVideoFile(Intent intent) {
try {
AssetFileDescriptor videoAsset = getContentResolver().openAssetFileDescriptor(intent.getData(), "r");
FileInputStream fis = videoAsset.createInputStream();
FileOutputStream fos = new FileOutputStream(photoFile);
byte[] buffer = new byte[1024];
int length;
while ((length = fis.read(buffer)) > 0) {
fos.write(buffer, 0, length);
}
fis.close();
fos.close();
} catch (IOException e) {
Log.e(CameraTest.TAG,e.getMessage(),e);
}
}
示例2: get
import android.content.res.AssetFileDescriptor; //导入方法依赖的package包/类
public String get(Cursor cursor) {
//cursor.moveToFirst();
String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
Log.d("Vcard lookupKey ", lookupKey);
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);
Log.d("Vcard uri ", uri.toString());
AssetFileDescriptor fd;
try {
fd = this.getContentResolver().openAssetFileDescriptor(uri, "r");
// Your Complex Code and you used function without loop so how can you get all Contacts Vcard.??
/* FileInputStream fis = fd.createInputStream();
byte[] buf = new byte[(int) fd.getDeclaredLength()];
fis.read(buf);
String VCard = new String(buf);
String path = Environment.getExternalStorageDirectory().toString() + File.separator + vfile;
FileOutputStream out = new FileOutputStream(path);
out.write(VCard.toString().getBytes());
Log.d("Vcard", VCard);*/
//https://stackoverflow.com/questions/42017591/in-android-7-contentresolvers-method-openassetfiledescriptorvcarduri-r-re
FileInputStream fis = fd.createInputStream();
byte[] buf = new byte[fis.available()];
fis.read(buf);
String vcardstring = new String(buf);
if(mapVcard.containsKey(uri.toString())){
String vv=mapVcard.get(uri.toString());
if(vv.equals(vcardstring)){
Log.d("Vcard lookupKey 重复", lookupKey);
return vv;
}
}
mapVcard.put(uri.toString(),vcardstring);
//log.d("write "+vcardstring);
// FileOutputStream mFileOutputStream = new FileOutputStream(storage_path, true);
mFileOutputStream.write(buf);//vcardstring.toString().getBytes());
return vcardstring;
} catch (Exception e1) {
e1.printStackTrace();
log.e(e1);
}
return "";
}
示例3: getBinaryFile
import android.content.res.AssetFileDescriptor; //导入方法依赖的package包/类
private FileInputStream getBinaryFile(String resourceLocation){
FileInputStream fis = null;
try {
AssetFileDescriptor fd = mContext.getResources().getAssets().openFd(resourceLocation);
fis = fd.createInputStream();
} catch (IOException e) {
e.printStackTrace();
}
return fis;
}