public override bool Authenticate(WakeLock wakeLock) { return true; }
public override void Connect(WakeLock wakeLock) { // do nothing }
public override void Connect(WakeLock wakeLock) { Disconnect(); var sessionId = GetRandomId(); var transportConfig = new TcpClientTransportConfig(_settings.NearestDcIp, _settings.NearestDcPort); using (var client = new TelegramClient(transportConfig, new ConnectionConfig(_settings.AuthKey, _settings.Salt), AppInfo)) { var result = TelegramUtils.RunSynchronously(client.Connect()); if (result != MTProtoConnectResult.Success) { throw new Exception("Failed to connect: " + result); } DebugPrint("Registering long poller..."); var registerDeviceResult = TelegramUtils.RunSynchronously(client.Methods.AccountRegisterDeviceAsync( new AccountRegisterDeviceArgs { TokenType = 7, Token = sessionId.ToString(CultureInfo.InvariantCulture), })); if (!registerDeviceResult) { throw new Exception("Failed to register long poller..."); } DebugPrint(">>>>>>>>>>>>>> Fetching state!"); FetchState(client); DebugPrint (">>>>>>>>>>>>>> Fetching dialogs!"); GetDialogs(client); GetConfig(client); } DebugPrint("Starting long poller..."); if (_longPollClient != null) { _longPollClient.OnUpdateTooLong -= OnLongPollClientUpdateTooLong; _longPollClient.OnClosedInternally -= OnLongPollClientClosed; } _longPollerAborted = false; _longPollClient = new TelegramClient(transportConfig, new ConnectionConfig(_settings.AuthKey, _settings.Salt) { SessionId = sessionId }, AppInfo); var result2 = TelegramUtils.RunSynchronously(_longPollClient.Connect()); if (result2 != MTProtoConnectResult.Success) { throw new Exception("Failed to connect long poll client: " + result2); } _longPollClient.OnUpdateTooLong += OnLongPollClientUpdateTooLong; _longPollClient.OnClosedInternally += OnLongPollClientClosed; ScheduleLongPollPing(); DebugPrint("Long poller started!"); }
private void unlockScreen() { WakeLock screenLock = ((PowerManager)GetSystemService(Context.PowerService)).NewWakeLock(WakeLockFlags.ScreenBright | WakeLockFlags.AcquireCausesWakeup, "tag"); screenLock.Acquire(); }
public override bool Authenticate(WakeLock wakeLock) { return(true); }
private void FinishLoadApp() { try { MobileGlobals.ApplicationDir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); AndroidGlobals.MainActivity = this; MobileGlobals.CacheDirectory = AndroidGlobals.MainActivity.CacheDir.AbsolutePath; MobileGlobals.RootDir = Android.OS.Environment.RootDirectory.Path; MobileGlobals.SharedStorageDir = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath; MobileGlobals.ExternalStorageDirRoot = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath; MobileGlobals.ExternalStorageDirRemovableMusic = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryMusic).AbsolutePath; MobileGlobals.ExternalStorageDirForAppUninstalled = AndroidGlobals.MainActivity.GetExternalFilesDir(null).AbsolutePath; MobileGlobals.AppDataPermanentStorageDir = MobileGlobals.ExternalStorageDirRoot + "/com.AndroidTest.Data"; if (!Directory.Exists(MobileGlobals.AppDataPermanentStorageDir)) { try { Directory.CreateDirectory(MobileGlobals.AppDataPermanentStorageDir); } catch (Exception ex) { MobileGlobals.AddNewException(ex); MobileGlobals.WriteExceptionLog(); } } } catch (Exception ex) { MobileGlobals.AddNewException(ex); MobileGlobals.WriteExceptionLog(); } // Get a Wakelock try { PowerManager powerManager = (PowerManager)this.GetSystemService(Context.PowerService); wakeLock = powerManager.NewWakeLock(WakeLockFlags.Full, "My Lock"); } catch (Exception ex) { MobileGlobals.AddNewException(ex); ex = new Exception("Error Getting PowerManager Wake Lock."); MobileGlobals.AddNewException(ex); MobileGlobals.WriteExceptionLog(); } try { LoadApplication(new App()); } catch (Exception ex) { MobileGlobals.AddNewException(ex); ex = new Exception("Error on LoadApplication() method."); MobileGlobals.AddNewException(ex); MobileGlobals.WriteExceptionLog(); } }