如何从我自己的android应用程序启动电报应用程序?
问题描述:
我有一个android应用程序应该能够通过按下按钮在电报应用程序中打开聊天。
我想从我的应用程序直接打开现有的机器人聊天页面。我的机器人有一个有效的标记。这怎么能实现?如何从我自己的android应用程序启动电报应用程序?
在此先感谢。
机器人的名字:@InfotechAvl_bot
机器人令牌:179284 ***********
//-------------
case ContentFragment.lMenuTelegram:
Intent LaunchIntent=getPackageManager().getLaunchIntentForPackage("org.telegram.messenger");
startActivity(LaunchIntent);
break;
答
我解决了我的问题。 其实你要打开机器人ID与此:
Intent telegram = new Intent(Intent.ACTION_VIEW , Uri.parse("https://telegram.me/InfotechAvl_bot"));
startActivity(telegram);
+0
你救了我的一天兄弟! –
+0
如何获取朋友的用户名? – NehaK
答
如果你喜欢一点点的复杂系统,我建议你使用:
/**
* 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;
}
}
希望这对你有用。
希望这将帮助你http://*.com/questions/30055201/android-send-telegram-message-to-a-specific-number –
其实我不想发送消息,我只想打开机器人聊天画面。 – BoshRa