Intent Filter to Launch My Activity when custom URI is clicked

后端 未结 7 2040
傲寒
傲寒 2020-12-07 14:58

I am trying to allow a URI to be registered to open up with my app. Like the PatternRepository on the Blackberry and the CFBundleURLName/CFBu

相关标签:
7条回答
  • 2020-12-07 15:34

    You could always try sending your emails using HTML and then use an <a> tag around to create the URL. I don't think there is a way to change the way the Gmail or Mail parse their text, since they probably use the Linkify class.

    Another option would be use use http:// and then just parse for a specific custom subdomain which would provide your users with the option to open in a browser or your application.

    0 讨论(0)
  • 2020-12-07 15:45

    When I was working on OAuth with Google Calendar, I had to add this filter to the Activity I wanted to receive the callback:

    <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="yourapp" android:host="goog"></data>
    </intent-filter>
    

    The when the browser invoked the yourapp://goog URL, it would return to my Activity.

    0 讨论(0)
  • 2020-12-07 15:45

    I just ran into this also, but for standard http: scheme urls. Gmail doesn't appear to add any categories to the Intent. Now I check for BROWSABLE, but I also include a check for !intent.hasCategories() and allow that to go through as well.

    0 讨论(0)
  • 2020-12-07 15:47

    This is solution for me. Thanks @DanO

    <intent-filter>
            <data android:scheme="yourcustomname"/>
            <data android:host="*"/>
                    <action android:name="android.intent.action.VIEW" />
                    <category android:name="android.intent.category.DEFAULT" />
                    <category android:name="android.intent.category.BROWSABLE" />
      </intent-filter>
    
    0 讨论(0)
  • 2020-12-07 15:54

    The final solution was a hacky workaround to cover all bases. The email now also contains an attachment with an extension that is registered to open with the app.

    AndroidManifest.xml :

        <activity android:name=".gui.activity.CustomerDetailActivity" > 
            <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="https"
                     android:host="myapp.mycompany.com" /> 
            </intent-filter> 
    
            <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="myapp"
                     android:host="myapp.mycompany.com" /> 
            </intent-filter>
    
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <action android:name="android.intent.action.EDIT" />
                <action android:name="android.intent.action.PICK" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:mimeType="application/myapp" />
            </intent-filter>
        </activity>
    
    0 讨论(0)
  • 2020-12-07 15:55

    You can get around the issue of GMail not linking non-standard protocols by using a standard HTTP URL with a 302 redirect. You could either set it up on your website's webserver or application server, or for the quick and dirty test you could use a URL shortener like http://bit.ly.

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