class Android::Manifest

parsed AndroidManifest.xml class @see developer.android.com/guide/topics/manifest/manifest-intro.html

Constants

APPLICATION_TAG

Attributes

doc[R]

Manifest class definitions

@return [REXML::Document] manifest xml

Public Class Methods

new(data, rsc=nil) click to toggle source

@param [String] data binary data of AndroidManifest.xml

# File lib/android/manifest.rb, line 156
def initialize(data, rsc=nil)
  parser = AXMLParser.new(data)
  @doc = parser.parse
  @rsc = rsc
end

Public Instance Methods

components() click to toggle source

@return [Array<Android::Manifest::Component>] all components in apk @note return empty array when the manifest include no components

# File lib/android/manifest.rb, line 175
def components
  components = []
  unless @doc.elements['/manifest/application'].nil?
    @doc.elements['/manifest/application'].each do |elem|
      components << Component.new(elem) if Component.valid?(elem)
    end
  end
  components
end
label(lang=nil) click to toggle source

application label @param [String] lang language code like ‘ja’, ‘cn’, … @return [String] application label string(if resouce is provided), or label resource id @return [nil] when label is not found @since 0.5.1

# File lib/android/manifest.rb, line 221
def label(lang=nil)
  label = @doc.elements['/manifest/application'].attributes['label']
  if label.nil?
    # application element has no label attributes.
    # so looking for activites that has label attribute.
    activities = @doc.elements['/manifest/application'].find{|e| e.name == 'activity' && !e.attributes['label'].nil? }
    label = activities.nil? ? nil : activities.first.attributes['label']
  end
  unless @rsc.nil?
    if /^@(\w+\/\w+)|(0x[0-9a-fA-F]{8})$/ =~ label
      opts = {}
      opts[:lang] = lang unless lang.nil?
      label = @rsc.find(label, opts)
    end
  end
  label
end
min_sdk_ver() click to toggle source

@return [Integer] minSdkVersion in uses element

# File lib/android/manifest.rb, line 212
def min_sdk_ver
  @doc.elements['/manifest/uses-sdk'].attributes['minSdkVersion'].to_i
end
package_name() click to toggle source

application package name @return [String]

# File lib/android/manifest.rb, line 187
def package_name
  @doc.root.attributes['package']
end
to_xml(indent=4) click to toggle source

return xml as string format @param [Integer] indent size(bytes) @return [String] raw xml string

# File lib/android/manifest.rb, line 242
def to_xml(indent=4)
  xml =''
  formatter = REXML::Formatters::Pretty.new(indent)
  formatter.write(@doc.root, xml)
  xml
end
use_permissions() click to toggle source

used permission array @return [Array<String>] permission names @note return empty array when the manifest includes no use-parmission element

# File lib/android/manifest.rb, line 165
def use_permissions
  perms = []
  @doc.each_element('/manifest/uses-permission') do |elem|
    perms << elem.attributes['name']
  end
  perms.uniq
end
version_code() click to toggle source

application version code @return [Integer]

# File lib/android/manifest.rb, line 193
def version_code
  @doc.root.attributes['versionCode'].to_i
end
version_name(lang=nil) click to toggle source

application version name @return [String]

# File lib/android/manifest.rb, line 199
def version_name(lang=nil)
  vername = @doc.root.attributes['versionName']
  unless @rsc.nil?
    if /^@(\w+\/\w+)|(0x[0-9a-fA-F]{8})$/ =~ vername
      opts = {}
      opts[:lang] = lang unless lang.nil?
      vername = @rsc.find(vername, opts)
    end
  end
  vername
end