How to implement my very own URI scheme on Android

后端 未结 5 691
借酒劲吻你
借酒劲吻你 2020-11-22 06:12

Say I want to define that an URI such as:

myapp://path/to/what/i/want?d=This%20is%20a%20test

must be handled by my own application, or serv

5条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 07:02

    This is very possible; you define the URI scheme in your AndroidManifest.xml, using the element. You setup an intent filter with the element filled out, and you'll be able to create your own scheme. (More on intent filters and intent resolution here.)

    Here's a short example:

    
        
            
            
            
            
        
    
    

    As per how implicit intents work, you need to define at least one action and one category as well; here I picked VIEW as the action (though it could be anything), and made sure to add the DEFAULT category (as this is required for all implicit intents). Also notice how I added the category BROWSABLE - this is not necessary, but it will allow your URIs to be openable from the browser (a nifty feature).

提交回复
热议问题