public static MyIR GetInstance(Context context) { lock (objLock) { if (s_Instance == null) { s_Instance = new MyIR(context); } return(s_Instance); } }
private void init() { #region 初始化 Common.StaticInfo var staticInfoInitArgs = new Common.StaticInfoInitArgs(); staticInfoInitArgs.AppName = "XamarinTest"; #region 安卓项目路径赋值 // 安卓系统外部存储绝对路径 staticInfoInitArgs.AndroidExternalPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath; // App外部缓存绝对路径 -- /{安卓系统外部存储路径}/Android/data/{appPackageName}/cache foreach (var item in this.GetExternalCacheDirs()) { staticInfoInitArgs.AndroidExternalCachePath = item.AbsolutePath; break; } // App外部文件绝对路径 -- /{安卓系统外部存储路径}/Android/data/{appPackageName}/files foreach (var item in this.GetExternalFilesDirs(string.Empty)) { staticInfoInitArgs.AndroidExternalFilesPath = item.AbsolutePath; break; } #endregion #region 务器配置 string pathServiceSettings = Common.ServiceSettingsUtils.GetConfigFilePath(argsDirPath: staticInfoInitArgs.AndroidExternalFilesPath); if (System.IO.File.Exists(pathServiceSettings) == false) { Common.ServiceSettingsUtils.InitConfig(pathServiceSettings); } Common.ServiceSettingsUtils.ReadConfig(pathServiceSettings, staticInfoInitArgs); #endregion #region 本机配置 string pathNativeSettings = Common.NativeSettingsUtils.GetConfigFilePath(argsDirPath: staticInfoInitArgs.AndroidExternalFilesPath); if (System.IO.File.Exists(pathNativeSettings) == false) { Common.NativeSettingsUtils.InitConfig(pathNativeSettings); } Common.NativeSettingsUtils.ReadConfig(pathNativeSettings, staticInfoInitArgs); #endregion #region SQLite staticInfoInitArgs.InnerSQLiteConnStr = System.IO.Path.Combine ( System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), Util.Principle.DatabaseName_SQLite ); staticInfoInitArgs.ExternalSQLiteConnStr = System.IO.Path.Combine ( staticInfoInitArgs.AndroidExternalFilesPath, Util.Principle.DatabaseName_SQLite ); #endregion Common.StaticInfo.Init(staticInfoInitArgs); #endregion // 实现IOutput接口 - 用 Logcat 来实现 App.Output = new MyOutput(); // 屏幕方向 App.Screen = Util.XamariN.AndroiD.MyScreen.GetInstance(this); // 初始化条码扫描器 ZXing.Net.Mobile.Forms.Android.Platform.Init(); // 初始化百度定位 App.LBS = new BaiduLBS(ApplicationContext); // 初始化Audio App.AudioPlayer = Util.XamariN.AndroiD.MyAudioPlayer.GetInstance(); // 初始化TTS App.TTS = Util.XamariN.AndroiD.MyTTS.GetInstance(); // 初始化IR App.IR = MyIR.GetInstance(ApplicationContext); // 弃用 // 初始化动态权限 // 1)实现封装好的接口 // App.AndroidPermissionUtils = Util.XamariN.AndroiD.MyAndroidPermission.GetInstance(this); // 2)下面这个实现用于本项目快速测试, 不需要更新 Util.XamariN.AndroiD 的 DLL 到 nuget // MyAndroidPermission_InTestSolution myPermission = MyAndroidPermission_InTestSolution.GetInstance(this); // App.AndroidPermissionUtils_InTestSolution = myPermission; // 初始化Bluetooth App.Bluetooth = Util.XamariN.AndroiD.MyBluetooth.GetInstance(this); App.MyShareUtils = new Util.XamariN.AndroiD.MyShareUtils(); // 文件管理器 ShareUtils 赋值具体 Util.XamariN.FileExplorer.MyFileExplorer.ShareUtils = new Util.XamariN.AndroiD.MyShareUtils(); App.MyWechatOpenSDK = new MyWeChatOpenSDK(app_id: "wxd66c092941a6aabf"); #region 安卓特有 // 访问 Assets 资源 App.AndroidAssetsUtils = Util.XamariN.AndroiD.MyAndroidAssetsUtils.GetInstance(this); // 初始化 Intent 工具类 App.AndroidIntentUtils = Util.XamariN.AndroiD.MyAndroidIntentUtils.GetInstance(this); string auth = $"{this.Application.PackageName}.fileprovider"; App.AndroidIntentUtils.SetFileProvider_Authority(auth); // 初始化 Android 权限工具类 App.AndroidPermissionUtils = Util.XamariN.AndroiD.MyAndroidPermission.GetInstance(this); // 初始化截屏 App.AndroidScreenshot = Util.XamariN.AndroiD.MyAndroidScreenshot.GetInstance(this); // 初始化录屏 App.AndroidScreenRecord = Util.XamariN.AndroiD.MyAndroidScreenRecord.GetInstance(this); #endregion #region 初始化第三方 DLL 库 // 初始化 Acr.UserDialogs Acr.UserDialogs.UserDialogs.Init(this); //// [弃用] DevExpress.Mobile.Forms //// 初始化 DevExpress.Mobile.Forms //DevExpress.Mobile.Forms.Init(); //// 由于DevExpress.Mobile.DataGrid.Theme.ThemeManager.ThemeName 默认主题为 Themes.Dark, //// 这里初始化主题颜色为 Theme.Light //DevExpress.Mobile.DataGrid.Theme.ThemeManager.ThemeName = DevExpress.Mobile.DataGrid.Theme.Themes.Light; //DevExpress.Mobile.DataGrid.Theme.ThemeManager.RefreshTheme(); // 初始化 FFImageLoading // 2.4.4.589(稳定版)执行 init 方式会报错 // System.TypeLoadException: Could not load list of method overrides due to Method not found: void // Nuget 引用 2.4.5.880-pre // 1) Xamarin.FFImageLoading // 2) Xamarin.FFImageLoading.Forms // 然后以下的执行初始化语句 var svgAssembly = typeof(FFImageLoading.Svg.Forms.SvgCachedImage).GetTypeInfo().Assembly; // <-- 追加 FFImageLoading.Forms.Platform.CachedImageRenderer.Init(enableFastRenderer: true); // Plugin.MediaManager.Forms ( 视频播放类库 ) //MediaManager.CrossMediaManager.Current.Init(); // 初始化 XLab var resolverContainer = new global::XLabs.Ioc.SimpleContainer(); resolverContainer.Register <XLabs.Platform.Services.Media.IMediaPicker, XLabs.Platform.Services.Media.MediaPicker>(); XLabs.Ioc.Resolver.SetResolver(resolverContainer.GetResolver()); // Aspose.Cells App.ExcelUtils_Aspose = new Util.Excel.ExcelUtils_Aspose_XamarinAndroid(); #endregion }