本文整理匯總了Java中android.net.Uri類的典型用法代碼示例。如果您正苦於以下問題:Java Uri類的具體用法?Java Uri怎麽用?Java Uri使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Uri類屬於android.net包,在下文中一共展示了Uri類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doInBackground
import android.net.Uri; //導入依賴的package包/類
@Override
protected Boolean doInBackground(String... params) {
String szFilename = params[0];
if (szFilename == null || szFilename.length() == 0) {
Log.e(MFBConstants.LOG_TAG, "No filename passed back!!!");
return false;
}
// Add the image/video to the gallery if necessary (i.e., if from the camera)
if (fAddToGallery) {
File f = new File(szFilename);
Uri uriSource = FileProvider.getUriForFile(ActMFBForm.this.getContext(), "com.example.android.fileprovider", f);
ActMFBForm.this.getActivity().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uriSource));
}
GallerySource gs = (GallerySource) ActMFBForm.this;
mfbii = new MFBImageInfo(gs.getDestination());
return mfbii.initFromCamera(szFilename, fGeoTag ? MFBLocation.LastSeenLoc() : null, m_fVideo, fDeleteFileWhenDone);
}
示例2: delete
import android.net.Uri; //導入依賴的package包/類
@Override
public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) {
createDbIfNotExists();
SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
if (Binder.getCallingPid() != Process.myPid()
&& Favorites.TABLE_NAME.equalsIgnoreCase(args.table)) {
mOpenHelper.removeGhostWidgets(mOpenHelper.getWritableDatabase());
}
int count = db.delete(args.table, args.where, args.args);
if (count > 0) {
notifyListeners();
reloadLauncherIfExternal();
}
return count;
}
示例3: initImagePicker
import android.net.Uri; //導入依賴的package包/類
/**
* 初始化仿微信控件ImagePicker
*/
private void initImagePicker() {
ImagePicker imagePicker = ImagePicker.getInstance();
imagePicker.setImageLoader(new ImageLoader() {
@Override
public void displayImage(Activity activity, String path, ImageView imageView, int width, int height) {
Glide.with(getContext()).load(Uri.parse("file://" + path).toString()).centerCrop().into(imageView);
}
@Override
public void clearMemoryCache() {
}
}); //設置圖片加載器
imagePicker.setShowCamera(true); //顯示拍照按鈕
imagePicker.setCrop(true); //允許裁剪(單選才有效)
imagePicker.setSaveRectangle(true); //是否按矩形區域保存
imagePicker.setSelectLimit(9); //選中數量限製
imagePicker.setStyle(CropImageView.Style.RECTANGLE); //裁剪框的形狀
imagePicker.setFocusWidth(800); //裁剪框的寬度。單位像素(圓形自動取寬高最小值)
imagePicker.setFocusHeight(800); //裁剪框的高度。單位像素(圓形自動取寬高最小值)
imagePicker.setOutPutX(1000);//保存文件的寬度。單位像素
imagePicker.setOutPutY(1000);//保存文件的高度。單位像素
}
示例4: enterFragment
import android.net.Uri; //導入依賴的package包/類
/**
* 加載會話頁麵 ConversationFragmentEx 繼承自 ConversationFragment
*
* @param mConversationType 會話類型
* @param mTargetId 會話 Id
*/
private void enterFragment(Conversation.ConversationType mConversationType, String mTargetId) {
fragment = new ConversationFragmentEx();
Uri uri = Uri.parse("rong://" + getApplicationInfo().packageName).buildUpon()
.appendPath("conversation").appendPath(mConversationType.getName().toLowerCase())
.appendQueryParameter("targetId", mTargetId).build();
fragment.setUri(uri);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
//xxx 為你要加載的 id
transaction.add(R.id.rong_content, fragment);
transaction.commitAllowingStateLoss();
}
示例5: openCalendar
import android.net.Uri; //導入依賴的package包/類
@TargetApi(14)
private void openCalendar(JSONArray args) {
try {
final Long millis = args.getJSONObject(0).optLong("date");
cordova.getThreadPool().execute(new Runnable() {
@Override
public void run() {
final Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon().appendPath("time");
ContentUris.appendId(builder, millis);
final Intent intent = new Intent(Intent.ACTION_VIEW).setData(builder.build());
Calendar.this.cordova.startActivityForResult(Calendar.this, intent, RESULT_CODE_OPENCAL);
callback.success();
}
});
} catch (JSONException e) {
System.err.println("Exception: " + e.getMessage());
callback.error(e.getMessage());
}
}
示例6: add
import android.net.Uri; //導入依賴的package包/類
public Observable<Account> add(final AccessToken accessToken) {
ContentValues values = new ContentValues();
values.put(AccountContract.TOKEN, accessToken.getToken());
values.put(AccountContract.TOKEN_SECRET, accessToken.getTokenSecret());
values.put(AccountContract.SCREEN_NAME, accessToken.getScreenName());
values.put(AccountContract.USER_ID, accessToken.getUserId());
return mSqlBriteContentProvider
.insert(AccountContract.CONTENT_URI, values)
.flatMap(new Func1<Uri, Observable<SqlBriteContentProvider.Query>>() {
@Override
public Observable<SqlBriteContentProvider.Query> call(Uri uri) {
return mSqlBriteContentProvider
.query(uri, AccountContract.PROJECTION,
null, null, null, false);
}
})
.map(MapFunctions.ACCOUNT)
.take(1);
}
示例7: extractBaseUri
import android.net.Uri; //導入依賴的package包/類
/**
* Looks for the base URI
* <p>
* https://tools.ietf.org/html/rfc2326#appendix-C.1.1
*
* @param res RtspResponse
* @return Base URI
*/
Uri extractBaseUri(RtspRequest req, RtspResponse res) throws URISyntaxException {
Uri baseUri = null;
// 1. The RTSP Content-Base field
String contentBase = res.getContentBase();
if (contentBase != null) baseUri = Uri.parse(res.getContentBase());
// 2. The RTSP Content-Location field
String contentLocation = res.getContentLocation();
if (baseUri == null && contentLocation != null) {
baseUri = Uri.parse(res.getContentLocation());
}
// 3. The RTSP request URL
if (baseUri == null) baseUri = req.getUri();
return baseUri;
}
示例8: mapUriToFile
import android.net.Uri; //導入依賴的package包/類
/**
* Returns a File that points to the resource, or null if the resource
* is not on the local filesystem.
*/
public File mapUriToFile(Uri uri) {
assertBackgroundThread();
switch (getUriType(uri)) {
case URI_TYPE_FILE:
return new File(uri.getPath());
case URI_TYPE_CONTENT: {
Cursor cursor = contentResolver.query(uri, LOCAL_FILE_PROJECTION, null, null, null);
if (cursor != null) {
try {
int columnIndex = cursor.getColumnIndex(LOCAL_FILE_PROJECTION[0]);
if (columnIndex != -1 && cursor.getCount() > 0) {
cursor.moveToFirst();
String realPath = cursor.getString(columnIndex);
if (realPath != null) {
return new File(realPath);
}
}
} finally {
cursor.close();
}
}
}
}
return null;
}
示例9: takePicture
import android.net.Uri; //導入依賴的package包/類
public void takePicture() {
try {
mPhotoPath = sdcardPath + "/icon.png";
mPhotoFile = new File(mPhotoPath);
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (Build.VERSION.SDK_INT >= 23) {
Uri uri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".provider", mPhotoFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
}else {
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mPhotoFile));
}
startActivityForResult(intent, 1);
} catch (Exception e) {
}
}
示例10: ShareSingleImage
import android.net.Uri; //導入依賴的package包/類
/**
* 分享單張圖片至所有第三方軟件
*/
public static void ShareSingleImage(Context context, File file) {
Uri imageUri;
if (Build.VERSION.SDK_INT >= 24) {
imageUri = FileProvider.getUriForFile(context,"com.hzecool.common.fileProvider", file);
} else {
imageUri = Uri.fromFile(file);
}
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/*");
context.startActivity(Intent.createChooser(shareIntent, "分享到"));
}
示例11: onCreateLoader
import android.net.Uri; //導入依賴的package包/類
@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
return new CursorLoader(this,
// Retrieve data rows for the device user's 'profile' contact.
Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION,
// Select only email addresses.
ContactsContract.Contacts.Data.MIMETYPE +
" = ?", new String[]{ContactsContract.CommonDataKinds.Email
.CONTENT_ITEM_TYPE},
// Show primary email addresses first. Note that there won't be
// a primary email address if the user hasn't specified one.
ContactsContract.Contacts.Data.IS_PRIMARY + " DESC");
}
示例12: start
import android.net.Uri; //導入依賴的package包/類
@Override
public Uri start(Activity activity, MediaResult mediaResult, PhotoParams photoParams) {
Log.d(getClass().getName(), "pick gallery");
if (hasPicker(activity)) {
if (FeatureUtils.isSdAvailable()) {
activity.startActivityForResult(intent, mediaResult.getRequestCode());
return createExternalUri(activity.getApplicationContext());
}else {
mediaResultListener.onPickMediaResult(mediaResult, activity.getString(R.string.error_please_plug_sd_card));
}
} else {
mediaResultListener.onPickMediaResult(mediaResult, photoParams.getNoGalleryMsg());
}
return Uri.EMPTY;
}
示例13: getRealPathFromUri
import android.net.Uri; //導入依賴的package包/類
public static String getRealPathFromUri(Context context, Uri uri) {
if (uri != null) {
Helper.showLog(TAG, uri.toString());
}
String realPath = null;
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(uri, new String[]{"_data"}, null, null,
null);
if (cursor != null) {
int column_index = cursor.getColumnIndexOrThrow("_data");
cursor.moveToFirst();
realPath = cursor.getString(column_index);
}
Helper.showLog(TAG + "real path", realPath);
return realPath;
} finally {
if (cursor != null) {
cursor.close();
}
}
}
示例14: getType
import android.net.Uri; //導入依賴的package包/類
@Nullable
@Override
public String getType(@NonNull Uri uri) {
int match = sUriMATCHER.match(uri);
switch (match) {
case ITEM_TASKS:
return "vnd.android.cursor.dir" + "/" + TaskItemsContract.AUTHORITY + "/" + TaskItemsContract.PATH_TASK_ITEMS;
case ITEM_TASKS_WITH_ID:
return "vnd.android.cursor.item" + "/" + TaskItemsContract.AUTHORITY + "/" + TaskItemsContract.PATH_TASK_ITEMS;
case ITEM_TASKS_TODAY:
return "vnd.android.cursor.dir" + "/" + TaskItemsContract.AUTHORITY + "/" + TaskItemsContract.PATH_TASK_ITEMS + "/" + COLUMN_NAME_IS_TODAY;
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
}
}
示例15: getUriFromMediaStore
import android.net.Uri; //導入依賴的package包/類
/**
* Create entry in media store for image
*
* @return uri
*/
private Uri getUriFromMediaStore() {
ContentValues values = new ContentValues();
values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
Uri uri;
try {
uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
} catch (RuntimeException e) {
LOG.d(LOG_TAG, "Can't write to external media storage.");
try {
uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
} catch (RuntimeException ex) {
LOG.d(LOG_TAG, "Can't write to internal media storage.");
return null;
}
}
return uri;
}