Package com.unblu.sdk.core.links
Class UnbluPatternMatchingExternalLinkHandler
java.lang.Object
com.unblu.sdk.core.links.UnbluPatternMatchingExternalLinkHandler
- All Implemented Interfaces:
UnbluExternalLinkHandler
public class UnbluPatternMatchingExternalLinkHandler
extends Object
implements UnbluExternalLinkHandler
An implementation of the
UnbluExternalLinkHandler
interface.
This implementation checks links against a list of link patterns and returns UnbluExternalLinkHandlingPolicy.OPEN
if the link matches a pattern.
-
Constructor Summary
ConstructorDescriptionDefault constructor.UnbluPatternMatchingExternalLinkHandler
(List<Pattern> patternList) This constructor allows the user to pass in a custom list ofPattern
s. -
Method Summary
Modifier and TypeMethodDescriptiondecidePolicy
(android.net.Uri url) Determines the handling policy for a given URL within a conversation.
-
Constructor Details
-
UnbluPatternMatchingExternalLinkHandler
public UnbluPatternMatchingExternalLinkHandler()Default constructor.
If you use this constructor, the list of patterns that may be opened in the system browser is as follows:^\Qhttps://\E.*
^\Qmailto://\E.*
^\Qtel:\E.*
-
UnbluPatternMatchingExternalLinkHandler
This constructor allows the user to pass in a custom list ofPattern
s. The list overrides the default list.- Parameters:
patternList
- A list of patterns to compare links to
-
-
Method Details
-
decidePolicy
Determines the handling policy for a given URL within a conversation. This method checks the URL against a list of predefined URL patterns. If the URL matches any of the patterns, it permits opening the link by returningUnbluExternalLinkHandlingPolicy.OPEN
. If the URL does not match any pattern, the link is not allowed to be opened, indicated by returningUnbluExternalLinkHandlingPolicy.BLOCK
. This approach allows for fine-grained control over which links can be opened, enhancing security by preventing potentially harmful links from being accessed.- Specified by:
decidePolicy
in interfaceUnbluExternalLinkHandler
- Parameters:
url
- TheUri
object representing the link that was clicked. This parameter is used to extract the string representation of the URL for pattern matching.- Returns:
- The
UnbluExternalLinkHandlingPolicy
indicating whether the link should be opened or blocked. If the URL matches a predefined pattern,UnbluExternalLinkHandlingPolicy.OPEN
is returned, otherwiseUnbluExternalLinkHandlingPolicy.BLOCK
is returned.
-