如何通过intent从我自己的活动中启动connectbot

Jul*_*dra 4 ssh android android-intent android-activity

我的申请有问题.我想通过intent从我的应用程序启动connectbot,如果我的活动开始我也想连接startbot.如何从我的活动意图connectbot应用程序,请回答我的问题.谢谢...

Dir*_*kel 6

ConnectBot的AndroidManifest具有以下intent-filter:

<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data android:scheme="ssh" />
  <data android:scheme="telnet" />
  <data android:scheme="local" />
  <!-- format:  ssh://user@host:port/#nickname  -->
  <!-- format:  telnet://host:port/#nickname  -->
  <!-- format:  local://  -->
</intent-filter>
Run Code Online (Sandbox Code Playgroud)

这意味着您可以使用以下操作抛出Intent以启动ConnectBot并打开ConsoleActivity.ConsoleActivity对Uri没有任何作用,因此您可以使用以"ssh://"开头的任何内容:

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("ssh://user@host:port/#nickname")));
Run Code Online (Sandbox Code Playgroud)

ConnectBot还响应ACTION_PICK,它打开已配置连接的列表.ACTION_PICK实际解析给定的uri并打开昵称,但前提是用户,主机和端口也是正确的.