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


C# Android.Net.Uri.ToString方法代碼示例

本文整理匯總了C#中Android.Net.Uri.ToString方法的典型用法代碼示例。如果您正苦於以下問題:C# Android.Net.Uri.ToString方法的具體用法?C# Android.Net.Uri.ToString怎麽用?C# Android.Net.Uri.ToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Android.Net.Uri的用法示例。


在下文中一共展示了Android.Net.Uri.ToString方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetLocalPath

		/// <summary>
		/// Gets the local path.
		/// </summary>
		/// <param name="uri">The URI.</param>
		/// <returns>System.String.</returns>
		private static string GetLocalPath(Uri uri)
		{
			return new System.Uri(uri.ToString()).LocalPath;
		}
開發者ID:XnainA,項目名稱:InsideInning,代碼行數:9,代碼來源:MediaPickerActivity.cs

示例2: GetFileForUriAsync

		/// <summary>
		/// Gets the file for URI asynchronous.
		/// </summary>
		/// <param name="context">The context.</param>
		/// <param name="uri">The URI.</param>
		/// <param name="isPhoto">if set to <c>true</c> [is photo].</param>
		/// <returns>Task&lt;Tuple&lt;System.String, System.Boolean&gt;&gt;.</returns>
		internal static Task<Tuple<string, bool>> GetFileForUriAsync(Context context, Uri uri, bool isPhoto)
		{
			var tcs = new TaskCompletionSource<Tuple<string, bool>>();

			if (uri.Scheme == "file")
				tcs.SetResult(new Tuple<string, bool>(new System.Uri(uri.ToString()).LocalPath, false));
			else if (uri.Scheme == "content")
			{
				Task.Factory.StartNew(() =>
				{
					ICursor cursor = null;
					try
					{
						cursor = context.ContentResolver.Query(uri, null, null, null, null);
						if (cursor == null || !cursor.MoveToNext())
							tcs.SetResult(new Tuple<string, bool>(null, false));
						else
						{
							int column = cursor.GetColumnIndex(MediaStore.MediaColumns.Data);
							string contentPath = null;

							if (column != -1)
								contentPath = cursor.GetString(column);

							bool copied = false;

							// If they don't follow the "rules", try to copy the file locally
//							if (contentPath == null || !contentPath.StartsWith("file"))
//							{
//								copied = true;
//								Uri outputPath = GetOutputMediaFile(context, "temp", null, isPhoto);
//
//								try
//								{
//									using (Stream input = context.ContentResolver.OpenInputStream(uri))
//									using (Stream output = File.Create(outputPath.Path))
//										input.CopyTo(output);
//
//									contentPath = outputPath.Path;
//								}
//								catch (FileNotFoundException)
//								{
//									// If there's no data associated with the uri, we don't know
//									// how to open this. contentPath will be null which will trigger
//									// MediaFileNotFoundException.
//								}
//							}

							tcs.SetResult(new Tuple<string, bool>(contentPath, copied));
						}
					}
					finally
					{
						if (cursor != null)
						{
							cursor.Close();
							cursor.Dispose();
						}
					}
				}, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
			}
			else
				tcs.SetResult(new Tuple<string, bool>(null, false));

			return tcs.Task;
		}
開發者ID:XnainA,項目名稱:InsideInning,代碼行數:73,代碼來源:MediaPickerActivity.cs

示例3: SetImageURI

 public override void SetImageURI(Uri uri)
 {
     base.SetImageURI(uri);
     var stream = Application.Context.ContentResolver.OpenInputStream(uri);
     var drawable = Drawable.CreateFromStream(stream, uri.ToString());
     _mBitmap = GetBitmapFromDrawable(drawable);
     Setup();
 }
開發者ID:blocke79,項目名稱:CircleImageView-Xamarin,代碼行數:8,代碼來源:CircleImageView.cs

示例4: GetMediaFileAsync

		/// <summary>
		/// Gets the media file asynchronous.
		/// </summary>
		/// <param name="context">The context.</param>
		/// <param name="requestCode">The request code.</param>
		/// <param name="action">The action.</param>
		/// <param name="isPhoto">if set to <c>true</c> [is photo].</param>
		/// <param name="path">The path.</param>
		/// <param name="data">The data.</param>
		/// <returns>Task&lt;MediaPickedEventArgs&gt;.</returns>
		internal static Task<MediaPickedEventArgs> GetMediaFileAsync(Context context, int requestCode, string action,
			bool isPhoto, ref Uri path, Uri data)
		{
			Task<Tuple<string, bool>> pathFuture;
			Action<bool> dispose = null;
			string originalPath = null;

			if (action != Intent.ActionPick)
			{
				originalPath = path.Path;

				// Not all camera apps respect EXTRA_OUTPUT, some will instead
				// return a content or file uri from data.
				if (data != null && data.Path != originalPath)
				{
					originalPath = data.ToString();
					var currentPath = path.Path;

					pathFuture = TryMoveFileAsync(context, data, path, isPhoto).ContinueWith(t =>
						new Tuple<string, bool>(t.Result ? currentPath : null, false));
				}
				else
					pathFuture = TaskUtils.TaskFromResult(new Tuple<string, bool>(path.Path, false));
			}
			else if (data != null)
			{
				originalPath = data.ToString();
				path = data;
				pathFuture = GetFileForUriAsync(context, path, isPhoto);
			}
			else
			{
				pathFuture = TaskUtils.TaskFromResult<Tuple<string, bool>>(null);
			}

			return pathFuture.ContinueWith(t =>
			{
				string resultPath = t.Result.Item1;
				if (resultPath != null && File.Exists(t.Result.Item1))
				{
					if (t.Result.Item2)
					{
						dispose = d => File.Delete(resultPath);
					}

					var mf = new MediaFile(resultPath, () => File.OpenRead(t.Result.Item1) , dispose);

					return new MediaPickedEventArgs(requestCode, false, mf);
				}
				return new MediaPickedEventArgs(requestCode, new MediaFileNotFoundException(originalPath));
			});
		}
開發者ID:XnainA,項目名稱:InsideInning,代碼行數:62,代碼來源:MediaPickerActivity.cs

示例5: HtmlElement

 public HtmlElement(string caption, Uri uri)
     : base(caption, uri.ToString(), "dialog_labelfieldright")
 {
     Url = uri;
 }
開發者ID:runegri,項目名稱:Android.Dialog,代碼行數:5,代碼來源:HtmlElement.cs


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