Open an url in android browser, avoid multiple tabs

前端 未结 2 826
抹茶落季
抹茶落季 2020-12-29 08:31

My project is mostly a web application. Now I have an android app with a home screen widget and would like to open a web page in the built-in browser on some user actions. T

相关标签:
2条回答
  • 2020-12-29 09:13

    Yes, this is possible. Use http://developer.android.com/reference/android/provider/Browser.html#EXTRA_APPLICATION_ID to ensure that the same browser tab is reused for your application. For example:

    Context context = widget.getContext();
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
    
    0 讨论(0)
  • 2020-12-29 09:16

    To the best of my knowledge there is no way to specify if a new tab is opened or not using the Intent. I even did some looking and could not find anyway to check which tabs were open. Another thing you may be able to try is keeping track of if the user has recently been sent to the browser activity from your application, and check if the browser is still open, but once again I can see this going wrong in numerous ways.

    Your activity idea would probably be one of the best bets in this situation, though I can understand why you would want to avoid that.

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