本文整理汇总了Java中android.provider.OpenableColumns类的典型用法代码示例。如果您正苦于以下问题:Java OpenableColumns类的具体用法?Java OpenableColumns怎么用?Java OpenableColumns使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OpenableColumns类属于android.provider包,在下文中一共展示了OpenableColumns类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFileName
import android.provider.OpenableColumns; //导入依赖的package包/类
private String getFileName(Uri uri) {
String result = null;
if (uri.getScheme().equals("content")) {
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
}
} finally {
cursor.close();
}
}
if (result == null) {
result = uri.getPath();
int cut = result.lastIndexOf('/');
if (cut != -1) {
result = result.substring(cut + 1);
}
}
return result;
}
示例2: getContentSize
import android.provider.OpenableColumns; //导入依赖的package包/类
public static long getContentSize(final Uri contentUri) {
Cursor cursor = null;
try {
cursor = FacebookSdk
.getApplicationContext()
.getContentResolver()
.query(contentUri, null, null, null, null);
int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE);
cursor.moveToFirst();
return cursor.getLong(sizeIndex);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
示例3: getFileName
import android.provider.OpenableColumns; //导入依赖的package包/类
/**
* 根据uri获取文件路径
* @param context
* @param uri
* @return
*/
static String getFileName(Context context, Uri uri) {
String result = null;
if (uri.getScheme().equals("content")) {
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cursor != null) {
cursor.close();
}
}
}
if (result == null) {
result = uri.getPath();
int cut = result.lastIndexOf(File.separator);
if (cut != -1) {
result = result.substring(cut + 1);
}
}
return result;
}
示例4: getFileName
import android.provider.OpenableColumns; //导入依赖的package包/类
public static String getFileName(Uri uri) {
String result = null;
if (uri.getScheme().equals("content")) {
Cursor cursor = null;
try {
cursor = ApplicationLoader.applicationContext.getContentResolver().query(uri, new String[]{OpenableColumns.DISPLAY_NAME}, null, null, null);
if (cursor.moveToFirst()) {
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
}
} catch (Exception e) {
FileLog.e("tmessages", e);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
if (result == null) {
result = uri.getPath();
int cut = result.lastIndexOf('/');
if (cut != -1) {
result = result.substring(cut + 1);
}
}
return result;
}
示例5: getFileName
import android.provider.OpenableColumns; //导入依赖的package包/类
protected String getFileName(Uri uri) {
String result = null;
if (uri.getScheme().equals("content")) {
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
}
} finally {
cursor.close();
}
}
if (result == null) {
result = uri.getPath();
int cut = result.lastIndexOf('/');
if (cut != -1) {
result = result.substring(cut + 1);
}
}
return result;
}
示例6: getFileName
import android.provider.OpenableColumns; //导入依赖的package包/类
static String getFileName(Context context, Uri uri) {
String result = null;
if (uri.getScheme().equals("content")) {
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cursor != null) {
cursor.close();
}
}
}
if (result == null) {
result = uri.getPath();
int cut = result.lastIndexOf(File.separator);
if (cut != -1) {
result = result.substring(cut + 1);
}
}
return result;
}
示例7: getFileName
import android.provider.OpenableColumns; //导入依赖的package包/类
public String getFileName(Uri uri) {
String result = null;
if (uri.getScheme().equals("content")) {
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
}
} finally {
if (cursor != null) {
cursor.close();
}
}
}
if (result == null) {
result = uri.getLastPathSegment();
}
return result;
}
示例8: loadFromUri
import android.provider.OpenableColumns; //导入依赖的package包/类
@Override
public void loadFromUri(Context context, Uri fileUri) {
try {
InputStream in =
context.getContentResolver().openInputStream(fileUri);
if (fileUri.getScheme().equals("content")) {
Cursor retCur = context.getContentResolver()
.query(fileUri, null, null, null, null);
if (retCur != null) {
int nameIndex = retCur
.getColumnIndex(OpenableColumns.DISPLAY_NAME);
retCur.moveToFirst();
setFileName(retCur.getString(nameIndex));
}
} else if (fileUri.getScheme().equals("file")) {
setFileName(fileUri.getLastPathSegment());
}
loadMarkdown(in);
} catch (Exception e) {
if (editView != null)
editView.showFileLoadeddError(MarkdownFile.READ_ERROR);
}
}
示例9: getFileName
import android.provider.OpenableColumns; //导入依赖的package包/类
public String getFileName(Uri uri) {
String result = null;
if (uri.getScheme().equals("content")) {
Cursor cursor = mCR.query(uri, null, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
}
} finally {
if (cursor != null) {
cursor.close();
}
}
}
if (result == null) {
result = uri.getPath();
int cut = result.lastIndexOf('/');
if (cut != -1) {
result = result.substring(cut + 1);
}
}
return result;
}
示例10: getFileName
import android.provider.OpenableColumns; //导入依赖的package包/类
public String getFileName(Uri uri) {
String result = null;
if (uri.getScheme().equals("content")) {
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
}
} finally {
cursor.close();
}
}
if (result == null) {
result = uri.getPath();
int cut = result.lastIndexOf('/');
if (cut != -1) {
result = result.substring(cut + 1);
}
}
return result;
}
示例11: retrieveFileName
import android.provider.OpenableColumns; //导入依赖的package包/类
public static String retrieveFileName(Context context, Uri uri) {
//retrieve file name
try {
Cursor cursor = context.getContentResolver().query(uri,
new String[]{OpenableColumns.DISPLAY_NAME},
null, null, null);
if (cursor != null) {
int nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
cursor.moveToFirst();
if (!cursor.isAfterLast()) {
String filename = cursor.getString(nameIndex);
cursor.close();
return filename;
}
}
} catch (SecurityException e) {
e.printStackTrace();
}
return null;
}
示例12: retrieveFileSize
import android.provider.OpenableColumns; //导入依赖的package包/类
public static InfoItem retrieveFileSize(Context context, Uri uri) {
//retrieve fileSize form MediaStore
Cursor cursor = context.getContentResolver().query(
uri, null, null,
null, null);
long size = 0;
if (cursor != null && !cursor.isAfterLast()) {
int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE);
cursor.moveToFirst();
if (!cursor.isAfterLast()) {
size = cursor.getLong(sizeIndex);
cursor.close();
}
}
return new InfoItem(context.getString(R.string.info_size), Parser.parseFileSize(context, size));
}
示例13: getNameFromUri
import android.provider.OpenableColumns; //导入依赖的package包/类
static String getNameFromUri(@NonNull Context context, @NonNull Uri uri) {
String result = null;
if (uri.getScheme().equals("content")) {
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
if(cursor != null) {
//noinspection TryFinallyCanBeTryWithResources
try {
if (cursor.moveToFirst()) {
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
}
} finally {
cursor.close();
}
}
}
if (result == null) {
result = uri.getPath();
int cut = result.lastIndexOf('/');
if (cut != -1) {
result = result.substring(cut + 1);
}
}
return result;
}
示例14: getFileSize
import android.provider.OpenableColumns; //导入依赖的package包/类
private long getFileSize(Uri uri) {
long size = -1;
Cursor cursor = getContext().getContentResolver().query(uri, null, null, null, null);
if (cursor != null) {
try {
int rowsCount = cursor.getCount();
if (rowsCount > 0 && cursor.moveToFirst()) {
int nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE);
return cursor.getLong(sizeIndex);
}
} finally {
cursor.close();
}
}
return size;
}
示例15: getFilename
import android.provider.OpenableColumns; //导入依赖的package包/类
public static String getFilename(Uri uri, Context context) {
String fileName = null;
String scheme = uri.getScheme();
if (scheme.equals("file")) {
fileName = uri.getLastPathSegment();
}
else if (scheme.equals("content")) {
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
fileName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
}
} finally {
cursor.close();
}
}
return fileName;
}