本文整理汇总了Java中android.net.Uri.getPathSegments方法的典型用法代码示例。如果您正苦于以下问题:Java Uri.getPathSegments方法的具体用法?Java Uri.getPathSegments怎么用?Java Uri.getPathSegments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.net.Uri
的用法示例。
在下文中一共展示了Uri.getPathSegments方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: query
import android.net.Uri; //导入方法依赖的package包/类
@Nullable
@Override
public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection,
@Nullable String[] selectionArgs, @Nullable String sortOrder)
throws UnsupportedOperationException {
final SQLiteDatabase db = mDbHelper.getReadableDatabase();
int match = sUriMatcher.match(uri);
Cursor cursor = null;
switch (match) {
case MEDIA:
List<String> pathSegments = uri.getPathSegments();
if (pathSegments != null && pathSegments.size() > 1) {
String id = uri.getPathSegments().get(1);
cursor = db.query(MediaEntry.TABLE_NAME, projection, MediaEntry.COLUMN_MEDIA_ID + " = ? ", new String[]{id}, null, null, sortOrder);
}
break;
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
}
mContext.getContentResolver().notifyChange(uri, null);
return cursor;
}
示例2: fromUri
import android.net.Uri; //导入方法依赖的package包/类
public static DocumentMetadata fromUri(Uri uri, SmbClient client) throws IOException {
final List<String> pathSegments = uri.getPathSegments();
if (pathSegments.isEmpty()) {
throw new UnsupportedOperationException("Can't load metadata for workgroup or server.");
}
final StructStat stat = client.stat(uri.toString());
final DirectoryEntry entry = new DirectoryEntry(
OsConstants.S_ISDIR(stat.st_mode) ? DirectoryEntry.DIR : DirectoryEntry.FILE,
"",
uri.getLastPathSegment());
final DocumentMetadata metadata = new DocumentMetadata(uri, entry);
metadata.mStat.set(stat);
return metadata;
}
示例3: insert
import android.net.Uri; //导入方法依赖的package包/类
public Uri insert(Uri uri, ContentValues values) {
SQLiteDatabase sqlDb = dbHelper.getWritableDatabase();
List<String> segments = uri.getPathSegments();
String recordId = segments.get(1);
String name = segments.get(3);
String insertView = "Insert or replace into views (record_id, name, query, date_synced) values(?,?,?,?)";
SQLiteStatement insertViewStmt = sqlDb.compileStatement(insertView);
insertViewStmt.bindString(1, recordId);
insertViewStmt.bindString(2, name);
insertViewStmt.bindString(3, values.getAsString("query"));
insertViewStmt.bindString(4, values.getAsString("date_synced"));
insertViewStmt.execute();
getContext()
.getContentResolver()
.notifyChange(uri, null);
return uri;
}
示例4: update
import android.net.Uri; //导入方法依赖的package包/类
public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
int updateCount = 0;
SQLiteDatabase sqlDb = dbHelper.getWritableDatabase();
List<String> segments = uri.getPathSegments();
String recordId = segments.get(1);
String name = segments.get(3);
String updateView = "update views set query = ?, date_synced = ? where record_id = ? and name = ?";
SQLiteStatement updateViewStmt = sqlDb.compileStatement(updateView);
updateViewStmt.bindString(1, values.getAsString("query"));
updateViewStmt.bindString(2, values.getAsString("date_synced"));
updateViewStmt.bindString(3, recordId);
updateViewStmt.bindString(4, name);
updateCount = updateViewStmt.executeUpdateDelete();
if (updateCount > 0) {
getContext().getContentResolver().notifyChange(uri, null);
}
return updateCount;
}
示例5: querySingleFromAnyRepo
import android.net.Uri; //导入方法依赖的package包/类
private QuerySelection querySingleFromAnyRepo(Uri uri, boolean includeAlias) {
String alias = includeAlias ? "apk." : "";
String selection =
alias + Cols.VERSION_CODE + " = ? AND " +
alias + Cols.APP_ID + " IN (" + getMetadataIdFromPackageNameQuery() + ")";
List<String> pathSegments = uri.getPathSegments();
List<String> args = new ArrayList<>(3);
args.add(pathSegments.get(1)); // First (0th) path segment is the word "apk" and we are not interested in it.
args.add(pathSegments.get(2));
if (pathSegments.size() >= 4) {
selection += " AND " + alias + Cols.SIGNATURE + " = ? ";
args.add(pathSegments.get(3));
}
return new QuerySelection(selection, args);
}
示例6: delete
import android.net.Uri; //导入方法依赖的package包/类
@Override
public int delete(final Uri uri, final String selection, final String[] selectionArgs) {
final List<String> pathSegments = uri.getPathSegments();
if (pathSegments.size() != 1)
throw new IllegalArgumentException(uri.toString());
final String address = uri.getLastPathSegment();
final int count = helper.getWritableDatabase().delete(DATABASE_TABLE, KEY_ADDRESS + "=?",
new String[] { address });
if (count > 0)
getContext().getContentResolver().notifyChange(uri, null);
return count;
}
示例7: getUser
import android.net.Uri; //导入方法依赖的package包/类
@Nullable private static Intent getUser(@NonNull Context context, @NonNull Uri uri) {
List<String> segments = uri.getPathSegments();
if (segments != null && !segments.isEmpty() && segments.size() == 1) {
return ProfileActivity.createIntent(context, segments.get(0));
} else if (segments != null && !segments.isEmpty() && segments.size() > 1 && segments.get(0).equalsIgnoreCase("orgs")) {
if ("invitation".equalsIgnoreCase(uri.getLastPathSegment())) {
return null;
} else if ("search".equalsIgnoreCase(uri.getLastPathSegment())) {
String query = uri.getQueryParameter("q");
// return SearchActivity.getIntent(context, query);
} else {
return ProfileActivity.createIntent(context, segments.get(1), true);
}
}
return null;
}
示例8: getVerse
import android.net.Uri; //导入方法依赖的package包/类
private Cursor getVerse(Uri uri) {
int sura = 1;
int ayah = 1;
String langType = getActiveTranslation();
String lang = (TextUtils.isEmpty(langType)) ? null : langType;
if (lang == null) {
return null;
}
List<String> parts = uri.getPathSegments();
for (String s : parts) {
Timber.d("uri part: %s", s);
}
final DatabaseHandler handler = DatabaseHandler.getDatabaseHandler(getContext(), lang);
return handler.getVerse(sura, ayah);
}
示例9: getScopeFromUrl
import android.net.Uri; //导入方法依赖的package包/类
/**
* Generates a scope URL based on the passed in URL. It should be used if the Web Manifest
* does not specify a scope URL.
* @param url The url to convert to a scope.
* @return The scope.
*/
@CalledByNative
public static String getScopeFromUrl(String url) {
// Scope URL is generated by:
// - Removing last component of the URL.
// - Clearing the URL's query and fragment.
Uri uri = Uri.parse(url);
List<String> path = uri.getPathSegments();
int endIndex = path.size();
// If there is at least one path element, remove the last one.
if (endIndex > 0) {
endIndex -= 1;
}
// Make sure the path starts and ends with a slash (or is only a slash if there is no path).
Uri.Builder builder = uri.buildUpon();
String scope_path = "/" + TextUtils.join("/", path.subList(0, endIndex));
if (scope_path.length() > 1) {
scope_path += "/";
}
builder.path(scope_path);
builder.fragment("");
builder.query("");
return builder.build().toString();
}
示例10: getForIssue
import android.net.Uri; //导入方法依赖的package包/类
public static PullsIssuesParser getForIssue(@NonNull String url) {
Uri uri = Uri.parse(url);
List<String> segments = uri.getPathSegments();
if (segments == null || segments.size() < 3) return null;
String owner = null;
String repo = null;
String number = null;
if (segments.size() > 3) {
if (segments.get(2).equalsIgnoreCase("issues")) {
owner = segments.get(0);
repo = segments.get(1);
number = segments.get(3);
} else if (segments.get(3).equalsIgnoreCase("issues") && segments.size() > 4) {
owner = segments.get(1);
repo = segments.get(2);
number = segments.get(4);
} else {
return null;
}
}
if (InputHelper.isEmpty(number))
return null;
int issueNumber;
try {
issueNumber = Integer.parseInt(number);
} catch (NumberFormatException nfe) {
return null;
}
if (issueNumber < 1) return null;
PullsIssuesParser model = new PullsIssuesParser();
model.setLogin(owner);
model.setRepoId(repo);
model.setNumber(issueNumber);
return model;
}
示例11: getDocumentId
import android.net.Uri; //导入方法依赖的package包/类
/**
* Extract the {@link dev.jibovico.apps.sharem.model.DocumentsContract.Document#COLUMN_DOCUMENT_ID} from the given URI.
*
* @see #isDocumentUri(android.content.Context, android.net.Uri)
*/
public static String getDocumentId(Uri documentUri) {
final List<String> paths = documentUri.getPathSegments();
if (paths.size() >= 2 && PATH_DOCUMENT.equals(paths.get(0))) {
return paths.get(1);
}
if (paths.size() >= 4 && PATH_TREE.equals(paths.get(0))
&& PATH_DOCUMENT.equals(paths.get(2))) {
return paths.get(3);
}
throw new IllegalArgumentException("Invalid URI: " + documentUri);
}
示例12: query
import android.net.Uri; //导入方法依赖的package包/类
public Cursor query(
Uri uri,
String[] projection,
String selection,
String[] selectionArgs,
String sortOrder) {
SQLiteDatabase db = dbHelper.getReadableDatabase();
List<String> segments = uri.getPathSegments();
String recordId = segments.get(1);
String name = segments.size() == 4
? segments.get(3)
: null;
SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
builder.setTables("views");
builder.appendWhere("record_id = '" + recordId + "'");
if (name != null) {
builder.appendWhere(" and name = '" + name + "'");
}
Cursor cursor =
builder.query(
db,
projection,
selection,
selectionArgs,
null,
null,
sortOrder);
return cursor;
}
示例13: getZipPathFromUri
import android.net.Uri; //导入方法依赖的package包/类
/**return zip path from a uri like this : zip://path/to/zip.zip/entry
would return /path/to/zip.zip
*/
public static String getZipPathFromUri(Uri uri){
String toTest = "";
for(String seg : uri.getPathSegments()){
if(!seg.startsWith("/"))
toTest+="/";
toTest+=seg;
if(new File(toTest).isFile()) // then we have our zip file
break;
}
return toTest;
}
示例14: getTreeDocumentId
import android.net.Uri; //导入方法依赖的package包/类
/**
* Extract the via {@link dev.jibovico.apps.sharem.model.DocumentsContract.Document#COLUMN_DOCUMENT_ID} from the given URI.
*/
public static String getTreeDocumentId(Uri documentUri) {
final List<String> paths = documentUri.getPathSegments();
if (paths.size() >= 2 && PATH_TREE.equals(paths.get(0))) {
return paths.get(1);
}
throw new IllegalArgumentException("Invalid URI: " + documentUri);
}
示例15: getEnterpriseGistUrl
import android.net.Uri; //导入方法依赖的package包/类
public static String getEnterpriseGistUrl(@NonNull String url, boolean isEnterprise) {
if (isEnterprise) {
Uri uri = Uri.parse(url);
boolean isGist = uri == null || uri.getPathSegments() == null ? url.contains("gist/") : uri.getPathSegments().get(0).equals("gist");
if (isGist) {
String enterpriseUrl = PrefGetter.getEnterpriseUrl();
if (!url.contains(enterpriseUrl + "/raw/")) {
url = url.replace(enterpriseUrl, enterpriseUrl + "/raw");
}
}
}
return url;
}