2017-07-26 29 views
0

我目前正在Xamarin Native Android中開發Android應用程序。我需要打開一個電子郵件URL一旦按下按鈕,但我收到錯誤。設備在當前上下文中不存在Xamarin Android開發

「CS0103 C#中的名稱‘設備’並不在當前的背景下存在」

這是我的代碼。當我點擊試圖導入任何東西時,它建議我導入藍牙類毫不奇怪,這是行不通的。

 Email.Click += delegate { 
      Device.OpenUri(new Uri("mailto:[email protected]")); 
     }; 

任何人都可以幫忙嗎?

感謝 喬

+0

設備是靜態類。你在使用Xamarin Forms嗎? – Jason

+0

你好傑森,我不使用Xamarin形式。 – JAVAJoseph

回答

1

在Android中,您將在Xamarin.Forms命名空間中這樣做是爲了open a URL

intent.button.Click += delegate { 
     var uri = Android.Net.Uri.Parse ("http://www.xamarin.com"); 
     var intent = new Intent (Intent.ActionView, uri); 
     StartActivity (intent); 
}; 
+0

我將如何打開默認的電子郵件客戶端?與預先填充的電子郵件地址? – JAVAJoseph

+0

https://developer.xamarin.com/recipes/android/networking/email/send_an_email/ – Jason

+0

謝謝賈森有點修修補補我得到它的工作。我對於我的投票登記太新了,但我對你的回答投了贊成票。 – JAVAJoseph

1

我的解決方案

  Email.Click += delegate { 
      Intent email = new Intent(Intent.ActionSend); 
      email.PutExtra(Intent.ExtraEmail, "[email protected]"); 
      email.PutExtra(Intent.ExtraSubject, "Subject Area"); 
      email.PutExtra(Intent.ExtraText, "Subject"); 
      email.SetType("messsage/rfc822"); 
      StartActivity(Intent.CreateChooser(email, "Send Email Via")); 

     }; 
相關問題