当前位置: 首页>>代码示例>>C#>>正文


C# Intent.SetDataAndType方法代码示例

本文整理汇总了C#中Android.Content.Intent.SetDataAndType方法的典型用法代码示例。如果您正苦于以下问题:C# Intent.SetDataAndType方法的具体用法?C# Intent.SetDataAndType怎么用?C# Intent.SetDataAndType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Android.Content.Intent的用法示例。


在下文中一共展示了Intent.SetDataAndType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: openPDF

        private void openPDF(SavedExpenseForm selectedExpenseForm)
        {
            try {
                var pathToPdf = global::Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
                pathToPdf = Path.Combine (pathToPdf, selectedExpenseForm.ID.ToString () + ".pdf");

                Backend.Current.getFormPDF (selectedExpenseForm.ID, pathToPdf);
                Console.WriteLine ("PDF: " + pathToPdf);
                Java.IO.File myFile = new Java.IO.File (pathToPdf);

                Console.WriteLine ("File Uri: " + myFile.ToString ());

                Android.Net.Uri targetUri = global::Android.Net.Uri.FromFile (myFile);
                Intent intent = new Intent (Intent.ActionView);
                intent.SetDataAndType (targetUri, "application/pdf");

                StartActivity (intent); // Adobe reader does not want to open the pdf...
            }
            catch (ActivityNotFoundException e)
            {
                Toast.MakeText (this, "No PDF viewer installed.", ToastLength.Short).Show ();
            }
            catch (Exception ex)
            {
                Toast.MakeText (this, ex.Message, ToastLength.Short).Show ();
            }
        }
开发者ID:bertouttier,项目名称:ExpenseApp-Mono,代码行数:27,代码来源:ExpenseFormOverviewActivity.cs

示例2: OnCreateView

        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            base.OnCreateView (inflater, container, savedInstanceState);
            var view = inflater.Inflate (Resource.Layout.DocumentFragmentLayout, null, true);

            documentListView = view.FindViewById<ListView> (Resource.Id.documentsListView);
            if (Documents != null)
                documentListView.Adapter = new DocumentsAdapter (Activity, Resource.Layout.DocumentListItemLayout, Documents);

            documentListView.ItemClick += (sender, e) => {
                var textView = e.View.FindViewById<TextView> (Resource.Id.documentListItemDocTitle);

                var document = Documents.ElementAtOrDefault ((int)textView.Tag);

                //start intent with the uri path of the document
                var strings = document.Path.Split ('/');
                CopyReadAsset (strings [1]);
                var intent = new Intent (Intent.ActionView);
                var uri = Uri.FromFile (file);
                intent.SetDataAndType (uri, "application/pdf");
                intent.SetFlags (ActivityFlags.ClearTop);
                try {
                    Activity.StartActivity (intent);
                } catch (ActivityNotFoundException exc) {
                    Log.WriteLine (LogPriority.Error, Constants.LogTag, exc.Message);
                }
            };

            return view;
        }
开发者ID:tranuydu,项目名称:prebuilt-apps,代码行数:30,代码来源:DocumentFragment.cs

示例3: performCrop

		/**
	     * Helper method to carry out crop operation
	     */
		private void performCrop(){
			//take care of exceptions
			try {
				//call the standard crop action intent (the user device may not support it)
				Intent cropIntent = new Intent("com.android.camera.action.CROP"); 
				//indicate image type and Uri
				cropIntent.SetDataAndType(picUri, "image/*");
				//set crop properties
				cropIntent.PutExtra("crop", "true");
				//indicate aspect of desired crop
				cropIntent.PutExtra("aspectX", 1);
				cropIntent.PutExtra("aspectY", 1);
				//indicate output X and Y
				cropIntent.PutExtra("outputX", 256);
				cropIntent.PutExtra("outputY", 256);
				//retrieve data on return
				cropIntent.PutExtra("return-data", true);
				//start the activity - we handle returning in onActivityResult
				StartActivityForResult(cropIntent, PIC_CROP);  
			}
			//respond to users whose devices do not support the crop action
			catch(ActivityNotFoundException anfe){
				//display an error message
				String errorMessage = "Whoops - your device doesn't support the crop action!";
				Toast toast = Toast.MakeText(this, errorMessage, ToastLength.Short);
				toast.Show();
			}
		}
