How to launch Telegram app from my own Android app?

I have an Android application that should open a chat in a telegram application by clicking a button.
I want to open an existing DIRECTLY robot chat page from my application. I have a valid token for my robot. How can this be achieved?

Thanks in advance.

robot name: @InfotechAvl_bot

robot token: 179284 ***********

   //-------------
    case ContentFragment.lMenuTelegram:
     Intent LaunchIntent=getPackageManager().getLaunchIntentForPackage("org.telegram.messenger");
     startActivity(LaunchIntent);
            break;
+4
source share
2 answers

I solved my problem. in fact you need to open the robot id:

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

If you prefer a slightly complex system, I recommend you use:

/** 
     * 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 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; 
            } 
        } 

, .

+3

All Articles