Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open telegram channel in android

In my app want to use Intent to open specific telegram channel or telegram group. i search in SF but i can't find anything.i try to implement but i only can open all messenger apps that user can choose but not telegram or specific telegram group or channel. if find this on sf but it's not answer to my question.

    Intent myIntent = new Intent(Intent.ACTION_SEND);
    myIntent.setType("text/plain");
    myIntent.setPackage(appName);
    myIntent.putExtra(Intent.EXTRA_TEXT, msg);//
    mUIActivity.startActivity(Intent.createChooser(myIntent, "Share with"));
like image 453
MBehtemam Avatar asked Jan 09 '16 10:01

MBehtemam


2 Answers

Intent for opening a Telegram channel or user :

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("tg://resolve?domain=partsilicon"));
startActivity(intent);
like image 151
Sadegh Ghanbari Avatar answered Oct 04 '22 01:10

Sadegh Ghanbari


First check if any telegram client (telegram messenger or telegram x) is installed. If not open it in browser.

fun telegramIntent(context: Context): Intent {
    var intent: Intent? = null
    try {
        try {
           context.packageManager.getPackageInfo("org.telegram.messenger", 0)//Check for Telegram Messenger App
        } catch (e : Exception){
           context.packageManager.getPackageInfo("org.thunderdog.challegram", 0)//Check for Telegram X App
        }
       intent = Intent(Intent.ACTION_VIEW, Uri.parse("tg://resolve?domain=${TELEGRAM_PAGE_ID}"))
    }catch (e : Exception){ //App not found open in browser
       intent = Intent(Intent.ACTION_VIEW, Uri.parse("http://www.telegram.me/$TELEGRAM_PAGE_ID"))
    }
   return intent!!
}
like image 45
Saurabh Padwekar Avatar answered Oct 04 '22 00:10

Saurabh Padwekar