【问题标题】:How to launch Telegram app from my own android application?如何从我自己的 android 应用程序启动 Telegram 应用程序?
【发布时间】:2016-06-13 19:31:52
【问题描述】:

我有一个 Android 应用程序,它应该能够通过按一个按钮在电报应用程序中打开聊天。
我想直接从我的应用打开现有的机器人聊天页面。我的机器人有一个有效的令牌。如何实现?

提前致谢。

机器人名称:@InfotechAvl_bot

机器人令牌:179284*************

   //-------------
    case ContentFragment.lMenuTelegram:
     Intent LaunchIntent=getPackageManager().getLaunchIntentForPackage("org.telegram.messenger");
     startActivity(LaunchIntent);
            break;

【问题讨论】:

标签: java android launch telegram


【解决方案1】:

要解决这个问题,你必须用这个打开机器人 ID:

Intent telegram = new Intent(Intent.ACTION_VIEW , Uri.parse("https://telegram.me/InfotechAvl_bot"));
startActivity(telegram);

【讨论】:

  • 你拯救了我的一天兄弟!
【解决方案2】:

对于 Instagram 和 Telegram 和 WhatsApp,您可以使用此方法

 void getTelegram(){

        try {
            Intent telegramIntent = new Intent(Intent.ACTION_VIEW);
            telegramIntent.setData(Uri.parse("https://telegram.me/diako099"));
            startActivity(telegramIntent);
        } catch (Exception e) {
            // show error message
        }
    }

    void getInstagram(){
        try {
            Intent instagramIntent = new Intent(Intent.ACTION_VIEW);
            instagramIntent.setData(Uri.parse("https://www.instagram.com/diako_hasani99/"));
            startActivity(instagramIntent);
        } catch (Exception e) {
            // show error message
        }

    }

    void getWhatsApp(){
        try{

            String trimToNumner = "+989180074693"; //10 digit number
            Intent intent = new Intent ( Intent.ACTION_VIEW );
            intent.setData ( Uri.parse ( "https://wa.me/" + trimToNumner + "/?text=" + "" ) );
            startActivity ( intent );

        }catch (Exception e){

        }
    }

【讨论】:

    【解决方案3】:

    如果你喜欢稍微复杂一点的系统,我推荐你使用:

    /** 
         * Intent to send a telegram message 
         * @param msg 
         */ 
        void intentMessageTelegram(String msg)
        { 
            final String appName = "org.telegram.messenger";
            final boolean isAppInstalled = isAppAvailable(mUIActivity.getApplicationContext(), appName);
            if (isAppInstalled) 
            { 
                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"));
            }  
            else  
            { 
                Toast.makeText(mUIActivity, "Telegram not Installed", Toast.LENGTH_SHORT).show();
            } 
        } 
    

    并检查是否安装了:

    /** 
             * Indicates whether the specified app ins installed and can used as an intent. This 
             * method checks the package manager for installed packages that can 
             * respond to an intent with the specified app. If no suitable package is 
             * found, this method returns false. 
             * 
             * @param context The application's environment. 
             * @param appName The name of the package you want to check 
             * 
             * @return True if app is installed 
             */ 
            public static boolean isAppAvailable(Context context, String appName) 
            { 
                PackageManager pm = context.getPackageManager();
                try  
                { 
                    pm.getPackageInfo(appName, PackageManager.GET_ACTIVITIES);
                    return true; 
                }  
                catch (NameNotFoundException e) 
                { 
                    return false; 
                } 
            } 
    

    希望这对你有用。

    【讨论】:

    • 复制粘贴但没问题
    • @Ali 谢谢我不知道这个。
    • 哦,真的吗? stackoverflow.com/questions/21627167/… 而你不知道这一点,两年前你只是不小心写下了这个答案的每一个字,我不是说你做错了什么,我说没关系,它可能会帮助找到这个问题的人那个,但不要玩聪明的“我不知道这个”是的,是的~
    • @Ali 谢谢你可以对答案投反对票,以防你发现它被复制了。感谢您的好意。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-07
    • 2015-05-26
    • 1970-01-01
    • 1970-01-01
    • 2010-09-07
    • 1970-01-01
    • 2012-01-21
    相关资源
    最近更新 更多