Android - 将电报消息发送到特定号码 [英] Android - Send Telegram message to a specific number

查看:188
本文介绍了Android - 将电报消息发送到特定号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的Android应用中向特定号码发送电报消息。现在我的代码启动Telegram应用程序,然后用户必须选择destinatary。我想要做的是将消息发送到指定的号码,而无需用户选择联系人。我的代码如下:

I'm trying to send a Telegram message to a specific number from within my Android app. Right now my code launches Telegram app, and then the user has to select the destinatary. What I want to do is to send the message to the specified number, without having the user select the contact. My code is as follows:

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


推荐答案

Telegram Android App无法直接向电报用户发送消息,因此如果您使用共享意图,您将获得电报/任何其他应用程序想要对共享消息执行的操作。在这种情况下,打开联系人列表以向他发送此消息。

The Telegram Android App does not have a way to send messages directly to telegram users, so if you use the share intent, you'll get what telegram / any other app wants to do with the message shared. In this case, open the contact list to send this message to him.

如果要直接向Telegram用户发送消息,则应使用Telegram API
https://core.telegram.org/api#getting-started

If you want to send messages directly to Telegram users you should use the Telegram API https://core.telegram.org/api#getting-started

在应用程序中配置API密钥后,您可以发送消息,阅读消息,甚至使用这些方法获取电报联系人

once you have configured your API key in your app, you could send messages, read them or even get the telegram contacts with these methods

https://core.telegram.org/methods

这篇关于Android - 将电报消息发送到特定号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