4. 3.1.1 Configuration of your Android Application
- The components, settings and metadata, APIs Level and Hardware or software
of an Android application are described in the AndroidManifest.xml file.
- The manifest is read by the Android system during installation of the
application.
6. 3.1.3 Version and Package
- The package attribute defines the base package for the Java objects referred to
in this file.
- Google Play requires that every Android application uses its own unique
package name. Therefore it is a good habit to use your reverse domain name
here. This will avoid collisions with other Android applications.
- android:versionName and android:versionCode specify the version of your
application. versionName is what the user sees and can be any string.
- versionCode must be an integer. The Android Market determines whether it
should perform an update of the applications for the existing installation based
7. 3.1.4 Application and Component
- The <application> is a container for declaring other Android components.
- The <activity> tag defines an activity. The name attribute points to class, which (if not fully
qualified) is relative to the package defined in the`package` attribute.
- The intent filter part in the Android manifest file, tells the Android runtime that this activity should be
registered as a possible entry point into the application and made available in the launcher of the
Android system. The action defines that it ( android:name="android.intent.action.MAIN" ` ) can be
started. The `category android:name="android.intent.category.LAUNCHER" parameter tells the
Android system to add the activity to the launcher.
- The <@string/app_name> value refers to resource files which contain the actual value of the
application name. The usage of a resource file makes it easy to provide different resources (e.g.,
strings, colors, icons) for different devices and makes it easy to translate applications.
8. 3.1.4 Minimum and target SDK
minSdkVersion: Define the minimum
version of Android your application
works on. This attribute is used as a
filter in applications stores Play. A
user cannot install your application on
a device with a lower API level than
specified in this attribute.
targetSdkVersion: Specifies the
version on which you tested and
developed. If it is not equal to the API
version of the Android device, the
Android system might apply forward-
or backward-compatibility changes. It
is good practice to always set this to
the latest Android API version to take
advantages of changes in the latest
Android improvements.
9. 3.1.5 Permissions
- The Android manifest file must also contain the required permissions for the
application. For example, if the application requires network access, it must be
specified here.
- Your application can declare permissions with the <permission> tag and
declare that it required a permission with the <uses-permission> tag.
- Certain permissions, like network access, are granted automatically on Android
6.0 or higher systems. Other permissions must be confirmed by the users to
become active.
10. 3.1.6 Required Device Configuration
- The uses-configuration section in the manifest allows you to specify required
input methods for your device. For example, the following snippet would require
that the device has a hardware keyboard.
<uses-configuration android:reqHardKeyboard="true"/>
- The uses-feature section allows you to specify the required hardware
configuration for your device. For example, the following snippet would require
that the device has a camera.
<uses-feature android:name="android.hardware.camera" />
12. 3.2.1 Resource Introduction
- Externalize Resource has such as image, string, layout,...
- There are 2 kind of Resource: Default and Alternative resources.
- Example : res/layout vs res/layout-land
- Externalize Resource allows alternative resource that support specific device
configurations such as different languages or screen sizes.
- At runtime, Android uses the appropriate resource based on the current
configuration.
13. 3.2.2 Resource Type
Directory Resource Type
animator/ XML files that define property animations.
anim/ XML files that define tween animations. (Property animations can also be saved in
this directory, but the animator/ directory is preferred for property animations to
distinguish between the two types.)
color/ XML files that define a state list of colors
drawable/ Bitmap files (.png, .9.png, .jpg, .gif) or XML files that are compiled into the
following drawable resource subtypes:
Bitmap files, Nine-Patches (re-sizable bitmaps), State lists, Shapes, Animation
drawables, Other drawables
mipmap/ Drawable files for different launcher icon densities.
layout/ XML files that define a user interface layout
14. Directory Resource Type
menu/ XML files that define application menus, such as an Options Menu, Context Menu, or Sub Menu
raw/ Arbitrary files to save in their raw form. To open these resources with a raw InputStream, call
Resources.openRawResource() with the resource ID, which is R.raw.filename.
However, if you need access to original file names and file hierarchy, you might consider saving
some resources in the assets/ directory (instead of res/raw/). Files in assets/ are not given a
resource ID, so you can read them only using AssetManager.
values/ XML files that contain simple values, such as strings, integers, and colors.
arrays.xml for resource arrays (typed arrays).
colors.xml for color values
dimens.xml for dimension values.
strings.xml for string values.
styles.xml for styles.
xml/ Arbitrary XML files that can be read at runtime by calling Resources.getXML(). Various XML
configuration files must be saved here, such as a searchable configuration.
font/ Font files with extensions such as .ttf, .otf, or .ttc, or XML files that include a <font-family>
element. For more information about fonts as resources, go to Fonts in XML.
15. 3.2.3 Alternative Resource
- Alternative Resource - <resources_name>-<config_qualifier>.
- <resources_name> is the directory name of the corresponding default resources (defined in table 1).
- <qualifier> is a name that specifies an individual configuration for which these resources are to be
used (defined in table 2)
- Example
res/
drawable/
icon.png
background.png
drawable-hdpi/
icon.png
Background.png
- Details - https://developer.android.com/guide/topics/resources/providing-
resources.html#ResourceTypes
16. 3.2.4 Resource Accessing
- There are two ways to access a resource:
- In code: Using a static integer from a sub-class of your R class, such as:
● R.string.hello
● string is the resource type and hello is the resource name. There are many Android APIs
that can access your resources when you provide a resource ID in this format.
- In XML: Using a special XML syntax that also corresponds to the resource ID defined in your R
class, such as:
● @string/hello
● string is the resource type and hello is the resource name. You can use this syntax in an
XML resource any place where a value is expected that you provide in a resource.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="opaque_red">#f00</color>
<string name="hello">Hello!</string>
</resources>
res/values/string.xml
18. 3.3.1 Asset Introduction
- assets/ directory (instead of res/raw/).
- Files in assets/ are not given a resource ID, so you can read them only using
AssetManager.
19. Example of Using Assets
Java code:
WebView wv = (WebView)this.findViewById(R.id.splashWebView);
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
wv.loadUrl("file:///android_asset/html_no_copy/demo_welcome.html");
20. demo_welcome.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Demo Html</title>
<link rel="stylesheet" type="text/css" href="demo.css" />
</head>
<body>
<H1>Testing One Two Three</H1>
<a href="test.html">CLICK HERE</a><p>
<a href="file:///android_asset/html_no_copy/test.html">OR HERE</a>
</body>
</html>
test.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="test.css" />
<title>Insert title here</title>
</head>
<body>
<H1>TEST.HTML</H1>
</body>
</html>