skip to Main Content

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,
      ),
    ),
  ),

3

Answers


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

    Login or Signup to reply.
  2. You can adapt the example yourself

    IconButton(
                              onPressed: () async {
                                await launch(
                                  "https://t.me/Your link",
                                  forceSafariVC: false,
                                  forceWebView: false,
                                  headers: <String, String>{
                                    'my_header_key': 'my_header_value'
                                  },
                                );
                              },
                              icon: Icon(
                                FontAwesomeIcons.telegram,
                                color: Colors.blue,
                              ),
                              iconSize: 45,
                            ),
    
    Login or Signup to reply.
  3. 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=";
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search