This question already has answers here:
Android Respond To URL in Intent
                                
                                    (2个答案)
                                
                        
                                6年前关闭。
            
                    
当用户单击给定模式的URL而不是允许浏览器打开它时,我希望能够启动已安装的应用程序。当用户在浏览器中的网页上时,可能是这种情况。

例如,从手机中的任意位置单击YouTube链接,您将有机会打开安装在

如何为自己的应用程序实现这一目标?

最佳答案

在您的MyLinkActivity中:

String url = getIntent().getDataString();


在您的清单中:

<activity
    android:name=".MyLinkActivity">
    <intent-filter>
        <data
            android:host="*.myurl.com"
            android:scheme="http" />
        <data
            android:host="myurl.com"
            android:scheme="http" />
        <data
            android:host="*.myurl.com"
            android:scheme="https" />
        <data
            android:host="myurl.com"
            android:scheme="https" />
                
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <action android:name="android.intent.action.VIEW" />   
    </intent-filter>
</activity>

09-11 20:18
查看更多