【问题标题】:My Webview App keeps crashing for messenger chat我的 Webview 应用程序在进行信使聊天时不断崩溃
【发布时间】:2020-12-17 02:14:17
【问题描述】:

一切正常,除了信使。 代码

if (url.startsWith("www.messenger.com")) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(intent);
                return true;
            }

对于 messenger,即使是这个通用意图代码,它也不会显示使用 messenger 打开的选项


if (url.startsWith("intent")){
                Intent sendIntent = new Intent();
                sendIntent.setAction(Intent.ACTION_VIEW);
                if (sendIntent.resolveActivity(getPackageManager()) != null) {
                    startActivity(sendIntent);
                }
                return true;
            }

带有协议错误日志:

2020-08-28 17:21:24.098 16802-16802/com.mesports.ga E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.mesports.ga, PID: 16802
    android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=intent://user/102700191461284/?intent_trigger=mme&ref=c4254e87a85bef8dd4c3e74bc771d099dda9c6bb22e340c644&nav=discover&source=customer_chat_plugin&source_id=1507329&metadata={"referer_uri":"https:\/\/m-esports.ga\/f2d7b535e73be5c"} }
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2014)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1675)
        at android.app.Activity.startActivityForResult(Activity.java:4586)
        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:676)
        at android.app.Activity.startActivityForResult(Activity.java:4544)
        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:663)
        at android.app.Activity.startActivity(Activity.java:4905)
        at android.app.Activity.startActivity(Activity.java:4873)
        at com.mesports.ga.MainActivity$MyWebviewClient.shouldOverrideUrlLoading(MainActivity.java:194)
        at android.webkit.WebViewClient.shouldOverrideUrlLoading(WebViewClient.java:77)
        at org.chromium.android_webview.AwContentsClientBridge.shouldOverrideUrlLoading(chromium-Monochrome.aab-stable-418308173:16)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:326)
        at android.os.Looper.loop(Looper.java:160)
        at android.app.ActivityThread.main(ActivityThread.java:6762)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

即使使用 http 和 https 协议,它也会显示相同的错误

这是 android 清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mesports.ga">
    <uses-permission  android:name="android.permission.INTERNET"></uses-permission>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity"
            android:screenOrientation="portrait">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>
        </activity>
    </application>

</manifest>

【问题讨论】:

  • if (url.startsWith("www.messenger.com") 浏览器操作视图的 URL 应以协议开头。所以使用if (url.startsWith("http://www.messenger.com")if (url.startsWith("https://www.messenger.com")。并让您的网址以它开头! ;-)。
  • 还是一样的@blackapps,我也添加了协议版本的错误日志
  • 它显示 `No Activity found to handle intent` 但通过 chrome 应用打开时会加载
  • 你有两个意图的代码。第二个好像不行但是你说的是哪一个?对于第一个,您尝试打开浏览器。你想要的第二个是未知的。而且还不清楚这与 webview 有什么关系。
  • 我想在 Messenger 应用程序中打开聊天,这是网站 - www.m-esports.ga @blackapps

标签: java android android-studio android-intent android-webview


【解决方案1】:

您需要在清单文件中注册您的活动

【讨论】:

  • &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; 这是意图过滤器
  • 您的意图过滤器与操作视图无关。
  • 你能回答@FarukhTariq 我是如何注册主要活动的,并且整个代码都在其中。是否还需要其他东西?
  • @Clare 你的意图过滤器在清单中是正确的,但你需要在清单中声明你的活动以及从上面的代码我无法在你的代码中找到你的活动。
  • @FarukhTariq 我在问题中也添加了清单文件,我还需要在清单中添加其他内容吗?
【解决方案2】:

我终于想通了如何用 WebView 做到这一点。

首先,从页面设置-> 消息中获取您的 Messenger URL。如下图所示。

之后处理要由外部浏览器打开的“intent:”案例。将“https://”与您的信使 URL 一起使用。

if(url.startsWith("intent:"))
            {
                Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://m.me/***********"));
                startActivity(i);
                return true;
            }

而且,你已经完成了。呸!

【讨论】:

  • 这将对所有意图强加。我也在使用其他意图。
  • 您可以在 url.startsWith("intent:") 中为 messenger 添加更多文本。示例:url.startsWith("intent: //user/")
猜你喜欢
  • 1970-01-01
  • 2019-01-19
  • 2017-05-31
  • 1970-01-01
  • 2019-10-12
  • 1970-01-01
  • 1970-01-01
  • 2019-01-28
  • 1970-01-01
相关资源
最近更新 更多