public override void OnCreate() { base.OnCreate(); // A great place to initialize Xamarin.Insights and Dependency Services! // конфигурируем приложение var container = new UnityContainer(); Configure(container); // start app _log?.InfoFormat("====== Start on '{0}'. OS: '{1}'. Ver. '{2} ({3})'.", AndroidUtil.GetDeviceName(), AndroidUtil.GetAndroidVersion(), AppSettings.Default.VersionName, AssemblyAttributeAccessors.GetAssemblyFileVersion(GetType())); try { // json settings //http://www.newtonsoft.com/json/help/html/PreserveReferencesHandlingObject.htm //http://stackoverflow.com/questions/13510204/json-net-self-referencing-loop-detected //https://gist.github.com/carlin-q-scott/4c8a9cce734fa5b10a97 JsonConvert.DefaultSettings = () => new JsonSerializerSettings { #if DEBUG Formatting = Formatting.Indented, #endif ContractResolver = ShouldSerializeContractResolver.Instance, TypeNameHandling = TypeNameHandling.Auto //PreserveReferencesHandling = PreserveReferencesHandling.Objects //ReferenceLoopHandling = ReferenceLoopHandling.Ignore }; Task.Run(() => { try { var api = new ServiceApi(); api.StartService(this, ControlService.ActionAppStart); _log?.Info("------ Init is completed."); } catch (Exception ex) { _log?.Error(ex); } }); } catch (Exception ex) { _log?.Error(ex); } }
private void OnFileBoundServiceResult(string action) { //http://stackoverflow.com/questions/2197741/how-can-i-send-emails-from-my-android-application try { if (!_isBound) { return; } var service = _binder.Service as FileBoundService; if (service == null) { return; } if (service.ServiceExceptions != null && service.ServiceExceptions.ContainsKey(action)) { var exception = service.ServiceExceptions[action]; if (exception != null) { ShowError(exception, Resource.String.InternalError); return; } } if (service.Result != Result.Ok) { return; } Intent activityIntent; var requestCode = 0; switch (action) { case FileBoundService.ActionFeedback: var emailIntent = new Intent(Intent.ActionSend); //emailIntent.SetData(Uri.Parse("mailto:" + GetString(Resource.String.FeedbackMail))); emailIntent.PutExtra(Intent.ExtraEmail, new[] { GetString(Resource.String.FeedbackMail) }); var applicationName = GetString(Resource.String.ApplicationName); emailIntent.PutExtra(Intent.ExtraSubject, string.Format("{0} ver. {1}", applicationName, _version)); var bodytext = string.Format("Model: {0}{1}OS: {2}{1}Application: {3}", AndroidUtil.GetDeviceName(), System.Environment.NewLine, AndroidUtil.GetAndroidVersion(), string.Format("{0} ver. {1}", applicationName, _versionFull)); var intentType = "text/plain; charset=UTF-8;"; var zipFile = new Java.IO.File(_compressFileName); if (zipFile.Exists()) { //emailIntent.SetType("application/zip"); intentType += " " + MimeTypeZip; var uri = FileProvider.GetUriForFile(this, Application.Context.PackageName + ".FileProvider", zipFile); //emailIntent.PutExtra(Intent.ExtraStream, Uri.Parse("file://" + _compressFileName)); emailIntent.PutExtra(Intent.ExtraStream, uri); } else { //throw new FileNotFoundException(string.Format("File '{0}' not found.", _compressFileName)); bodytext += string.Format("{0}No log-file (logToFile: {1})", System.Environment.NewLine, AppSettings.Default.LoggingUseFile); } emailIntent.SetType(intentType); emailIntent.PutExtra(Intent.ExtraText, bodytext); activityIntent = Intent.CreateChooser(emailIntent, GetString(Resource.String.EmailChooserTitle)); break; case FileBoundService.ActionZipLogFiles: activityIntent = new Intent(Intent.ActionCreateDocument); activityIntent.AddCategory(Intent.CategoryOpenable); activityIntent.SetType(MimeTypeZip); var title = Path.GetFileName(_compressFileName)?.ToLower(); if (!string.IsNullOrEmpty(title)) { activityIntent.PutExtra(Intent.ExtraTitle, title); } requestCode = RequestCodeExportLog; break; case FileBoundService.ActionExportLog: return; default: throw new NotImplementedException(action); } if (activityIntent != null) { StartActivityForResult(activityIntent, requestCode); } } catch (ActivityNotFoundException ex) { ShowError(ex, Resource.String.NoEmailClientsInstalled); } catch (Exception ex) { ShowError(ex, Resource.String.InternalError); } finally { ShowProgressbar(false); } }