本文整理汇总了Java中android.net.Uri.getScheme方法的典型用法代码示例。如果您正苦于以下问题:Java Uri.getScheme方法的具体用法?Java Uri.getScheme怎么用?Java Uri.getScheme使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.net.Uri
的用法示例。
在下文中一共展示了Uri.getScheme方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRealFilePath
import android.net.Uri; //导入方法依赖的package包/类
public static String getRealFilePath(final Context context, final Uri uri) {
if (null == uri) return null;
final String scheme = uri.getScheme();
String data = null;
if (scheme == null)
data = uri.getPath();
else if (ContentResolver.SCHEME_FILE.equals(scheme)) {
data = uri.getPath();
} else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) {
final Cursor cursor = context.getContentResolver().query(uri, new String[]{MediaStore.Images.ImageColumns.DATA}, null, null, null);
if (null != cursor) {
if (cursor.moveToFirst()) {
final int index = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
if (index > -1) {
data = cursor.getString(index);
}
}
cursor.close();
}
}
return data;
}
示例2: getRealFilePath
import android.net.Uri; //导入方法依赖的package包/类
/**
* Try to return the absolute file path from the given Uri
*
* @param context
* @param uri
* @return the file path or null
*/
public static String getRealFilePath(final Context context, final Uri uri ) {
if ( null == uri ) return null;
final String scheme = uri.getScheme();
String data = null;
if ( scheme == null )
data = uri.getPath();
else if ( ContentResolver.SCHEME_FILE.equals( scheme ) ) {
data = uri.getPath();
} else if ( ContentResolver.SCHEME_CONTENT.equals( scheme ) ) {
Cursor cursor = context.getContentResolver().query( uri, new String[] { MediaStore.Images.ImageColumns.DATA }, null, null, null );
if ( null != cursor ) {
if ( cursor.moveToFirst() ) {
int index = cursor.getColumnIndex( MediaStore.Images.ImageColumns.DATA );
if ( index > -1 ) {
data = cursor.getString( index );
}
}
cursor.close();
}
}
return data;
}
示例3: getFileWithUri
import android.net.Uri; //导入方法依赖的package包/类
/**
* 通过URI获取文件
* @param uri
* @param activity
* @return
* Author JPH
* Date 2016/10/25
*/
public static File getFileWithUri(Uri uri, Activity activity) {
String picturePath = null;
String scheme=uri.getScheme();
if (ContentResolver.SCHEME_CONTENT.equals(scheme)){
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = activity.getContentResolver().query(uri,
filePathColumn, null, null, null);//从系统表中查询指定Uri对应的照片
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
if(columnIndex>=0){
picturePath = cursor.getString(columnIndex); //获取照片路径
}else if(TextUtils.equals(uri.getAuthority(),TConstant.getFileProviderName(activity))){
picturePath=parseOwnUri(activity,uri);
}
cursor.close();
}else if (ContentResolver.SCHEME_FILE.equals(scheme)){
picturePath=uri.getPath();
}
return TextUtils.isEmpty(picturePath)? null:new File(picturePath);
}
示例4: setSource
import android.net.Uri; //导入方法依赖的package包/类
@ReactProp(name = "src")
public void setSource(@Nullable ReadableArray sources) {
final String source =
(sources == null || sources.size() == 0) ? null : sources.getMap(0).getString("uri");
Uri uri = null;
if (source != null) {
try {
uri = Uri.parse(source);
// Verify scheme is set, so that relative uri (used by static resources) are not handled.
if (uri.getScheme() == null) {
uri = null;
}
} catch (Exception e) {
// ignore malformed uri, then attempt to extract resource ID.
}
if (uri == null) {
uri = getResourceDrawableUri(getThemedContext(), source);
}
}
if (uri != mUri) {
markUpdated();
}
mUri = uri;
}
示例5: setDataSource
import android.net.Uri; //导入方法依赖的package包/类
public void setDataSource(Context context, Uri uri) throws IOException, IllegalArgumentException,
SecurityException, IllegalStateException {
if (context == null || uri == null)
throw new IllegalArgumentException();
String scheme = uri.getScheme();
if (scheme == null || scheme.equals("file")) {
setDataSource(FileUtils.getPath(uri.toString()));
return;
}
try {
ContentResolver resolver = context.getContentResolver();
mFD = resolver.openAssetFileDescriptor(uri, "r");
if (mFD == null)
return;
setDataSource(mFD.getParcelFileDescriptor().getFileDescriptor());
return;
} catch (Exception e) {
closeFD();
}
Log.e("Couldn't open file on client side, trying server side %s", uri.toString());
setDataSource(uri.toString());
return;
}
示例6: a
import android.net.Uri; //导入方法依赖的package包/类
public static MLinkResult a(Uri uri, Uri uri2) {
if (uri2 == null) {
return new MLinkResult();
}
String scheme = uri2.getScheme();
String host = uri2.getHost();
int port = uri2.getPort();
String encodedPath = uri2.getEncodedPath();
String encodedQuery = uri2.getEncodedQuery();
String scheme2 = uri.getScheme();
String host2 = uri.getHost();
int port2 = uri.getPort();
String encodedPath2 = uri.getEncodedPath();
String encodedQuery2 = uri.getEncodedQuery();
if (n.a(scheme, scheme2) && n.a(host, host2) && port == port2) {
return a(encodedPath, encodedPath2, a(encodedQuery2, encodedQuery));
}
return new MLinkResult();
}
示例7: getUriType
import android.net.Uri; //导入方法依赖的package包/类
public static int getUriType(Uri uri) {
assertNonRelative(uri);
String scheme = uri.getScheme();
if (ContentResolver.SCHEME_CONTENT.equalsIgnoreCase(scheme)) {
return URI_TYPE_CONTENT;
}
if (ContentResolver.SCHEME_ANDROID_RESOURCE.equalsIgnoreCase(scheme)) {
return URI_TYPE_RESOURCE;
}
if (ContentResolver.SCHEME_FILE.equalsIgnoreCase(scheme)) {
if (uri.getPath().startsWith("/android_asset/")) {
return URI_TYPE_ASSET;
}
return URI_TYPE_FILE;
}
if ("data".equalsIgnoreCase(scheme)) {
return URI_TYPE_DATA;
}
if ("http".equalsIgnoreCase(scheme)) {
return URI_TYPE_HTTP;
}
if ("https".equalsIgnoreCase(scheme)) {
return URI_TYPE_HTTPS;
}
if (PLUGIN_URI_SCHEME.equalsIgnoreCase(scheme)) {
return URI_TYPE_PLUGIN;
}
return URI_TYPE_UNKNOWN;
}
示例8: open
import android.net.Uri; //导入方法依赖的package包/类
@JSMethod(uiThread = true)
public void open(JSONObject options, JSCallback success, JSCallback failure) {
if (options != null) {
String url = options.getString(Constants.Value.URL);
JSCallback callback = success;
JSONObject result = new JSONObject();
if (!TextUtils.isEmpty(url)) {
Uri rawUri = Uri.parse(url);
String scheme = rawUri.getScheme();
if (TextUtils.isEmpty(scheme) || Constants.Scheme.HTTP.equalsIgnoreCase(scheme) || Constants.Scheme.HTTPS.equalsIgnoreCase(scheme)) {
this.push(options.toJSONString(), success);
} else {
try {
Intent intent = new Intent(Intent.ACTION_VIEW, rawUri);
mWXSDKInstance.getContext().startActivity(intent);
result.put(CALLBACK_RESULT, MSG_SUCCESS);
} catch (Throwable e) {
e.printStackTrace();
result.put(CALLBACK_RESULT, MSG_FAILED);
result.put(CALLBACK_MESSAGE, "Open page failed.");
callback = failure;
}
}
} else {
result.put(CALLBACK_RESULT, MSG_PARAM_ERR);
result.put(CALLBACK_MESSAGE, "The URL parameter is empty.");
callback = failure;
}
if(callback != null){
callback.invoke(result);
}
}
}
示例9: getFromUri
import android.net.Uri; //导入方法依赖的package包/类
public static Repo getFromUri(Context context, String uriString) {
Uri uri = Uri.parse(uriString);
if (uri != null && uri.getScheme() != null) { // Make sure uri is valid and has a scheme
try {
switch (uri.getScheme()) {
case ContentRepo.SCHEME:
return new ContentRepo(context, uri);
case DropboxRepo.SCHEME:
if (! BuildConfig.IS_DROPBOX_ENABLED) {
return null;
}
/* There should be no authority. */
if (uri.getAuthority() != null) {
return null;
}
return new DropboxRepo(context, uri);
case DirectoryRepo.SCHEME:
return new DirectoryRepo(uriString, false);
case MockRepo.SCHEME:
return new MockRepo(context, uriString);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
示例10: setDataSource
import android.net.Uri; //导入方法依赖的package包/类
@Override
public void setDataSource(String path) throws IOException,
IllegalArgumentException, SecurityException, IllegalStateException {
mDataSource = path;
Uri uri = Uri.parse(path);
String scheme = uri.getScheme();
if (!TextUtils.isEmpty(scheme) && scheme.equalsIgnoreCase("file")) {
mInternalMediaPlayer.setDataSource(uri.getPath());
} else {
mInternalMediaPlayer.setDataSource(path);
}
}
示例11: getUrl
import android.net.Uri; //导入方法依赖的package包/类
private String getUrl(Uri uri) {
String url = uri.toString();
String scheme = uri.getScheme();
if (uri.isHierarchical()) {
if (TextUtils.equals(scheme, "http") || TextUtils.equals(scheme, "https")) {
String weexTpl = uri.getQueryParameter(Constants.WEEX_TPL_KEY);
if (!TextUtils.isEmpty(weexTpl)) {
url = weexTpl;
}
}
}
return url;
}
示例12: Request
import android.net.Uri; //导入方法依赖的package包/类
/**
* @param uri the HTTP URI to download.
*/
public Request(Uri uri) {
if (uri == null) {
throw new NullPointerException();
}
String scheme = uri.getScheme();
if (scheme == null || (!scheme.equals("http") && !scheme.equals("https"))) {
throw new IllegalArgumentException("Can only download HTTP/HTTPS URIs: " + uri);
}
mUri = uri;
}
示例13: setDataSource
import android.net.Uri; //导入方法依赖的package包/类
@Override
public void setDataSource(Context context, Uri uri) throws IllegalArgumentException,
SecurityException {
String scheme = uri.getScheme();
if (SmbProxy.needToStream(scheme)){
mSmbProxy = SmbProxy.setDataSource(uri, this, null);
return;
}
super.setDataSource(context, uri);
}
示例14: getRealFilePath
import android.net.Uri; //导入方法依赖的package包/类
public String getRealFilePath(final Uri uri) {
if (null == uri) return null;
final String scheme = uri.getScheme();
String data = null;
if (scheme == null) {
Log.e("wuwang", "scheme is null");
data = uri.getPath();
} else if (ContentResolver.SCHEME_FILE.equals(scheme)) {
data = uri.getPath();
Log.e("wuwang", "SCHEME_FILE");
} else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) {
data = GetPathFromUri4kitkat.getPath(getApplicationContext(), uri);
}
return data;
}
示例15: splitPathFromUrlDisplayText
import android.net.Uri; //导入方法依赖的package包/类
/**
* Given the URL display text, this will remove any path portion contained within.
* @param displayText The text to strip the path from.
* @return A pair where the first item is the text without any path content (if the path was
* successfully found), and the second item is the path content (or null if no path
* was found or parsing the path failed).
* @see ToolbarDataProvider#getText()
*/
// TODO(tedchoc): Move this logic into the original display text calculation.
@VisibleForTesting
public static Pair<String, String> splitPathFromUrlDisplayText(String displayText) {
int pathSearchOffset = 0;
Uri uri = Uri.parse(displayText);
String scheme = uri.getScheme();
if (!TextUtils.isEmpty(scheme)) {
if (UNSUPPORTED_SCHEMES_TO_SPLIT.contains(scheme)) {
return Pair.create(displayText, null);
} else if (ACCEPTED_SCHEMES.contains(scheme)) {
for (pathSearchOffset = scheme.length();
pathSearchOffset < displayText.length();
pathSearchOffset++) {
char c = displayText.charAt(pathSearchOffset);
if (c != ':' && c != '/') break;
}
}
}
int pathOffset = -1;
if (pathSearchOffset < displayText.length()) {
pathOffset = displayText.indexOf('/', pathSearchOffset);
}
if (pathOffset != -1) {
String prePathText = displayText.substring(0, pathOffset);
// If the '/' is the last character and the beginning of the path, then just drop
// the path entirely.
String pathText = pathOffset == displayText.length() - 1
? null : displayText.substring(pathOffset);
return Pair.create(prePathText, pathText);
}
return Pair.create(displayText, null);
}