<metaproperty="description"content="The Android SDK helps you easily integrate Telegram Passport requests into your Android-based apps. Check out our GitHub…">
<metaproperty="og:title"content="Android SDK">
<metaproperty="og:image"content="">
<metaproperty="og:description"content="The Android SDK helps you easily integrate Telegram Passport requests into your Android-based apps. Check out our GitHub…">
<p>The Android SDK helps you easily integrate Telegram Passport requests into your Android-based apps. Check out our <ahref="https://github.com/TelegramMessenger/TGPassportAndroidSDK">GitHub repository</a> to see samples using this SDK.</p>
<h4><aclass="anchor"href="#installing-from-maven"id="installing-from-maven"name="installing-from-maven"><iclass="anchor-icon"></i></a>Installing from Maven</h4>
<p>Telegram Passport SDK is available from the Maven repository.
Add this line to the dependencies section in your build.gradle:</p>
<h4><aclass="anchor"href="#adding-as-a-module"id="adding-as-a-module"name="adding-as-a-module"><iclass="anchor-icon"></i></a>Adding as a module</h4>
<p>Download the library, unzip it and copy the library project to the root of your project directory (the one with settings.gradle and gradle.properties). Then, make the following changes to your Gradle scripts.</p>
<p>In settings.gradle, add <code>':telegrampassport'</code> to includes:</p>
<h4><aclass="anchor"href="#adding-the-button"id="adding-the-button"name="adding-the-button"><iclass="anchor-icon"></i></a>Adding the button</h4>
<p>The SDK provides the "Log in with Telegram" button which we recommend using for a consistent user experience across different apps. You can either add it from your Java code:</p>
<pre><code>TelegramLoginButton telegramButton;
// ...
telegramButton=new TelegramLoginButton(this);
// Optionally you can change the roundness of the button corners
<p>The button doesn't do anything by itself; you need to set an OnClickListener on it to start the authorization flow (replace the comments with actual parameters):</p>
<pre><code>private static final int TG_PASSPORT_RESULT=352; // this can be any integer less than 0xFFFF
<p>If you need more control over the process, the <code>TelegramPassport</code> class contains several more methods:</p>
<ul>
<li><code>getAuthIntent(AuthParams)</code> returns an <code>Intent</code> for you to use in <code>startActivityForResult</code> if you need to do that in some special way. Be sure to check that an app is present that can handle this intent before starting it by using <code>PackageManager</code> or <code>intent.resolveActivity</code>.</li>
<li><code>showAppInstallAlert(Activity)</code> shows an alert that the user needs to install Telegram in order to continue. This is intended to be used together with the previous method for the cases when the app isn't installed.</li>
</ul>
<h4><aclass="anchor"href="#handling-the-result"id="handling-the-result"name="handling-the-result"><iclass="anchor-icon"></i></a>Handling the result</h4>
<p>The result is delivered via the <code>onActivityResult</code> method in your activity with the request code you passed to <code>TelegramPassport.request</code>. Currently, the only meaningful parameter is <code>resultCode</code>, which is <code>RESULT_OK</code> if the authorization was successful and <code>RESULT_CANCELED</code> otherwise.</p></div>
</div>
</div>
</div>
<divclass="footer_wrap">
<divclass="footer_columns_wrap footer_desktop">
<divclass="footer_column footer_column_telegram">
<h5>Telegram</h5>
<divclass="footer_telegram_description"></div>
Telegram is a cloud-based mobile and desktop messaging app with a focus on security and speed.