Android Respond To URL in Intent

后端 未结 2 1541
Happy的楠姐
Happy的楠姐 2020-11-22 05:07

I want my intent to be launched when the user goes to a certain url: for example, the android market does this with http://market.android.com/ urls. so does youtube. I want

相关标签:
2条回答
  • 2020-11-22 05:52

    You might need to add different permutations to your intent filter to get it to work in different cases (http/ https/ ect).

    For example, I had to do the following for an app which would open when the user opened a link to google drive forms, www.docs.google.com/forms

    Note that path prefix is optional.

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data
                    android:scheme="http"
                    android:host="docs.google.com"
                    android:pathPrefix="/forms"/>
                <data
                    android:scheme="http"
                    android:host="www.docs.google.com"
                    android:pathPrefix="/forms" />
    
                <data
                    android:scheme="https"
                    android:host="www.docs.google.com"
                    android:pathPrefix="/forms" />
    
                <data
                    android:scheme="https"
                    android:host="docs.google.com"
                    android:pathPrefix="/forms" />
            </intent-filter>
    
    0 讨论(0)
  • 2020-11-22 06:07

    I did it! Using <intent-filter>. Put the following into your manifest file:

    <intent-filter>
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.DEFAULT" />
      <category android:name="android.intent.category.BROWSABLE" />
      <data android:host="www.youtube.com" android:scheme="http" />
    </intent-filter>
    

    This works perfectly!

    0 讨论(0)
提交回复
热议问题