當前位置: 首頁>>代碼示例>>Java>>正文


Java ContentResolver.getType方法代碼示例

本文整理匯總了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);
}
 
開發者ID:XFY9326,項目名稱:CatchSpy,代碼行數:39,代碼來源:SettingsActivity.java

示例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;
    }
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:34,代碼來源:K9WebViewClient.java

示例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;
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:9,代碼來源:DownloadImageTask.java

示例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);
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:15,代碼來源:ContentUriUtils.java

示例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);
    }
}
 
開發者ID:l465659833,項目名稱:Bigbang,代碼行數:15,代碼來源:SPHelper.java

示例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);
    }
}
 
開發者ID:l465659833,項目名稱:Bigbang,代碼行數:15,代碼來源:SPHelper.java

示例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);
    }
}
 
開發者ID:l465659833,項目名稱:Bigbang,代碼行數:15,代碼來源:SPHelper.java

示例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);
    }
}
 
開發者ID:l465659833,項目名稱:Bigbang,代碼行數:15,代碼來源:SPHelper.java

示例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);
    }
}
 
開發者ID:l465659833,項目名稱:Bigbang,代碼行數:15,代碼來源:SPHelper.java

示例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);
    }
}
 
開發者ID:l465659833,項目名稱:Bigbang,代碼行數:16,代碼來源:SPHelper.java

示例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();
    }
}
 
開發者ID:l465659833,項目名稱:Bigbang,代碼行數:13,代碼來源:SPHelper.java

示例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();
        }
    }
}
 
開發者ID:XFY9326,項目名稱:CatchSpy,代碼行數:26,代碼來源:ImportActivity.java

示例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;
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:58,代碼來源:AttachmentInfoLoader.java

示例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;
}
 
開發者ID:Applandeo,項目名稱:Material-File-Picker,代碼行數:75,代碼來源:FileUtils.java


注:本文中的android.content.ContentResolver.getType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。