本文整理汇总了Java中android.content.ContentResolver.getType方法的典型用法代码示例。如果您正苦于以下问题:Java ContentResolver.getType方法的具体用法?Java ContentResolver.getType怎么用?Java ContentResolver.getType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.ContentResolver
的用法示例。
在下文中一共展示了ContentResolver.getType方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onActivityResult
import android.content.ContentResolver; //导入方法依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == Config.REQUEST_GET_LOCAL_DICTIONARY) {
if (resultCode == RESULT_OK) {
if (data != null && data.getData() != null) {
ContentResolver resolver = getContentResolver();
String fileType = resolver.getType(data.getData());
if (fileType != null) {
if (fileType.startsWith("image")) {
Toast.makeText(this, R.string.settings_extra_words_load_failed, Toast.LENGTH_SHORT).show();
finish();
return;
}
}
String file_path = URI.getAbsolutePath(this, data.getData());
String text = IOMethod.readFile(file_path);
try {
JSONObject jsonObject = new JSONObject(text);
if (jsonObject.has(Config.DEFAULT_EXTRA_WORDS_DATA_NAME)) {
String name = new File(file_path).getName();
String path = Config.DEFAULT_APPLICATION_DATA_DIR + name;
if (IOMethod.writeFile(jsonObject.toString(), path)) {
String newName = Code.unicodeEncode(name) + "-" + Code.getFileMD5String(path);
if (IOMethod.renameFile(path, newName)) {
Toast.makeText(this, R.string.settings_extra_words_load_success, Toast.LENGTH_SHORT).show();
return;
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
Toast.makeText(this, R.string.settings_extra_words_load_failed, Toast.LENGTH_SHORT).show();
}
}
}
super.onActivityResult(requestCode, resultCode, data);
}
示例2: shouldInterceptRequest
import android.content.ContentResolver; //导入方法依赖的package包/类
protected WebResourceResponse shouldInterceptRequest(WebView webView, Uri uri) {
if (!CID_SCHEME.equals(uri.getScheme())) {
return RESULT_DO_NOT_INTERCEPT;
}
if (attachmentResolver == null) {
return RESULT_DUMMY_RESPONSE;
}
String cid = uri.getSchemeSpecificPart();
if (TextUtils.isEmpty(cid)) {
return RESULT_DUMMY_RESPONSE;
}
Uri attachmentUri = attachmentResolver.getAttachmentUriForContentId(cid);
if (attachmentUri == null) {
return RESULT_DUMMY_RESPONSE;
}
Context context = webView.getContext();
ContentResolver contentResolver = context.getContentResolver();
try {
String mimeType = contentResolver.getType(attachmentUri);
InputStream inputStream = contentResolver.openInputStream(attachmentUri);
WebResourceResponse webResourceResponse = new WebResourceResponse(mimeType, null, inputStream);
addCacheControlHeader(webResourceResponse);
return webResourceResponse;
} catch (Exception e) {
Timber.e(e, "Error while intercepting URI: %s", uri);
return RESULT_DUMMY_RESPONSE;
}
}
示例3: getMimeType
import android.content.ContentResolver; //导入方法依赖的package包/类
private String getMimeType(ContentResolver contentResolver, Uri uri, String fileName) {
String mimeType = null;
if (fileName.indexOf('.') == -1) {
mimeType = contentResolver.getType(uri);
}
return mimeType;
}
示例4: getMimeType
import android.content.ContentResolver; //导入方法依赖的package包/类
/**
* Retrieve the MIME type for the content URI.
*
* @param context {@link Context} in interest.
* @param uriString the content URI to look up.
* @return MIME type or null if the input params are empty or invalid.
*/
@CalledByNative
public static String getMimeType(Context context, String uriString) {
ContentResolver resolver = context.getContentResolver();
if (resolver == null) return null;
Uri uri = Uri.parse(uriString);
return resolver.getType(uri);
}
示例5: getString
import android.content.ContentResolver; //导入方法依赖的package包/类
public static String getString(String name, String defaultValue) {
SharedPreferences sp = getSP(name);
if (sp == null) {
ContentResolver cr = mContext.getContentResolver();
Uri uri = Uri.parse(CONTENT_URI + SEPARATOR + TYPE_STRING + SEPARATOR + name);
String rtn = cr.getType(uri);
if (rtn == null || rtn.equals(NULL_STRING)) {
return defaultValue;
}
return rtn;
} else {
return sp.getString(name, defaultValue);
}
}
示例6: getInt
import android.content.ContentResolver; //导入方法依赖的package包/类
public static int getInt(String name, int defaultValue) {
SharedPreferences sp = getSP(name);
if (sp == null) {
ContentResolver cr = mContext.getContentResolver();
Uri uri = Uri.parse(CONTENT_URI + SEPARATOR + TYPE_INT + SEPARATOR + name);
String rtn = cr.getType(uri);
if (rtn == null || rtn.equals(NULL_STRING)) {
return defaultValue;
}
return Integer.parseInt(rtn);
} else {
return sp.getInt(name, defaultValue);
}
}
示例7: getFloat
import android.content.ContentResolver; //导入方法依赖的package包/类
public static float getFloat(String name, float defaultValue) {
SharedPreferences sp = getSP(name);
if (sp == null) {
ContentResolver cr = mContext.getContentResolver();
Uri uri = Uri.parse(CONTENT_URI + SEPARATOR + TYPE_FLOAT + SEPARATOR + name);
String rtn = cr.getType(uri);
if (rtn == null || rtn.equals(NULL_STRING)) {
return defaultValue;
}
return Float.parseFloat(rtn);
} else {
return sp.getFloat(name, defaultValue);
}
}
示例8: getBoolean
import android.content.ContentResolver; //导入方法依赖的package包/类
public static boolean getBoolean(String name, boolean defaultValue) {
SharedPreferences sp = getSP(name);
if (sp == null) {
ContentResolver cr = mContext.getContentResolver();
Uri uri = Uri.parse(CONTENT_URI + SEPARATOR + TYPE_BOOLEAN + SEPARATOR + name);
String rtn = cr.getType(uri);
if (rtn == null || rtn.equals(NULL_STRING)) {
return defaultValue;
}
return Boolean.parseBoolean(rtn);
} else {
return sp.getBoolean(name, defaultValue);
}
}
示例9: getLong
import android.content.ContentResolver; //导入方法依赖的package包/类
public static long getLong(String name, long defaultValue) {
SharedPreferences sp = getSP(name);
if (sp == null) {
ContentResolver cr = mContext.getContentResolver();
Uri uri = Uri.parse(CONTENT_URI + SEPARATOR + TYPE_LONG + SEPARATOR + name);
String rtn = cr.getType(uri);
if (rtn == null || rtn.equals(NULL_STRING)) {
return defaultValue;
}
return Long.parseLong(rtn);
} else {
return sp.getLong(name, defaultValue);
}
}
示例10: contains
import android.content.ContentResolver; //导入方法依赖的package包/类
public static boolean contains(String name) {
SharedPreferences sp = getSP(name);
if (sp == null) {
ContentResolver cr = mContext.getContentResolver();
Uri uri = Uri.parse(CONTENT_URI + SEPARATOR + TYPE_CONTAIN + SEPARATOR + name);
String rtn = cr.getType(uri);
if (rtn == null || rtn.equals(NULL_STRING)) {
return false;
} else {
return Boolean.parseBoolean(rtn);
}
} else {
return sp.contains(name);
}
}
示例11: clear
import android.content.ContentResolver; //导入方法依赖的package包/类
public static void clear(){
SharedPreferences sp = getSP(null);
if (sp == null) {
ContentResolver cr = mContext.getContentResolver();
Uri uri = Uri.parse(CONTENT_URI + SEPARATOR + TYPE_CLEAN);
cr.getType(uri);
} else {
SharedPreferences.Editor editor = sp.edit();
editor.clear();
editor.commit();
}
}
示例12: onActivityResult
import android.content.ContentResolver; //导入方法依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == Config.REQUEST_GET_EXTRA_FILE) {
if (resultCode == RESULT_OK && data != null && data.getData() != null) {
ContentResolver resolver = getContentResolver();
String fileType = resolver.getType(data.getData());
if (fileType != null) {
if (fileType.startsWith("image")) {
Toast.makeText(this, R.string.import_file_select_error, Toast.LENGTH_SHORT).show();
finish();
return;
}
}
DictionaryPath = URI.getAbsolutePath(this, data.getData());
String text = IOMethod.readFile(DictionaryPath);
if (text != null) {
TextView preview = findViewById(R.id.textview_import_text_preview);
preview.setText(text);
}
} else {
Toast.makeText(this, R.string.import_file_select_error, Toast.LENGTH_SHORT).show();
finish();
}
}
}
示例13: loadInBackground
import android.content.ContentResolver; //导入方法依赖的package包/类
@Override
public Attachment loadInBackground() {
Uri uri = sourceAttachment.uri;
String contentType = sourceAttachment.contentType;
long size = -1;
String name = null;
ContentResolver contentResolver = getContext().getContentResolver();
Cursor metadataCursor = contentResolver.query(
uri,
new String[] { OpenableColumns.DISPLAY_NAME, OpenableColumns.SIZE },
null,
null,
null);
if (metadataCursor != null) {
try {
if (metadataCursor.moveToFirst()) {
name = metadataCursor.getString(0);
size = metadataCursor.getInt(1);
}
} finally {
metadataCursor.close();
}
}
if (name == null) {
name = uri.getLastPathSegment();
}
String usableContentType = contentResolver.getType(uri);
if (usableContentType == null && contentType != null && contentType.indexOf('*') != -1) {
usableContentType = contentType;
}
if (usableContentType == null) {
usableContentType = MimeUtility.getMimeTypeByExtension(name);
}
if (size <= 0) {
String uriString = uri.toString();
if (uriString.startsWith("file://")) {
File f = new File(uriString.substring("file://".length()));
size = f.length();
} else {
Timber.v("Not a file: %s", uriString);
}
} else {
Timber.v("old attachment.size: %d", size);
}
Timber.v("new attachment.size: %d", size);
cachedResultAttachment = sourceAttachment.deriveWithMetadataLoaded(usableContentType, name, size);
return cachedResultAttachment;
}
示例14: getType
import android.content.ContentResolver; //导入方法依赖的package包/类
/**
* This method returns a String representing a type of the file using static variable from
* the FileType interface
*
* @param context An application context needed to get content resolver and find type of the file
* @param fileUri Uri of the file needed to get the file type using ContentResolver
* @return A string representing type of file
*/
public static String getType(Context context, Uri fileUri) {
File file = new File(fileUri.getPath());
if (file.isDirectory()) {
return DIRECTORY;
}
String mimeType;
if (fileUri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
ContentResolver cr = context.getContentResolver();
mimeType = cr.getType(fileUri);
} else {
String fileExtension = MimeTypeMap.getFileExtensionFromUrl(fileUri.toString());
mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension.toLowerCase());
}
if (mimeType == null) {
return UNKNOWN;
}
if (mimeType.equals(ZIP_ARCHIVE) || mimeType.equals(RAR_ARCHIVE)) {
return ARCHIVE;
}
if (mimeType.equals(DOC_FILE) || mimeType.equals(DOCX_FILE)) {
return DOCUMENT;
}
if (mimeType.equals(XLS_FILE) || mimeType.equals(XLSX_FILE)) {
return SHEET;
}
if (mimeType.equals(PPT_FILE) || mimeType.equals(PPTX_FILE)) {
return PRESENTATION;
}
if (mimeType.startsWith(IMAGE_FILE)) {
return IMAGE;
}
if (mimeType.startsWith(VIDEO_FILE)) {
return VIDEO;
}
if (mimeType.equals(PDF_FILE)) {
return PDF;
}
if (mimeType.startsWith(AUDIO_FILE)) {
return MUSIC;
}
if (mimeType.startsWith(TEXT_FILE)) {
return TEXT;
}
if (mimeType.equals(APK_FILE)) {
return APK;
}
if (mimeType.contains(EPUB_FILE)) {
return BOOK;
}
return UNKNOWN;
}