Class: Android::Manifest
- Inherits:
-
Object
- Object
- Android::Manifest
- Defined in:
- lib/android/manifest.rb
Overview
parsed AndroidManifest.xml class
Defined Under Namespace
Modules: IntentFilter Classes: Component, Meta
Constant Summary collapse
- APPLICATION_TAG =
'/manifest/application'
Instance Attribute Summary collapse
-
#doc ⇒ REXML::Document
readonly
Manifest class definitions.
Instance Method Summary collapse
-
#components ⇒ Array<Android::Manifest::Component>
All components in apk.
-
#initialize(data, rsc = nil) ⇒ Manifest
constructor
A new instance of Manifest.
-
#label(lang = nil) ⇒ String?
application label.
-
#min_sdk_ver ⇒ Integer
MinSdkVersion in uses element.
-
#package_name ⇒ String
application package name.
-
#to_xml(indent = 4) ⇒ String
return xml as string format.
-
#use_permissions ⇒ Array<String>
used permission array.
-
#version_code ⇒ Integer
application version code.
-
#version_name(lang = nil) ⇒ String
application version name.
Constructor Details
#initialize(data, rsc = nil) ⇒ Manifest
Returns a new instance of Manifest.
156 157 158 159 160 |
# File 'lib/android/manifest.rb', line 156 def initialize(data, rsc=nil) parser = AXMLParser.new(data) @doc = parser.parse @rsc = rsc end |
Instance Attribute Details
#doc ⇒ REXML::Document (readonly)
Manifest class definitions
153 154 155 |
# File 'lib/android/manifest.rb', line 153 def doc @doc end |
Instance Method Details
#components ⇒ Array<Android::Manifest::Component>
return empty array when the manifest include no components
Returns all components in apk.
175 176 177 178 179 180 181 182 183 |
# 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) ⇒ String?
application label
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# 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 ⇒ Integer
Returns minSdkVersion in uses element.
212 213 214 |
# File 'lib/android/manifest.rb', line 212 def min_sdk_ver @doc.elements['/manifest/uses-sdk'].attributes['minSdkVersion'].to_i end |
#package_name ⇒ String
application package name
187 188 189 |
# File 'lib/android/manifest.rb', line 187 def package_name @doc.root.attributes['package'] end |
#to_xml(indent = 4) ⇒ String
return xml as string format
242 243 244 245 246 247 |
# 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 ⇒ Array<String>
return empty array when the manifest includes no use-parmission element
used permission array
165 166 167 168 169 170 171 |
# File 'lib/android/manifest.rb', line 165 def perms = [] @doc.each_element('/manifest/uses-permission') do |elem| perms << elem.attributes['name'] end perms.uniq end |
#version_code ⇒ Integer
application version code
193 194 195 |
# File 'lib/android/manifest.rb', line 193 def version_code @doc.root.attributes['versionCode'].to_i end |
#version_name(lang = nil) ⇒ String
application version name
199 200 201 202 203 204 205 206 207 208 209 |
# 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 |