Android App link - Open a url from app in browser without triggering App Link

后端 未结 4 457
名媛妹妹
名媛妹妹 2021-01-12 05:46

I have enabled App linking in my application. It works fine. But in my application there are some scenarios where i cannot handle the incoming url. In those cases i want to

相关标签:
4条回答
  • 2021-01-12 06:02
    String data = "example.com/your_url?param=some_param";
    Intent defaultBrowser = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_BROWSER);
    defaultBrowser.setData(data);
    startActivity(defaultBrowser);
    

    this technique (using makeMainSelectorActivity) will force the link to open in the device's default browser

    Note - makeMainSelectorActivity only works for API level 15 and above.

    If you need to support API levels lower than 15, you could try this hack

    0 讨论(0)
  • 2021-01-12 06:23
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://stackoverflow.com/questions/58800240/android-app-link-open-a-url-from-app-in-browser-without-triggering-app-link"));
            Intent chooseIntent = Intent.createChooser(intent, "Choose from below");
            startActivity(chooseIntent);
    

    This will open all the installed web browsers from which user can choose!

    0 讨论(0)
  • 2021-01-12 06:27

    In Kotlin, try using makeMainSelectorActivity :

    val defaultBrowser = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_BROWSER)
    defaultBrowser.data = Uri.parse("https://yoururl.com/")
    startActivity(defaultBrowser)
    
    0 讨论(0)
  • 2021-01-12 06:27

    Unfortunately, we can't exclude any certain URL, since Android doesn't provide that option.

    But you can handle using path prefix.

    // To handle:
    http://myhost.com/v/page1?id=123
    // To exclude:
    http://myhost.com/v/page2?id=123
    

    then in manifiest

    <data android:scheme="http"
          android:host="myhost.com"
          android:pathPrefix="/v/page1" />
    
    0 讨论(0)
提交回复
热议问题