class Android::Manifest::IntentFilter
intent-filter element in components
Constants
- CATEGORY_BROWSABLE
browsable of category
- TYPES
filter types (action is required, category and data are optional)
Attributes
@return [IntentFilter::Action] intent-filter actions
@return [IntentFilter::Data] intent-filter data
@return [IntentFilter::Category] intent-filter categories
@return [IntentFilter::Data] intent-filter data
Public Class Methods
# File lib/android/manifest.rb, line 161 def initialize(filter) @activity = filter.parent @actions = [] @categories = [] @data = [] filter.elements.each do |element| type = element.name.downcase next unless TYPES.include?(type) case type when 'action' @actions << Action.new(element) when 'category' @categories << Category.new(element) when 'data' @data << Data.new(element) end end end
the element is valid IntentFilter
element or not @param [REXML::Element] elem xml element @return [Boolean]
# File lib/android/manifest.rb, line 144 def self.valid?(filter) filter&.elements&.any? do |elem| TYPES.include?(elem&.name&.downcase) end rescue => e false end
Public Instance Methods
the browsable category vaild or not @return [Boolean] @since 2.5.0
# File lib/android/manifest.rb, line 248 def browsable? exist?(CATEGORY_BROWSABLE) end
@return [Array<String>] all data elements @note return empty array when the manifest include no http or https scheme of data @since 2.5.0
# File lib/android/manifest.rb, line 212 def deep_links return unless deep_links? data.select {|d| !d.host.nil? } .map { |d| d.host } .uniq end
the deep links exists with http or https in data element or not @return [Boolean] @since 2.5.0
# File lib/android/manifest.rb, line 223 def deep_links? browsable? && data.any? { |d| ['http', 'https'].include?(d.scheme) } end
Returns true if self contains no [IntentFilter::Action] elements. @return [Boolean]
# File lib/android/manifest.rb, line 184 def empty? @actions.empty? end
# File lib/android/manifest.rb, line 188 def exist?(name, type: nil) if type.to_s.empty? && !name.start_with?('android.intent.') raise 'Fill type or use correct name' end type ||= name.split('.')[2] raise 'Not found type' unless TYPES.include?(type) method_name = case type when 'action' :actions when 'category' :categories when 'data' :data end values = send(method_name).select { |e| e.name == name } values.empty? ? false : values #(values.size == 1 ? values.first : values) end
@return [Array<String>] all data elements @note return empty array when the manifest not include http or https scheme(s) of data @since 2.5.0
# File lib/android/manifest.rb, line 230 def schemes return unless schemes? data.select {|d| !d.scheme.nil? && !['http', 'https'].include?(d.scheme) } .map { |d| d.scheme } .uniq end
the deep links exists with non-http or non-https in data element or not @return [Boolean] @since 2.5.0
# File lib/android/manifest.rb, line 241 def schemes? browsable? && data.any? { |d| !['http', 'https'].include?(d.scheme) } end