Handle download intents in my app

前端 未结 2 611
星月不相逢
星月不相逢 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:06

    You need to put below code in your activity which response the intent,

    void onCreate(Bundle savedInstanceState) {
        // Get intent, action and MIME type
        Intent intent = getIntent();
        String action = intent.getAction();
        String type = intent.getType();
    
        if (Intent.ACTION_VIEW.equals(action))
        {
            */if (type.startsWith("image/“))
              {*/
                downloadImage(intent); // Download image being sent
            }
        }
    
    void downloadImage(Intent intent) {
        Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
        if (imageUri != null) {
            // Write Your Download Code Here
        }
    }
    

提交回复
热议问题