skip to Main Content

I Wanna open My android app by links like WhatsApp and Telegram.

(example) https://chat.whatsapp.com if I Click this link and WhatsApp is installed this link will open WhatsApp So how can I do that in my app?

2

Answers


  1. First thing you should define your base URL inside strings file like this :

    <string name="base_url" translatable="false">yourapp.me</string>
    

    after that you should define an IntentFilter inside Manifest file like this :

    <activity android:name=".ExampleActivity">
    
    
    <intent-filter android:label="@string/app_name">
    
    <action android:name="android.intent.action.VIEW"/>
    
    <category android:name="android.intent.category.DEFAULT"/>
    
    <category android:name="android.intent.category.BROWSABLE"/>
    
    <data android:scheme="https" android:pathPrefix="/api" android:host="@string/base_url"/>
    
    </intent-filter>
    
    </activity>
    

    So your link should be like this :

    https://yourapp.me/api
    

    when you click on this link it should open your app in the activity that you put this intent filter inside it.

    Login or Signup to reply.
  2. If you want to deep link your app. For example: You open a link and it should be open through your app. In this case I use a website opened with a webView in your app. You can customize that of course.

    Start to create an <intent-filter> in your AndroidManifest.xml:

          <application
             <activity
                <intent-filter>
                       ...
                    <action android:name="android.intent.action.VIEW"></action>
                    <category android:name="android.intent.category.DEFAULT"></category>
                    <category android:name="android.intent.category.BROWSABLE"></category>
                       
                    <data android:scheme="https"
                        android:host="yourURL"></data>
                       ...
                </intent-filter>
            </activity>
         </application>
    

    And in your MainActivity.java you write the following code to get the data to be set in the webView:

    Uri uri = getIntent().getData();
            if (uri!=null){
                String path = uri.toString();
                
                WebView webView = (WebView)findViewById(R.id.webView);
                webView.loadUrl(path);
            }
    

    And your webView defined in your activity_main.xml:

                     <WebView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:id="@+id/webView"/>
    

    That’s it. Good luck! Cheers 🙂

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search