The Android Manifest file is an XML file that describes to the operating system, the application's ID and its capabilities. The name of the file is always the same. Android Manifest.xml. The first time you open it, you'll see this graphical UI in Eclipse. That lets you fill in critical parts of the manifest. You can get to most of the features of the manifest file through one of these tabs labeled manifest, application, permissions, and instrumentation.
But you can always edit the file in raw XML
code, by clicking on the last tab. The
manifest file starts with a name space declaration, pointing to schemas.android.com/apk/res/android. And
assigns a name space prefix of Android. All
of the attributes that are used throughout the
XML file will then use that prefix. Such
as the version code, the version name, and so on. The
manifest element is the root element, and it has three critical attributes.
The package points to the unique identifier
for the app, and it
does need to be globally unique as I've described previously. Typically,
this is accomplished by using the organization Or
the developers domain name in reverse domain notation, and
setting that as the beginning of the package name. So
my package might be com.example, and then I can use anything after that. We'll
stick with the root package that I'll
be using throughout this course org.example.
This package must match the route package in which
you place your Java classes. If
you change this package you also need to update the manifest so
for example I'll make sure that the manifest has been saved
then I'll come back over here to the package explorer
and I'll change it from hello android to hi android. Would
I make that change in my package structure?Some re-factoring will happen in the
XML file but not everything you need. For
example, down here, the
name of the package has been updated to show
the new actual package name that contains this class MainActivity. But
the package hasn't been updated here. I would have to do that manually. I'll
switch this all back to the version that I'll be using, Hello Android. And
once again show that the manifest has been
updated in the activity element down here. The
next two attributes are the version code and the version name. The
version code is always an integer. And
it should be increment by one, each time you update an app and distribute it
to the Google play store, the Amazon app
store, or any other applications distribution channel.
Again the version code is generic and it must
be an integer. You
can't user fractions and you can't use alpha characters. But
the user doesn't see the version code. They
see the version name. And
this can be any string you like. A
new Android app will have a version code of one and a version name of 1.0. That
would be the version that you use when you deliver
it to the app store for the first time. But
the next time you deliver a version, you would update the version code to two.
And you might change the version name to 1.1
or 1.0.1
or 2.0, depending on what you want to communicate to
your users. Next is the uses SDK element. There
are two required attributes here, min SDK version and target SDK version,
and there's an optional attribute Called maxSdkVersion. When
you're editing this XML file manually in Eclipse you can type the beginning of the
attribute name without the Android prefix, and then when it auto completes.
Android will add the prefix as needed. So
for example, let's say I wanted to target Jellybean.That means I'm going to
compile it against that version of the platform. I
would set the target SDK version to 18, for Jellybean, 4.3. But
I then might say this app can also run in later versions of Android. So
I would set this to 19 and that would be for kit kat again I'm
going to reverse all these changes and go back to the default.
The application element contains pointers to
certain resources and also certain
properties, the icon is pointing to the IC launcher graphic. Which
is in the drawable subfolder of the resources folder. This
is how you address an existing resource using XML syntax. Start
with the @ character, then
the name of the folder that the resource is stored in. You
only need to put drawable here, even though the
full names of the files are things like drawable.xhdp.
And again, it's up to the operating system to
figure out which version
of this graphic to use, depending on the current device's pixel density. Next
is the label attribute. This
describes how the application will be represented in the
device's application list and start screen. I'll
describe how this label is used in a number of places later in the course. This
is a string resource and it's defined in another kind of XML file. To
jump to this resource, hold down the Ctrl key
on Windows, or the cmd key on Mac.
And then move the cursor over the resource and
click. And
you'll open the XML file in which the resource is defined and it'll be
highlighted for you. Here's
the resource name, App name, and here's its value. Hello
Android. I'm
going to add an exclamation mark here, and save that change And then the
next time I run the app, we'll see how it's updated on the device. There's
also a theme attribute pointing to the application theme. And
again, we'll get to those details later on.
Finally, we get to an activity element. Each
screen in an application is known as an activity.And each activity has to be
registered with
the application through this application manifest file. The
name is the fully qualified name of the activity. And
it must match the actual package name. The
last time I changed this package, the refactoring didn't happen automatically. So
I'll fix it manually. You
can describe your activities with complete package
and class names, or you can use
a shortcut of just a dot and then the name of the activity.
The single dot means the current package, and
that would be the application's base package.Here's that label again, pointing
to app name. And
here is an intent-filter.
And
this intent-filter is telling the operating system when the user
wants to start up this application, this is
the activity that should start up first. I'll
save this change. And
I'll go back to the main activity class. And
then I'll run the application in the emulator again. When
the application opens, notice that the string resource I
changed is shown here with the exclamation mark.
But it's also shown on the application list. I'll
touch the
home button, then bring up the application list, and I see that
the name or label of the application is updated here as well. I'll
click and hold. And
then drop the application on the home screen. And
the label is being truncated on this version of the home screen,
but on a larger screen that exclamation mark might show up. So
that's a brief tour of the manifest file. We'll
get into other changes you can make in the manifest file throughout this course.
Every application must have an AndroidManifest.xml file (with precisely that name) in its root directory. The manifest file presents essential information about your app to the Android system, information the system must have before it can run any of the app's code. Among other things, the manifest does the following:
Every application must have an AndroidManifest.xml file (with precisely that name) in its root directory. The manifest file presents essential information about your app to the Android system, information the system must have before it can run any of the app's code. Among other things, the manifest does the following:
- It names the Java package for the application. The package name serves as a unique identifier for the application.
- It describes the components of the application — the activities,
services, broadcast receivers, and content providers that the application is
composed of. It names the classes that implement each of the components and
publishes their capabilities (for example, which
Intentmessages they can handle). These declarations let the Android system know what the components are and under what conditions they can be launched. - It determines which processes will host application components.
- It declares which permissions the application must have in order to access protected parts of the API and interact with other applications.
- It also declares the permissions that others are required to have in order to interact with the application's components.
- It lists the
Instrumentationclasses that provide profiling and other information as the application is running. These declarations are present in the manifest only while the application is being developed and tested; they're removed before the application is published. - It declares the minimum level of the Android API that the application requires.
- It lists the libraries that the application must be linked against.



0 comments:
Post a Comment