我的 Webview 应用在使用 Messenger 聊天时一直崩溃。

huangapple go评论83阅读模式
英文:

My Webview App keeps crashing for messenger chat

问题

以下是翻译好的内容:

代码部分:

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

对于 Messenger,除了这个一般性的 intent 代码外,它没有显示使用 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)
        ...
        ...

即使使用 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>
英文:

Everything works as it should except messenger.
Code

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

For messenger even for this general intent code it doesnt show the option to open with messenger


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

With protocol Error logs:

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&amp;ref=c4254e87a85bef8dd4c3e74bc771d099dda9c6bb22e340c644&amp;nav=discover&amp;source=customer_chat_plugin&amp;source_id=1507329&amp;metadata={&quot;referer_uri&quot;:&quot;https:\/\/m-esports.ga\/f2d7b535e73be5c&quot;} }
        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)

even by using http and https protocols it is showing the same error

Here's the android manifest file

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    package=&quot;com.mesports.ga&quot;&gt;
    &lt;uses-permission  android:name=&quot;android.permission.INTERNET&quot;&gt;&lt;/uses-permission&gt;

    &lt;application
        android:allowBackup=&quot;true&quot;
        android:icon=&quot;@mipmap/ic_launcher&quot;
        android:label=&quot;@string/app_name&quot;
        android:roundIcon=&quot;@mipmap/ic_launcher_round&quot;
        android:supportsRtl=&quot;true&quot;
        android:theme=&quot;@style/AppTheme&quot;&gt;
        &lt;activity android:name=&quot;.MainActivity&quot;
            android:screenOrientation=&quot;portrait&quot;&gt;

            &lt;intent-filter&gt;

                &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;

                &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;

            &lt;/intent-filter&gt;
        &lt;/activity&gt;
    &lt;/application&gt;

&lt;/manifest&gt;

答案1

得分: 1

我终于弄清楚如何在 WebView 中实现了。

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

我的 Webview 应用在使用 Messenger 聊天时一直崩溃。

之后处理 "intent:" 情况,以被外部浏览器打开。使用 "https://" 和您的 Messenger 链接。

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

然后,就完成了。哇!

英文:

I finally figured out how to do it with WebView.

First, get Your Messenger URL from Page Settings-> Messaging. As shown in the below image.

我的 Webview 应用在使用 Messenger 聊天时一直崩溃。

After that handle the "intent:" case to be opened by an external browser. Use "https://" with your messenger URL.

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

And, you are done. Phew!

答案2

得分: 0

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

英文:

You need to register your activity in manifest file

huangapple
  • 本文由 发表于 2020年8月28日 14:45:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/63628794.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定