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

actions[R]

@return [IntentFilter::Action] intent-filter actions

activity[R]

@return [IntentFilter::Data] intent-filter data

categories[R]

@return [IntentFilter::Category] intent-filter categories

data[R]

@return [IntentFilter::Data] intent-filter data

Public Class Methods

new(filter) click to toggle source
# 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
valid?(filter) click to toggle source

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

browsable?() click to toggle source

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
empty?() click to toggle source

Returns true if self contains no [IntentFilter::Action] elements. @return [Boolean]

# File lib/android/manifest.rb, line 184
def empty?
  @actions.empty?
end
exist?(name, type: nil) click to toggle source
# 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
schemes() click to toggle source

@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
schemes?() click to toggle source

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