开发者ID:jeedey93,项目名称:xamarin-android-samples,代码行数:31,代码来源:MainActivity.cs

示例4: Open

        public bool Open(string fileName) {
            if (String.IsNullOrWhiteSpace(fileName))
                return false;

            var dataType = GetMimeType(fileName);

            // external apps do not have access to cache directory, copy from the cache to an external location
            var newPath = Path.Combine(
                this.externalDirectory,
                Path.GetFileName(fileName)
            );
            File.Copy(fileName, newPath, true);

            try {
                var file = new Java.IO.File(newPath);
                var uri = Android.Net.Uri.FromFile(file);
                var intent = new Intent(Intent.ActionView);
                intent.SetDataAndType(uri, dataType);
                Forms.Context.StartActivity(intent);
                return true;
            }
            catch {
                return false;
            }
        }
开发者ID:rodyla,项目名称:acr-xamarin-forms,代码行数:25,代码来源:FileViewer.cs

示例5: ShowImage

		public void ShowImage (string imageURL)
		{
			Intent intent = new Intent();
			intent.AddFlags (ActivityFlags.NewTask);
			intent.SetAction(Intent.ActionView);
			intent.SetDataAndType(Android.Net.Uri.Parse(imageURL), "image/*");
			Application.Context.StartActivity(intent);
		}
开发者ID:praveenmohanmm,项目名称:PurposeColor_Bkp_Code,代码行数:8,代码来源:AndroidMediaView.cs

示例6: DisplayPDF

 public Intent DisplayPDF(Java.IO.File file)
 {
     Intent intent = new Intent (Intent.ActionView);
     Android.Net.Uri filepath = Android.Net.Uri.FromFile (file);
     intent.SetDataAndType (filepath, "application/pdf");
     intent.SetFlags (ActivityFlags.ClearTop);
     return intent;
 }
开发者ID:Mogikan,项目名称:iTextSharpLGPL-MonoForAndroid,代码行数:8,代码来源:MainActivity.cs

示例7: OpenPreview

        public override void OpenPreview(Android.App.Activity androidActivity)
        {
            if (ContactId != null)
            {
                var intent = new Intent(Intent.ActionView);
                intent.SetDataAndType(
                    Android.Net.Uri.WithAppendedPath(ContactsContract.Contacts.ContentUri, ContactId),
                    ContactsContract.Contacts.ContentType);

                androidActivity.StartActivity(intent);
            }
        }
开发者ID:fubar-coder,项目名称:cryptrans,代码行数:12,代码来源:ContactTransfer.cs

示例8: VideoTouched

        private void VideoTouched(object sender, System.EventArgs e)
        {
            if (video != null)
            {
                video.StopPlayback();
                video.Dispose();
                video = null;
            }

            Uri videoUri = Uri.Parse(videoAdd);
            Intent intent = new Intent(Intent.ActionView, videoUri);
            intent.SetDataAndType(videoUri, "video/mp4");
            Activity.StartActivity(intent);
            this.Dismiss();
        } 
开发者ID:GSDan,项目名称:Speeching_Client,代码行数:15,代码来源:VideoPlayerFragment.cs

示例9: OnCreate

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);
            Edit = FindViewById<AutoCompleteTextView>(Resource.Id.Edit);

            Button button = FindViewById<Button>(Resource.Id.MyButton);

            button.Click += delegate {
                string EditText = Edit.Text;

                Intent intent = new Intent(Intent.ActionView, Android.Net.Uri.Parse("http://test.mp4"));
                intent.SetDataAndType(Android.Net.Uri.Parse(EditText), "video/mp4");
                StartActivity(intent);
            };
        }
开发者ID:heavykick,项目名称:MilkVRLauncher,代码行数:16,代码来源:MainActivity.cs

