protected virtual void OnSelectItemClicked(object sender, EventArgs e) { var intent = new Intent(this, typeof(SecondActivity)); // Put the items list into the intent intent.PutParcelableArrayListExtra(SecondActivity.ItemsValueKey, Items); // Start up the activity, requesting a result back StartActivityForResult(intent, 0); }
/// <summary> /// Start to select photo. /// </summary> /// <param name="requestCode"> identity of the requester activity. </param> public void ForResult(int requestCode) { if (engine == null) { throw new ExceptionInInitializerError(LoadEngine.INITIALIZE_ENGINE_ERROR); } Activity activity = Activity; if (activity == null) { return; // cannot continue; } mSelectionSpec.MimeTypes = MimeTypes; mSelectionSpec.Engine = engine; Intent intent = new Intent(activity, typeof(ImageSelectActivity)); intent.PutExtra(ImageSelectActivity.EXTRA_SELECTION_SPEC, mSelectionSpec); // intent.putExtra(ImageSelectActivity.EXTRA_ENGINE, (Serializable) engine); intent.PutParcelableArrayListExtra(ImageSelectActivity.EXTRA_RESUME_LIST, mResumeList.AsIParcelableList()); Fragment fragment = Fragment; if (fragment != null) { fragment.StartActivityForResult(intent, requestCode); } else { activity.StartActivityForResult(intent, requestCode); } hasInitPicker = false; }
public void SendEmail(IEmailMessage email) { // NOTE: http://developer.xamarin.com/recipes/android/networking/email/send_an_email/ if (email == null) throw new ArgumentNullException("email"); if (CanSendEmail) { // NOTE: http://developer.android.com/guide/components/intents-common.html#Email string intentAction = Intent.ActionSend; if (email.Attachments.Count > 1) intentAction = Intent.ActionSendMultiple; Intent emailIntent = new Intent(intentAction); emailIntent.SetType("message/rfc822"); if (email.Recipients.Count > 0) emailIntent.PutExtra(Intent.ExtraEmail, email.Recipients.ToArray()); if (email.RecipientsCc.Count > 0) emailIntent.PutExtra(Intent.ExtraCc, email.RecipientsCc.ToArray()); if (email.RecipientsBcc.Count > 0) emailIntent.PutExtra(Intent.ExtraBcc, email.RecipientsBcc.ToArray()); emailIntent.PutExtra(Intent.ExtraSubject, email.Subject); // NOTE: http://stackoverflow.com/questions/13756200/send-html-email-with-gmail-4-2-1 if (((EmailMessage)email).IsHtml) emailIntent.PutExtra(Intent.ExtraText, Html.FromHtml(email.Message)); else emailIntent.PutExtra(Intent.ExtraText, email.Message); if (email.Attachments.Count > 0) { var uris = new List<IParcelable>(); foreach (var attachment in email.Attachments) { var uri = Android.Net.Uri.Parse("file://" + ((EmailAttachment)attachment).FilePath); uris.Add(uri); } if (uris.Count > 1) emailIntent.PutParcelableArrayListExtra(Intent.ExtraStream, uris); else emailIntent.PutExtra(Intent.ExtraStream, uris[0]); } emailIntent.StartNewActivity(); } }
public async Task OpenEmailManager(string[] emails, string subject, string text, string[] attachments) { var email = new Intent(Intent.ActionSendMultiple); email.PutExtra(Intent.ExtraSubject, subject); email.PutExtra(Intent.ExtraText, text); email.PutExtra(Intent.ExtraEmail, emails); var uris = new List<IParcelable>(); foreach (string attachment in attachments) if (!string.IsNullOrWhiteSpace(attachment)) using (var file = new Java.IO.File(attachment)) { Uri uri = Uri.FromFile(file); uris.Add(uri); } email.PutParcelableArrayListExtra(Intent.ExtraStream, uris); email.SetType("plain/text"); await _activity.StartActivityForResultAsync(email); // anyway result == Rasult.Cancelled uris.ForEach(val => val.Dispose()); }
public void ComposeEmail( IEnumerable<string> to, IEnumerable<string> cc = null, string subject = null, string body = null, bool isHtml = false, IEnumerable<EmailAttachment> attachments = null, string dialogTitle = null) { // http://stackoverflow.com/questions/2264622/android-multiple-email-attachments-using-intent var emailIntent = new Intent(Intent.ActionSendMultiple); if (to != null) { emailIntent.PutExtra(Intent.ExtraEmail, to.ToArray()); } if (cc != null) { emailIntent.PutExtra(Intent.ExtraCc, cc.ToArray()); } emailIntent.PutExtra(Intent.ExtraSubject, subject ?? string.Empty); body = body ?? string.Empty; if (isHtml) { emailIntent.SetType("text/html"); emailIntent.PutExtra(Intent.ExtraText, Html.FromHtml(body)); } else { emailIntent.SetType("text/plain"); emailIntent.PutExtra(Intent.ExtraText, body); } if (attachments != null) { var uris = new List<IParcelable>(); DoOnActivity(activity => { foreach (var file in attachments) { File localfile; using (var localFileStream = activity.OpenFileOutput( file.FileName, FileCreationMode.WorldReadable)) { localfile = activity.GetFileStreamPath(file.FileName); file.Content.CopyTo(localFileStream); } localfile.SetReadable(true, false); uris.Add(Uri.FromFile(localfile)); localfile.DeleteOnExit(); // Schedule to delete file when VM quits. } }); if (uris.Any()) emailIntent.PutParcelableArrayListExtra(Intent.ExtraStream, uris); } // fix for GMail App 5.x (File not found / permission denied when using "StartActivity") StartActivityForResult(0, Intent.CreateChooser(emailIntent, dialogTitle ?? string.Empty)); }
public void btAmendClick(object sender, EventArgs e) { new AlertDialog.Builder(this) .SetPositiveButton("Yes", async (sender1, args) => { LoginController.Log(Constant.ButtonAmendClick); Intent Intent = new Intent (this, typeof(OrderActivity)); var orderList = this.orderListAdapter.GetOrderList(); List<OrderList1> Items = new List<OrderList1> (); foreach (var order in orderList) { var isSkip = 0; if (order.IsSkip) { isSkip = 1; } OrderList1 item = new OrderList1 (order.StockId, order.StockName, order.ShouldNumber, order.StockNumber, order.OrderNumber, order.Unit, isSkip); Items.Add (item); } Intent.PutParcelableArrayListExtra("key", Items.ToArray()); Intent.PutExtra("type", "amend"); StartActivity (Intent); this.OverridePendingTransition(Resource.Animation.slide_in_top, Resource.Animation.slide_out_bottom); }) .SetNegativeButton("No", (sender3, args) => { // User pressed no }) .SetTitle("This button will allow you to enter or change the order number, Continue ?") .Show(); }
public void btOrderClick(object sender, EventArgs e) { LoginController.Log(Constant.ButtonOrderClick); Intent Intent = new Intent (this, typeof(OrderActivity)); var CurrentDate = Utility.GetTodayDate(); List<OrderList> orderList = new List<OrderList>(); //get current data if (CurrentDate == this.StartDate) { LoginController.Log("CurrentDate == this.StartDate: " + this.StartDate.ToShortDateString()); orderList = this.orderListAdapter.GetOrderList(); } //get the newest data else { LoginController.Log("CurrentDate != this.StartDate: " + CurrentDate.ToShortDateString()); orderList = OrderController.GetOrderList(CurrentDate); } List<OrderList1> Items = new List<OrderList1>(); foreach (var order in orderList) { var isSkip = 0; if (order.IsSkip) { isSkip = 1; } OrderList1 item = new OrderList1(order.StockId, order.StockName, order.ShouldNumber, order.StockNumber, order.OrderNumber, order.Unit, isSkip); Items.Add(item); } Intent.PutExtra("type", "order"); Intent.PutParcelableArrayListExtra("key", Items.ToArray()); StartActivity (Intent); this.OverridePendingTransition(Resource.Animation.slide_in_top, Resource.Animation.slide_out_bottom); }
private void GetAudioList() { //TODO: move to service XmlDocument xDoc = new XmlDocument(); WebRequest requestAudioList = WebRequest.Create("https://api.vk.com/method/audio.get.xml?&access_token=" + Auth.Token); WebResponse responseAudioList = requestAudioList.GetResponse(); Stream stream = responseAudioList.GetResponseStream(); xDoc.Load(stream); XmlElement xRoot = xDoc.DocumentElement; AudioList = new List<IParcelable>(); foreach (XmlElement childNodes in xRoot.ChildNodes) { AudioFile audioFile = new AudioFile(); foreach (XmlElement childNode in childNodes) { if (childNode.Name == "artist") audioFile.Artist = childNode.InnerText; if (childNode.Name == "title") audioFile.Title = childNode.InnerText; if (childNode.Name == "url") audioFile.URL = childNode.InnerText; } AudioList.Add(audioFile); } Intent intent = new Intent(this, typeof(SongsListActivity)); intent.PutParcelableArrayListExtra(SongsListActivity.AUDIO_LIST_KEY, AudioList); StartActivity(intent); }
//Handle when user click LIST button public void btFinalClick(object sender, EventArgs e) { //Save the last value // try { // // var stockNumber = Double.Parse (edit_Stock.Text); // // if (Settings.CKStaff || this.EditType == "amend") { // this.orderListAdapter.SetOrderAtPosition (selectedIndex, stockNumber); // } // else // { // this.orderListAdapter.SetStockAtPosition (selectedIndex, stockNumber); // this.orderListAdapter.SetOrderAtPosition (selectedIndex, this.orderListAdapter.GetItemAtPosition (selectedIndex).ShouldNumber - stockNumber); // } // // // } catch (Exception ew) { // // Console.WriteLine (ew.StackTrace); // // Toast.MakeText (this, "Input not valid", ToastLength.Short).Show (); // return; // } LoginController.Log(Constant.ButtonListClick); //Go back to homepage Intent Intent = new Intent (this, typeof(HomeActivity)); var orderList = this.orderListAdapter.GetOrderList(); List<OrderList1> Items = new List<OrderList1> (); foreach (var order in orderList) { var isSkip = 0; if (order.IsSkip) { isSkip = 1; } OrderList1 item = new OrderList1 (order.StockId, order.StockName, order.ShouldNumber, order.StockNumber, order.OrderNumber, order.Unit, isSkip); Items.Add (item); } Intent.PutParcelableArrayListExtra("key", Items.ToArray()); Intent.SetFlags (ActivityFlags.ClearTask | ActivityFlags.NewTask); StartActivity (Intent); this.OverridePendingTransition(Resource.Animation.slide_in_top, Resource.Animation.slide_out_bottom); this.Finish(); }
//Handle when user click Back on tablet public override void OnBackPressed(){ Intent Intent = new Intent (this, typeof(HomeActivity)); var orderList = this.orderListAdapter.GetOrderList(); List<OrderList1> Items = new List<OrderList1> (); foreach (var order in orderList) { var isSkip = 0; if (order.IsSkip) { isSkip = 1; } OrderList1 item = new OrderList1 (order.StockId, order.StockName, order.ShouldNumber, order.StockNumber, order.OrderNumber, order.Unit, isSkip); Items.Add (item); } Intent.PutParcelableArrayListExtra("key", Items.ToArray()); Intent.SetFlags (ActivityFlags.ClearTask | ActivityFlags.NewTask); StartActivity (Intent); this.OverridePendingTransition(Resource.Animation.slide_in_top, Resource.Animation.slide_out_bottom); this.Finish(); }
void SendButtonClicked(object sender, EventArgs e) { if (saveHistory) { var history = new HistoryInformation (); foreach (var p in _temp_IMG_List) { history.IMG_List.Add (p); } foreach (var r in _temp_RCD_List) { history.RCD_List.Add (r); } history.latitude = _lat_TextView.Text; history.longitude = _long_TextView.Text; DataManager.SharedInstance.History.Add (history); } var email = new Intent (Android.Content.Intent.ActionSendMultiple); var uris = new List<IParcelable> (); _temp_IMG_List.ForEach (uri=>{ Java.IO.File file = new Java.IO.File (uri.Path); file.SetReadable(true,true); var u = Android.Net.Uri.FromFile(file); uris.Add(u); }); _temp_RCD_List.ForEach (uri =>{ var file = new Java.IO.File (uri.Path); file.SetReadable(true,true); var u = Android.Net.Uri.FromFile(file); uris.Add(u); }); email.PutParcelableArrayListExtra (Intent.ExtraStream,uris); var msg = string.Format (" http://maps.google.com/maps?z=12&t=m&q=loc:{0},{1}",_lat_TextView.Text,_long_TextView.Text); email.PutExtra (Android.Content.Intent.ExtraText,msg); email.SetType ("message/rfc822"); StartActivityForResult (email,2); }
public override void OnActivityCreated (Bundle savedInstanceState) { base.OnActivityCreated (savedInstanceState); Activity act = Activity; /* BEGIN_INCLUDE (GET_CURRENT_RESTRICTIONS) */ // Existing app restriction settings, if exist, can be retrieved from the Bundle. mRestrictionsBundle = act.Intent.GetBundleExtra (Intent.ExtraRestrictionsBundle); if (mRestrictionsBundle == null) { mRestrictionsBundle = ((UserManager) act.GetSystemService (Context.UserService)) .GetApplicationRestrictions (Activity.PackageName); } if (mRestrictionsBundle == null) { mRestrictionsBundle = new Bundle (); } mRestrictions = (List<IParcelable>) act.Intent.GetParcelableArrayListExtra (Intent.ExtraRestrictionsList); /* END_INCLUDE (GET_CURRENT_RESTRICTIONS) */ // Transfers the saved values into the preference hierarchy. if (mRestrictions != null) { foreach (RestrictionEntry entry in mRestrictions) { if (entry.Key.Equals (GetRestrictionsReceiver.KEY_BOOLEAN)) { mBooleanPref.Checked = entry.SelectedState; mBooleanEntry = entry; } else if (entry.Key.Equals (GetRestrictionsReceiver.KEY_CHOICE)) { mChoicePref.Value = entry.SelectedString; mChoiceEntry = entry; } else if (entry.Key.Equals (GetRestrictionsReceiver.KEY_MULTI_SELECT)) { List <String> list = new List <String> (); foreach (String value in entry.GetAllSelectedStrings ()) { list.Add (value); } mMultiPref.Values = list; mMultiEntry = entry; } } } else { mRestrictions = new List<IParcelable> (); // Initializes the boolean restriction entry and updates its corresponding shared // preference value. mBooleanEntry = new RestrictionEntry (GetRestrictionsReceiver.KEY_BOOLEAN, mRestrictionsBundle.GetBoolean (GetRestrictionsReceiver.KEY_BOOLEAN, false)); mBooleanEntry.Type = RestrictionEntryType.Boolean; mBooleanPref.Checked = mBooleanEntry.SelectedState; // Initializes the single choice restriction entry and updates its corresponding // shared preference value. mChoiceEntry = new RestrictionEntry (GetRestrictionsReceiver.KEY_CHOICE, mRestrictionsBundle.GetString (GetRestrictionsReceiver.KEY_CHOICE)); mChoiceEntry.Type = RestrictionEntryType.Choice; mChoicePref.Value = mChoiceEntry.SelectedString; // Initializes the multi-select restriction entry and updates its corresponding // shared preference value. mMultiEntry = new RestrictionEntry (GetRestrictionsReceiver.KEY_MULTI_SELECT, mRestrictionsBundle.GetStringArray (GetRestrictionsReceiver.KEY_MULTI_SELECT)); mMultiEntry.Type = RestrictionEntryType.MultiSelect; if (mMultiEntry.GetAllSelectedStrings() != null) { List <String> hset = new List <String> (); String[] values = mRestrictionsBundle.GetStringArray (GetRestrictionsReceiver.KEY_MULTI_SELECT); if (values != null) { foreach (String value in values) { hset.Add (value); } } mMultiPref.Values = hset; } mRestrictions.Add (mBooleanEntry); mRestrictions.Add (mChoiceEntry); mRestrictions.Add (mMultiEntry); } // Prepares result to be passed back to the Settings app when the custom restrictions // activity finishes. Intent intent = new Intent (Activity.Intent); intent.PutParcelableArrayListExtra (Intent.ExtraRestrictionsList, new List <IParcelable> (mRestrictions)); Activity.SetResult (Result.Ok, intent); }
public void OnPreferenceChange (object sender, Preference.PreferenceChangeEventArgs e) { if (e.Preference == mBooleanPref) { mBooleanEntry.SelectedState = (bool) e.NewValue; } else if (e.Preference == mChoicePref) { mChoiceEntry.SelectedString = (string) e.NewValue; } else if (e.Preference == mMultiPref) { String[] selectedStrings = new String [((IList <string>) e.NewValue).Count]; int i = 0; foreach (String value in (IList<string>) e.NewValue) { selectedStrings[i++] = value; } mMultiEntry.SetAllSelectedStrings (selectedStrings); } // Saves all the app restriction configuration changes from the custom activity. Intent intent = new Intent (Activity.Intent); intent.PutParcelableArrayListExtra (Intent.ExtraRestrictionsList, new List<IParcelable> (mRestrictions)); Activity.SetResult (Result.Ok, intent); }