Handle download intents in my app

前端 未结 2 607
星月不相逢
星月不相逢 2021-02-13 19:31

My webview app already handles external URL\'s fine (opens links from external apps like viber, browsers, etc) like this- (i got this code from here)

// get URL          


        
2条回答
  •  广开言路
    2021-02-13 20:21

    you have to solve issues to

    • (a) always show the chooser
    • (b) tell android that your app should become part of the chooser
    • (c) process the "download"

    (a) always show the chooser

    replace

    startActivity(i);
    

    with

    startActivity(Intent.createChooser(i, "caption of the choser"));
    

    (b) tell android that your app should become part of the chooser

    In the manifest you have to declare that you have an activity that can handle the relevant content

    
        
            
                
                    
                    
                    
    
                    
                    
    
                    
                
                 
                    
                    
                    
    
                    
                    
                    
    
                    
                    
                
            
        
    
    
    

    * (c) process the "download"

    MyDownloadActivity Your MyDownloadActivity.onCreate() will receive all mime-types * / * for SEND, SENDTO, VIEW. For Details see @Vickyexpert-s answer

    intent-intercept is a free android tool to analyse intents. it can intercept nearly every intent. you can look at the sourcecode to see how this is done.

    I use sendtosd as my general purpose download handler. It-s sourcecoder is available on github

提交回复
热议问题