示例10: Download

        public async Task<bool> Download(string uri, string filename)
        {

            string downloadedFolder = "/storage/emulated/0/Download/";
            if (App.DownloadsPath != null && !string.IsNullOrEmpty(App.DownloadsPath))
            {
                downloadedFolder = App.DownloadsPath + "/";
            }

			string fileExtenstion = Path.GetExtension(filename);

			if (fileExtenstion == ".jpg" || fileExtenstion == ".jpeg" || fileExtenstion == ".png")
				return false;

            if (System.IO.File.Exists(downloadedFolder + filename))
            {
                string downloadedUri = "file://" + downloadedFolder + filename;
                Java.IO.File file = new Java.IO.File(new Java.Net.URI( downloadedUri ));
                Intent videoPlayerActivity = new Intent(Intent.ActionView);
                videoPlayerActivity.SetDataAndType(Android.Net.Uri.FromFile(file), "video/*");
                Activity activity = Forms.Context as Activity;
                activity.StartActivity(videoPlayerActivity);
                return true;
            }
          
            App.DownloadID = 0;

            Android.Net.Uri contentUri = Android.Net.Uri.Parse(uri);

            Android.App.DownloadManager.Request r = new Android.App.DownloadManager.Request(contentUri);


            r.SetDestinationInExternalPublicDir(Android.OS.Environment.ExternalStorageDirectory.ToString(), filename);

            r.AllowScanningByMediaScanner();

            r.SetNotificationVisibility(Android.App.DownloadVisibility.VisibleNotifyCompleted);

            Android.App.DownloadManager dm = (Android.App.DownloadManager)Xamarin.Forms.Forms.Context.GetSystemService(Android.Content.Context.DownloadService);

            App.DownloadID = dm.Enqueue(r);

            AndHUD.Shared.Show(MainActivity.GetMainActivity(), "Dowloading Media...", -1, MaskType.Clear, null, () => { dm.Remove(App.DownloadID); }, true, () => { dm.Remove(App.DownloadID); });


            return true;
        }
开发者ID:praveenmohanmm,项目名称:PurposeColor_Bkp_Code,代码行数:47,代码来源:AndroidVideoPlayer.cs

示例11: PerformCrop

        private void PerformCrop(Uri picUri, Action<string> callbackResult, string path)
        {
            Intent cropIntent = new Intent("com.android.camera.action.CROP");
            // indicate image type and Uri
            cropIntent.SetDataAndType(picUri, "image/*");
            // set crop properties
            cropIntent.PutExtra("crop", "true");
            // indicate aspect of desired crop
            cropIntent.PutExtra("aspectX", 1);
            cropIntent.PutExtra("aspectY", 1);
            // retrieve data on return
            cropIntent.PutExtra(MediaStore.ExtraOutput, picUri);
            // start the activity - we handle returning in onActivityResult
            ActivityService.StartActivityForResult(cropIntent, (result, data) =>
            {
				callbackResult(result == Result.Ok ? path : null);
            });
        }
开发者ID:india-rose,项目名称:xamarin-indiarose,代码行数:18,代码来源:MediaService.cs

示例12: Save

        public void Save(string fileName, String contentType, MemoryStream stream)
        {
            string exception = string.Empty;
            string root = null;
            if (Android.OS.Environment.IsExternalStorageEmulated)
            {
                root = Android.OS.Environment.ExternalStorageDirectory.ToString();
            }
            else
                root = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            Java.IO.File myDir = new Java.IO.File(root + "/Syncfusion");
            myDir.Mkdir();

            Java.IO.File file = new Java.IO.File(myDir, fileName);

            if (file.Exists()) file.Delete();

            try
            {
                FileOutputStream outs = new FileOutputStream(file);
                outs.Write(stream.ToArray());

                outs.Flush();
                outs.Close();
            }
            catch (Exception e)
            {
                exception = e.ToString();
            }
            if (file.Exists() && contentType != "application/html")
            {
                Android.Net.Uri path = Android.Net.Uri.FromFile(file);
                string extension = Android.Webkit.MimeTypeMap.GetFileExtensionFromUrl(Android.Net.Uri.FromFile(file).ToString());
                string mimeType = Android.Webkit.MimeTypeMap.Singleton.GetMimeTypeFromExtension(extension);
                Intent intent = new Intent(Intent.ActionView);
                intent.SetDataAndType(path, mimeType);
                Forms.Context.StartActivity(Intent.CreateChooser(intent, "Choose App"));

            }
        }
