Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: Can't open telegram channel from URL_LUNCHER

Tags:

flutter

I want to direct open to telegram channel using url_luncher from my flutter app. currently, I can open the telegram app but it does not direct to the channel.

Is there any configure would need to achieve this?

GestureDetector(
    onTap: () async {
      var url = Uri.parse("tg://t.me/channel_name");
      if (await canLaunchUrl(url)) {
        await launchUrl(url);
      }
    },
    child: ListTile(
      visualDensity: const VisualDensity(vertical: -4),
      minLeadingWidth: leadingTxtSpace,
      leading: const CircleAvatar(
        radius: 15,
        backgroundColor: Colors.blueAccent,
        child: Icon(Icons.telegram_outlined, color: Colors.white),
      ),
      title: Text(
        "Telegram",
        style: Theme.of(context).textTheme.bodySmall,
      ),
    ),
  ),
like image 564
BOOM Avatar asked Oct 28 '25 01:10

BOOM


2 Answers

In older version its working fine

url_launcher: ^6.0.12
minSdkVersion 21
targetSdkVersion 30
sdk: ">=2.12.0 <3.0.0"

After upgrading SDK & Packages facing same issue. app opened but not navigate to specific chatting screen so i found solution for whatsapp & telegram app.

url_launcher: ^6.1.6
minSdkVersion 21
targetSdkVersion 33
sdk: ">=2.12.0 <3.3.6"

add few things inside <queries> in AndroidManifest.xml

<queries>
                       
     <!-- Place inside the <queries> element. -->
                    <intent>
                     <action android:name="android.intent.action.VIEW" />
                        <category android:name="android.intent.category.BROWSABLE" />
                        <data android:scheme="https" />
                    </intent>
                    
                    <package android:name="com.whatsapp" />
                    <package android:name="org.telegram.messenger" />
</queries>

in launchURL you need to pass mode parameter explicitly with value: LaunchMode.externalApplication like this:

try {
    "Launch URL: $url".printLog();
    if (!await launchUrl(Uri.parse(url), mode: LaunchMode.externalApplication)) {
      showToast(sSomethingWrong);
    }
  } catch (ex) {
    "Could not launch url $ex".printLog();
 }

Used URL in my app

String sURLTelegram = "https://t.me/user_name";
String sURLWhatsapp = "whatsapp://send?phone=";
like image 78
Vishal Zaveri Avatar answered Oct 30 '25 15:10

Vishal Zaveri


In my case I used this link, try that too . https://t.me/user_name It work in my case..

like image 26
mohamad kanina Avatar answered Oct 30 '25 15:10

mohamad kanina