YYPOST群发软件 发表于 2025-1-20 09:05:30

无需担心应用未安装,自动切换到快手和抖音网页

<p style="margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: &quot;Microsoft YaHei&quot;, Helvetica, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, &quot;Helvetica Neue&quot;, &quot;Droid Sans&quot;, &quot;wenquanyi micro hei&quot;, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; box-sizing: border-box;">1.这是一段快手的意图跳转例子</p><pre style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: &quot;YaHei Consolas Hybrid&quot;, Consolas, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Helvetica, monospace, monospace; overflow-wrap: normal; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="lang-javascript这个是快手意图跳转例子 hljs" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 导入包</span>
importClass(Packages.android.content.Intent);
importClass(Packages.android.net.Uri);
importClass(Packages.android.content.ActivityNotFoundException);
importClass(Packages.android.widget.Toast);
importClass(Packages.android.os.Handler);
importClass(Packages.android.os.Looper);

<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 设置快手用户页面的URL</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> userId = <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"2037335125"</span>;
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> url = <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"kwai://profile/"</span> + userId;

<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">try</span> {
    <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 使用安卓intent跳转</span>
    <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> intent = <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">new</span> Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
} <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">catch</span> (e) {
    <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">if</span> (e.toString().indexOf(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"android.content.ActivityNotFoundException"</span>) !== -<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>) {
      <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 提示用户安装快手应用或提供网页链接</span>
      showToast(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"未找到快手应用,请确保已安装。"</span>);
      <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 或者提供一个网页链接作为替代</span>
      <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> webUrl = <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"https://www.kwai.com/profile/"</span> + userId;
      <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> webIntent = <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">new</span> Intent(Intent.ACTION_VIEW, Uri.parse(webUrl));
      webIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      context.startActivity(webIntent);
    } <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">else</span> {
      showToast(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"发生错误: "</span> + e.message);
    }
}

<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 自定义showToast方法</span>
<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(97, 174, 238);">showToast</span>(<span class="hljs-params" style="box-sizing: border-box;">message</span>) </span>{
    <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">new</span> Handler(Looper.getMainLooper()).post(<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span>(<span class="hljs-params" style="box-sizing: border-box;"></span>) </span>{
      Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
    });
}
</code></pre><p style="margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: &quot;Microsoft YaHei&quot;, Helvetica, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, &quot;Helvetica Neue&quot;, &quot;Droid Sans&quot;, &quot;wenquanyi micro hei&quot;, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; box-sizing: border-box;">这段代码是用于在安卓设备上通过Java Script尝试打开快手应用中的某个用户个人页面。如果设备上没有安装快手应用,则会显示一个短时的Toast提示信息,告知用户未找到快手应用,并尝试通过浏览器打开快手的网页版用户个人页面。</p><p style="margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: &quot;Microsoft YaHei&quot;, Helvetica, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, &quot;Helvetica Neue&quot;, &quot;Droid Sans&quot;, &quot;wenquanyi micro hei&quot;, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; box-sizing: border-box;">代码的主要步骤如下:</p><ol style="margin-bottom: 1.5em; padding-left: 2em; color: rgb(51, 51, 51); font-family: &quot;Microsoft YaHei&quot;, Helvetica, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, &quot;Helvetica Neue&quot;, &quot;Droid Sans&quot;, &quot;wenquanyi micro hei&quot;, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; box-sizing: border-box;"><li style="box-sizing: border-box;">导入必要的安卓类。</li><li style="box-sizing: border-box;">设置要访问的快手用户ID,并构建快手应用内链接URL。</li><li style="box-sizing: border-box;">创建一个Intent对象,设置为查看动作,并指定URI为快手用户页面的URL。</li><li style="box-sizing: border-box;">设置Intent标志为FLAG_ACTIVITY_NEW_TASK,以确保即使从后台服务启动,也能创建新的任务栈。</li><li style="box-sizing: border-box;">使用context.startActivity()方法尝试启动Intent。</li><li style="box-sizing: border-box;">如果遇到android.content.ActivityNotFoundException异常,表示设备上没有安装快手应用,此时会显示一个Toast提示信息,并构建快手网页版用户个人页面的URL,再次创建一个Intent对象尝试打开网页。</li><li style="box-sizing: border-box;">如果遇到其他异常,会显示包含错误信息的Toast提示。</li><li style="box-sizing: border-box;">自定义showToast方法,利用Handler和Looper确保Toast在主线程中显示,因为安卓UI操作必须在主线程中进行。</li></ol><p style="margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: &quot;Microsoft YaHei&quot;, Helvetica, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, &quot;Helvetica Neue&quot;, &quot;Droid Sans&quot;, &quot;wenquanyi micro hei&quot;, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; box-sizing: border-box;">2.这是抖音的意图跳转例子。</p><pre style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11.9px; line-height: 1.6; font-family: &quot;YaHei Consolas Hybrid&quot;, Consolas, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Helvetica, monospace, monospace; overflow-wrap: normal; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs javascript" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 导入包</span>
importClass(Packages.android.content.Intent);
importClass(Packages.android.net.Uri);
importClass(Packages.android.content.ActivityNotFoundException);
importClass(Packages.android.widget.Toast);
importClass(Packages.android.os.Handler);
importClass(Packages.android.os.Looper);