开发者ID:IanLeatherbury,项目名称:tryfsharpforms,代码行数:41,代码来源:SaveAndroid.cs

示例13: OnDownloadUpdate

        private void OnDownloadUpdate(object sender, DoWorkEventArgs args)
        {
            String path = Android.Os.Environment.GetExternalStoragePublicDirectory(Android.Os.Environment.DIRECTORY_DOWNLOADS) + "/JGCompanion.apk";

            try
            {
                WebClient client = new WebClient();
                client.DownloadFile(args.Argument.ToString(), path);

                Intent i = new Intent();
                i.SetAction(Intent.ACTION_VIEW);
                i.SetDataAndType(Android.Net.Uri.FromFile(new Java.Io.File(path)), "application/vnd.android.package-archive");
                Log.D("JGCompanion", "Starting auto-update");
                MainActivity.StartActivityOnMain(i);
            }
            catch (Exception ex)
            {
                Log.E("JGCompanion", "Error during auto-update!");
                Log.E("JGCompanion", ex.Message);
            }
        }
开发者ID:sschocke,项目名称:JGCompanion,代码行数:21,代码来源:AutoUpdateDialog.cs

示例14: Open

		public bool Open(IFile file) {
			try {
				// external apps do not have access to cache directory, copy from the cache to an external location
				var newPath = this.GetReadPath(file.Name);
				file.CopyTo(newPath);

				var javaFile = new Java.IO.File(newPath);
				var uri = Android.Net.Uri.FromFile(javaFile);
				var intent = new Intent(Intent.ActionView);
				intent.SetDataAndType(uri, file.MimeType);
				if (!IsIntentManagable(intent))
					return false;

				this.StartActivity(intent);
				return true;
			}
			catch (Exception ex) {
				Mvx.Warning(ex.ToString());
				return false;
			}
		}
开发者ID:Mvvmcross-Cn,项目名称:acrmvvmcross,代码行数:21,代码来源:FileViewerImpl.cs

示例15: ShowPdfFile

	    public void ShowPdfFile(string pdfFileName)
        {
            string path = Path.Combine(CurrentActivity.GetExternalFilesDir(null).AbsolutePath, pdfFileName);

            if (!File.Exists(path))
            {
                try
                {
                    FileStream output = File.OpenWrite(path);
					Stream input = CurrentActivity.Assets.Open(pdfFileName);
                    input.CopyTo(output);
                    input.Close();
                    output.Flush();
                    output.Close();
                }
                catch (Exception)
                {
                    LoggerService.Log(string.Format("ResourceService.ShowPdfFile() : Cannot create external file {0}", path), MessageSeverity.Error);
                }
            }
            try
            {
                Intent intent = new Intent(Intent.ActionView);
                intent.SetDataAndType(Uri.Parse("file://" + path), "application/pdf");
				CurrentActivity.StartActivity(intent);
            }
            catch (Exception)
            {
                try
                {
					CurrentActivity.StartActivity(new Intent(Intent.ActionView, Uri.Parse("market://search?q=pdf&c=apps")));
                }
                catch (ActivityNotFoundException)
                {
					CurrentActivity.StartActivity(new Intent(Intent.ActionView, Uri.Parse("https://play.google.com/store/search?q=pdf&c=apps")));
                }
            }

        }
开发者ID:india-rose,项目名称:xamarin-indiarose,代码行数:39,代码来源:ResourceService.cs


注:本文中的Android.Content.Intent.SetDataAndType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。