Example usage for android.webkit URLUtil isContentUrl

List of usage examples for android.webkit URLUtil isContentUrl

Introduction

In this page you can find the example usage for android.webkit URLUtil isContentUrl.

Prototype

public static boolean isContentUrl(String url) 

Source Link

Usage

From source file:com.apptentive.android.sdk.util.Util.java

/**
 * This method creates a cached file exactly copying from the input stream.
 *
 * @param sourceUrl     the source file path or uri string
 * @param localFilePath the cache file path string
 * @param mimeType      the mimeType of the source inputstream
 * @return null if failed, otherwise a StoredFile object
 *///  w w w  .  j a va2s.  co m
public static StoredFile createLocalStoredFile(String sourceUrl, String localFilePath, String mimeType) {
    InputStream is = null;
    try {
        Context context = ApptentiveInternal.getInstance().getApplicationContext();
        if (URLUtil.isContentUrl(sourceUrl) && context != null) {
            Uri uri = Uri.parse(sourceUrl);
            is = context.getContentResolver().openInputStream(uri);
        } else {
            File file = new File(sourceUrl);
            is = new FileInputStream(file);
        }
        return createLocalStoredFile(is, sourceUrl, localFilePath, mimeType);

    } catch (FileNotFoundException e) {
        return null;
    } finally {
        ensureClosed(is);
    }
}