<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 设置抖音用户页面的URL</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> userId = <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"xyz123"</span>; <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 请替换为实际用户ID</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> url = <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"snssdk1128://aweme/detail/"</span> + userId;

<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">try</span> {
    <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 使用安卓intent跳转</span>
    <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> intent = <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">new</span> Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
} <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">catch</span> (e) {
    <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">if</span> (e.toString().indexOf(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"android.content.ActivityNotFoundException"</span>) !== -<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>) {
      <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 提示用户安装抖音应用或提供网页链接</span>
      showToast(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"未找到抖音应用,请确保已安装。"</span>);
      <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 或者提供一个网页链接作为替代</span>
      <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> webUrl = <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"https://www.douyin.com/user/"</span> + userId; <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 替换为实际的用户网页链接</span>
      <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> webIntent = <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">new</span> Intent(Intent.ACTION_VIEW, Uri.parse(webUrl));
      webIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      context.startActivity(webIntent);
    } <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">else</span> {
      showToast(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"发生错误: "</span> + e.message);
    }
}

<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 自定义showToast方法</span>
<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(97, 174, 238);">showToast</span>(<span class="hljs-params" style="box-sizing: border-box;">message</span>) </span>{
    <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">new</span> Handler(Looper.getMainLooper()).post(<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">function</span>(<span class="hljs-params" style="box-sizing: border-box;"></span>) </span>{
      Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
    });
}
</code></pre><h3 id="h3-u4EE3u7801u7ED3u6784u4E0Eu529Fu80FD" style="margin-top: 1em; margin-bottom: 1.5em; color: rgb(51, 51, 51); font-family: &quot;Microsoft YaHei&quot;, Helvetica, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, &quot;Helvetica Neue&quot;, &quot;Droid Sans&quot;, &quot;wenquanyi micro hei&quot;, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; box-sizing: border-box; position: relative; line-height: 1.75; font-size: 1.25em !important;"><a name="代码结构与功能" class="reference-link" style="color: rgb(65, 131, 196); transition: color 0.08s ease-out 0s; box-sizing: border-box; background: 0px 0px;"></a>代码结构与功能</h3><ol style="margin-bottom: 1.5em; padding-left: 2em; color: rgb(51, 51, 51); font-family: &quot;Microsoft YaHei&quot;, Helvetica, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, &quot;Helvetica Neue&quot;, &quot;Droid Sans&quot;, &quot;wenquanyi micro hei&quot;, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; box-sizing: border-box;"><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">导入必要的安卓类</span>:</p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">Intent</code>:用于启动活动。</li><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">Uri</code>:处理URI(统一资源标识符)。</li><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">ActivityNotFoundException</code>:用于捕获活动未找到的异常。</li><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">Toast</code>:用于在屏幕上显示短暂的消息。</li><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">Handler</code>和<code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">Looper</code>:用于处理UI线程中的任务。</li></ul></li><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">设置用户页面的URL</span>:</p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">userId</code>指定需要访问的抖音用户ID。</li><li style="list-style: disc; box-sizing: border-box;"><code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">url</code>构建要访问的URI,格式为<code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">snssdk1128://aweme/detail/{userId}</code>。</li></ul></li><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">尝试使用Intent启动抖音应用</span>:</p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;">创建一个<code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">Intent</code>对象,用于启动<code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">ACTION_VIEW</code>操作,同时解析为之前构建的URL。</li><li style="list-style: disc; box-sizing: border-box;">设置标志为<code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">FLAG_ACTIVITY_NEW_TASK</code>,确保活动在新任务中启动。</li><li style="list-style: disc; box-sizing: border-box;">调用<code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">context.startActivity(intent)</code>尝试启动抖音的活动。</li></ul></li><li style="box-sizing: border-box;"><p style="margin-top: 16px; margin-bottom: 1.5em; box-sizing: border-box;"><span style="box-sizing: border-box; font-weight: 700;">异常处理</span>:</p><ul style="margin-left: 14px; padding-left: 2em; box-sizing: border-box;"><li style="list-style: disc; box-sizing: border-box;">捕获<code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">ActivityNotFoundException</code>,用于检测设备上是否安装了抖音应用。</li><li style="list-style: disc; box-sizing: border-box;">如果未安装,显示一个Toast提示用户安装应用,并提供一个网页版的链接作为替代。如果网页链接也未能处理,将使用<code style="box-sizing: border-box; font-family: Consolas, Monaco, &quot;Lucida Console&quot;, &quot;Liberation Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, monospace; padding: 3px; background: rgb(249, 249, 249); border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(64, 158, 255);">showToast</code>方法显示错误信息。</li></ul></li></ol><p style="color: rgb(51, 51, 51); font-family: &quot;Microsoft YaHei&quot;, Helvetica, &quot;Meiryo UI&quot;, &quot;Malgun Gothic&quot;, &quot;Segoe UI&quot;, &quot;Trebuchet MS&quot;, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, &quot;Helvetica Neue&quot;, &quot;Droid Sans&quot;, &quot;wenquanyi micro hei&quot;, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; box-sizing: border-box;"></p><div><ignore_js_op><br></ignore_js_op></div><p></p>
页: [1]
查看完整版本: 无需担心应用未安装,自动切换到快手和抖音网页