2

Everything works as it should except messenger. Code

if (url.startsWith("www.messenger.com")) {
                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("intent")){
                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&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)

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

Here's the android manifest file

<?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>
Clare
  • 31
  • 5
  • `if (url.startsWith("www.messenger.com")` Urls for action view for browsers should start with a protocol. So use `if (url.startsWith("http://www.messenger.com")` or `if (url.startsWith("https://www.messenger.com")`. And let your url start with it! ;-). – blackapps Aug 28 '20 at 11:44
  • Still the same @blackapps i have added the error logs for the protocol version too – Clare Aug 28 '20 at 11:52
  • its showing ` No Activity found to handle intent` but it loads when opened through chrome app – Clare Aug 28 '20 at 11:56
  • You have code for two intents. The second one looks not ok. But about which one are you talking? With the first one you try to open a browser. What you want with the second one is unknown. And it is also unclear what this has to do with a webview. – blackapps Aug 28 '20 at 12:08
  • I want to open the chat in messenger app this is the website - www.m-esports.ga @blackapps – Clare Aug 28 '20 at 12:49
  • In second one I was just checking which options appear for the intent it showed all options but it didnt show messenger – Clare Aug 28 '20 at 13:01
  • @blackapps I have checked the other posts too and all of them have answers that aren't marked as answer by the people who have asked the question. It's still unresolved I guess. – Karan Sethi Aug 29 '20 at 19:39
  • Is there no way to do it then? – Clare Sep 03 '20 at 04:54
  • @Clare Did you find a solution for this? – Rahul Kumar Dec 17 '20 at 14:22
  • I tried and was able to extract the package from the URL of the intent, and then launch the activity using that package. Messenger App was launched but not as expected in the case of the chatbot. Did anyone made any progress on this or was able to find any solution or workaround? @blackapps – Rahul Kumar Dec 17 '20 at 16:00
  • `if (url.startsWith("www.messenger.com")` That can never work. Didnt you mean `if (url.startsWith("https://www.messenger.com")` ? – blackapps Dec 17 '20 at 16:30

2 Answers2

0

You need to register your activity in manifest file

Bhargav Rao
  • 41,091
  • 27
  • 112
  • 129
  • ` ` This is the intent filter – Clare Aug 28 '20 at 12:05
  • Your intent filter has nothing to do with action view. – blackapps Aug 28 '20 at 12:08
  • Can you answer how @FarukhTariq I have registered the main activity and the whole code is in it. Is something else required too? – Clare Aug 28 '20 at 15:24
  • @Clare your intent filters are correct in manifest but you need to declare your activity in manifest as well from your above code i am unable to find your activity inside your code. – Farukh Tariq Aug 29 '20 at 06:15
  • @FarukhTariq I have added the manifest file too in the question do I need to add something else in manifest too? – Clare Aug 29 '20 at 06:47
0

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.

enter image description here

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

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

And, you are done. Phew!

Rahul Kumar
  • 79
  • 2
  • 10