From 5cdadb48d0e696352c21794861ba533214b06318 Mon Sep 17 00:00:00 2001 From: Scott Main Date: Tue, 5 Nov 2013 18:29:52 -0800 Subject: [PATCH] initial shuffle of the API guide nav to add introduction * revise to the Compatibility doc, put it in Intro * put Permissions in Intro * put App Fundamentals in Intro * move Manifest docs to the top of side nav tree * move App Resources above UI Will perform another fix to the Best Practices section later to deprecate some docs there and point to Training instead Change-Id: I88a8f94167ba15e97eb3bbbc08fd82dd82498e4b --- docs/html/guide/components/fundamentals.jd | 388 ++++++++--------- docs/html/guide/components/index.jd | 2 +- docs/html/guide/guide_toc.cs | 267 +++++------- docs/html/guide/index.jd | 75 ++++ docs/html/guide/practices/compatibility.jd | 485 +++++++++++++--------- docs/html/guide/practices/screens_support.jd | 3 +- docs/html/guide/topics/manifest/manifest-intro.jd | 2 +- docs/html/guide/topics/security/permissions.jd | 72 +++- 8 files changed, 709 insertions(+), 585 deletions(-) create mode 100644 docs/html/guide/index.jd diff --git a/docs/html/guide/components/fundamentals.jd b/docs/html/guide/components/fundamentals.jd index ce50022ad71e..9ac063ea8aff 100644 --- a/docs/html/guide/components/fundamentals.jd +++ b/docs/html/guide/components/fundamentals.jd @@ -4,24 +4,9 @@ page.title=Application Fundamentals
-

Quickview

-
    -
  • Android applications are composed of one or more application components (activities, -services, content providers, and broadcast receivers)
  • -
  • Each component performs a different role in the overall application behavior, and each -one can be activated individually (even by other applications)
  • -
  • The manifest file must declare all components in the application and should also declare -all application requirements, such as the minimum version of Android required and any hardware -configurations required
  • -
  • Non-code application resources (images, strings, layout files, etc.) should include -alternatives for different device configurations (such as different strings for different -languages and different layouts for different screen sizes)
  • -
- -

In this document

    -
  1. Application Components +
  2. App Components
    1. Activating components
    @@ -29,98 +14,91 @@ languages and different layouts for different screen sizes)
  3. The Manifest File
    1. Declaring components
    2. -
    3. Declaring application requirements
    4. +
    5. Declaring app requirements
  4. -
  5. Application Resources
  6. +
  7. App Resources
-

Android applications are written in the Java programming language. The Android SDK tools compile -the code—along with any data and resource files—into an Android package, an -archive file with an {@code .apk} suffix. All the code in a single {@code .apk} file is considered -to be one application and is the file that Android-powered devices use to install the -application.

+

Android apps are written in the Java programming language. The Android SDK tools compile +your code—along with any data and resource files—into an APK: an Android package, +which is an archive file with an {@code .apk} suffix. One APK file contains all the contents +of an Android app and is the file that Android-powered devices use to install the app.

-

Once installed on a device, each Android application lives in its own security sandbox:

+

Once installed on a device, each Android app lives in its own security sandbox:

In this way, the Android system implements the principle of least privilege. That is, -each application, by default, has access only to the components that it requires to do its work and -no more. This creates a very secure environment in which an application cannot access parts of +each app, by default, has access only to the components that it requires to do its work and +no more. This creates a very secure environment in which an app cannot access parts of the system for which it is not given permission.

-

However, there are ways for an application to share data with other applications and for an -application to access system services:

+

However, there are ways for an app to share data with other apps and for an +app to access system services:

-

That covers the basics regarding how an Android application exists within the system. The rest of +

That covers the basics regarding how an Android app exists within the system. The rest of this document introduces you to:

- -

Application Components

+

App Components

-

Application components are the essential building blocks of an Android application. Each -component is a different point through which the system can enter your application. Not all +

App components are the essential building blocks of an Android app. Each +component is a different point through which the system can enter your app. Not all components are actual entry points for the user and some depend on each other, but each one exists as its own entity and plays a specific role—each one is a unique building block that -helps define your application's overall behavior.

+helps define your app's overall behavior.

-

There are four different types of application components. Each type serves a distinct purpose +

There are four different types of app components. Each type serves a distinct purpose and has a distinct lifecycle that defines how the component is created and destroyed.

-

Here are the four types of application components:

+

Here are the four types of app components:

Activities
An activity represents a single screen with a user interface. For example, -an email application might have one activity that shows a list of new +an email app might have one activity that shows a list of new emails, another activity to compose an email, and another activity for reading emails. Although -the activities work together to form a cohesive user experience in the email application, each one -is independent of the others. As such, a different application can start any one of these -activities (if the email application allows it). For example, a camera application can start the -activity in the email application that composes new mail, in order for the user to share a picture. +the activities work together to form a cohesive user experience in the email app, each one +is independent of the others. As such, a different app can start any one of these +activities (if the email app allows it). For example, a camera app can start the +activity in the email app that composes new mail, in order for the user to share a picture.

An activity is implemented as a subclass of {@link android.app.Activity} and you can learn more about it in the Activities @@ -133,7 +111,7 @@ developer guide.

A service is a component that runs in the background to perform long-running operations or to perform work for remote processes. A service does not provide a user interface. For example, a service might play music in the background while -the user is in a different application, or it might fetch data over the network without +the user is in a different app, or it might fetch data over the network without blocking user interaction with an activity. Another component, such as an activity, can start the service and let it run or bind to it in order to interact with it. @@ -145,21 +123,21 @@ guide.

Content providers
-
A content provider manages a shared set of application data. You can store the data in +
A content provider manages a shared set of app data. You can store the data in the file system, an SQLite database, on the web, or any other persistent storage location your -application can access. Through the content provider, other applications can query or even modify +app can access. Through the content provider, other apps can query or even modify the data (if the content provider allows it). For example, the Android system provides a content -provider that manages the user's contact information. As such, any application with the proper +provider that manages the user's contact information. As such, any app with the proper permissions can query part of the content provider (such as {@link android.provider.ContactsContract.Data}) to read and write information about a particular person.

Content providers are also useful for reading and writing data that is private to your -application and not shared. For example, the Note Pad sample application uses a +app and not shared. For example, the Note Pad sample app uses a content provider to save notes.

A content provider is implemented as a subclass of {@link android.content.ContentProvider} -and must implement a standard set of APIs that enable other applications to perform +and must implement a standard set of APIs that enable other apps to perform transactions. For more information, see the Content Providers developer guide.

@@ -171,7 +149,7 @@ guide.

A broadcast receiver is a component that responds to system-wide broadcast announcements. Many broadcasts originate from the system—for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured. -Applications can also initiate broadcasts—for example, to let other applications know that +Apps can also initiate broadcasts—for example, to let other apps know that some data has been downloaded to the device and is available for them to use. Although broadcast receivers don't display a user interface, they may create a status bar notification @@ -188,26 +166,26 @@ see the {@link android.content.BroadcastReceiver} class.

-

A unique aspect of the Android system design is that any application can start another -application’s component. For example, if you want the user to capture a -photo with the device camera, there's probably another application that does that and your -application can use it, instead of developing an activity to capture a photo yourself. You don't -need to incorporate or even link to the code from the camera application. -Instead, you can simply start the activity in the camera application that captures a -photo. When complete, the photo is even returned to your application so you can use it. To the user, -it seems as if the camera is actually a part of your application.

+

A unique aspect of the Android system design is that any app can start another +app’s component. For example, if you want the user to capture a +photo with the device camera, there's probably another app that does that and your +app can use it, instead of developing an activity to capture a photo yourself. You don't +need to incorporate or even link to the code from the camera app. +Instead, you can simply start the activity in the camera app that captures a +photo. When complete, the photo is even returned to your app so you can use it. To the user, +it seems as if the camera is actually a part of your app.

-

When the system starts a component, it starts the process for that application (if it's not +

When the system starts a component, it starts the process for that app (if it's not already running) and instantiates the classes needed for the component. For example, if your -application starts the activity in the camera application that captures a photo, that activity -runs in the process that belongs to the camera application, not in your application's process. -Therefore, unlike applications on most other systems, Android applications don't have a single entry +app starts the activity in the camera app that captures a photo, that activity +runs in the process that belongs to the camera app, not in your app's process. +Therefore, unlike apps on most other systems, Android apps don't have a single entry point (there's no {@code main()} function, for example).

-

Because the system runs each application in a separate process with file permissions that -restrict access to other applications, your application cannot directly activate a component from -another application. The Android system, however, can. So, to activate a component in -another application, you must deliver a message to the system that specifies your intent to +

Because the system runs each app in a separate process with file permissions that +restrict access to other apps, your app cannot directly activate a component from +another app. The Android system, however, can. So, to activate a component in +another app, you must deliver a message to the system that specifies your intent to start a particular component. The system then activates the component for you.

@@ -217,7 +195,7 @@ start a particular component. The system then activates the component for you.intent. Intents bind individual components to each other at runtime (you can think of them as the messengers that request an action from other components), whether the component belongs -to your application or another.

+to your app or another.

An intent is created with an {@link android.content.Intent} object, which defines a message to activate either a specific component or a specific type of component—an intent @@ -273,21 +251,21 @@ href="{@docRoot}guide/topics/providers/content-providers.html">Content Providers

The Manifest File

-

Before the Android system can start an application component, the system must know that the -component exists by reading the application's {@code AndroidManifest.xml} file (the "manifest" -file). Your application must declare all its components in this file, which must be at the root of -the application project directory.

+

Before the Android system can start an app component, the system must know that the +component exists by reading the app's {@code AndroidManifest.xml} file (the "manifest" +file). Your app must declare all its components in this file, which must be at the root of +the app project directory.

-

The manifest does a number of things in addition to declaring the application's components, +

The manifest does a number of things in addition to declaring the app's components, such as:

    -
  • Identify any user permissions the application requires, such as Internet access or +
  • Identify any user permissions the app requires, such as Internet access or read-access to the user's contacts.
  • Declare the minimum API Level -required by the application, based on which APIs the application uses.
  • -
  • Declare hardware and software features used or required by the application, such as a camera, +required by the app, based on which APIs the app uses.
  • +
  • Declare hardware and software features used or required by the app, such as a camera, bluetooth services, or a multitouch screen.
  • -
  • API libraries the application needs to be linked against (other than the Android framework +
  • API libraries the app needs to be linked against (other than the Android framework APIs), such as the Google Maps library.
  • @@ -297,7 +275,7 @@ library.

    Declaring components

    -

    The primary task of the manifest is to inform the system about the application's components. For +

    The primary task of the manifest is to inform the system about the app's components. For example, a manifest file can declare an activity as follows:

    @@ -314,7 +292,7 @@ example, a manifest file can declare an activity as follows: 

    In the <application> element, the {@code android:icon} attribute points to resources for an icon that identifies the -application.

    +app.

    In the <activity> element, @@ -322,7 +300,7 @@ the {@code android:name} attribute specifies the fully qualified class name of t android.app.Activity} subclass and the {@code android:label} attributes specifies a string to use as the user-visible label for the activity.

    -

    You must declare all application components this way:

    +

    You must declare all app components this way:

    • <activity> elements @@ -345,7 +323,7 @@ receivers can be either declared in the manifest or created dynamically in code {@link android.content.BroadcastReceiver} objects) and registered with the system by calling {@link android.content.Context#registerReceiver registerReceiver()}.

      -

      For more about how to structure the manifest file for your application, see For more about how to structure the manifest file for your app, see The AndroidManifest.xml File documentation.

      @@ -356,28 +334,43 @@ documentation.

      As discussed above, in Activating Components, you can use an {@link android.content.Intent} to start activities, services, and broadcast receivers. You can do so by explicitly naming the target component (using the component class name) in the intent. However, -the real power of intents lies in the concept of intent actions. With intent actions, you simply -describe the type of action you want to perform (and optionally, the data upon which you’d like to +the real power of intents lies in the concept of implicit intents. An implicit intent +simply describe the type of action to perform (and optionally, the data upon which you’d like to perform the action) and allow the system to find a component on the device that can perform the action and start it. If there are multiple components that can perform the action described by the intent, then the user selects which one to use.

      The way the system identifies the components that can respond to an intent is by comparing the -intent received to the intent filters provided in the manifest file of other applications on +intent received to the intent filters provided in the manifest file of other apps on the device.

      -

      When you declare a component in your application's manifest, you can optionally include -intent filters that declare the capabilities of the component so it can respond to intents -from other applications. You can declare an intent filter for your component by +

      When you declare an activity in your app's manifest, you can optionally include +intent filters that declare the capabilities of the activity so it can respond to intents +from other apps. You can declare an intent filter for your component by adding an {@code <intent-filter>} element as a child of the component's declaration element.

      -

      For example, an email application with an activity for composing a new email might declare an -intent filter in its manifest entry to respond to "send" intents (in order to send email). An -activity in your application can then create an intent with the “send” action ({@link -android.content.Intent#ACTION_SEND}), which the system matches to the email application’s “send” -activity and launches it when you invoke the intent with {@link android.app.Activity#startActivity -startActivity()}.

      +

      For example, if you've built an email app with an activity for composing a new email, you can +declare an intent filter to respond to "send" intents (in order to send a new email) like this:

      +
      +<manifest ... >
      +    ...
      +    <application ... >
      +        <activity android:name="com.example.project.ComposeEmailActivity">
      +            <intent-filter>
      +                <action android:name="android.intent.action.SEND" />
      +                <data android:type="*/*" />
      +                <category android:name="android.intent.category.DEFAULT" />
      +            </intent-filter>
      +        </activity>
      +    </application>
      +</manifest>
      +
      + +

      Then, if another app creates an intent with the {@link +android.content.Intent#ACTION_SEND} action and pass it to {@link android.app.Activity#startActivity +startActivity()}, the system may start your activity so the user can draft and send an +email.

      For more about creating intent filters, see the Intents and Intent Filters document. @@ -385,102 +378,57 @@ href="{@docRoot}guide/components/intents-filters.html">Intents and Intent Filter -

      Declaring application requirements

      +

      Declaring app requirements

      There are a variety of devices powered by Android and not all of them provide the -same features and capabilities. In order to prevent your application from being installed on devices -that lack features needed by your application, it's important that you clearly define a profile for -the types of devices your application supports by declaring device and software requirements in your +same features and capabilities. In order to prevent your app from being installed on devices +that lack features needed by your app, it's important that you clearly define a profile for +the types of devices your app supports by declaring device and software requirements in your manifest file. Most of these declarations are informational only and the system does not read them, but external services such as Google Play do read them in order to provide filtering -for users when they search for applications from their device.

      - -

      For example, if your application requires a camera and uses APIs introduced in Android 2.1 (API Level 7), you should declare these as -requirements in your manifest file. That way, devices that do not have a camera and have an -Android version lower than 2.1 cannot install your application from Google Play.

      +for users when they search for apps from their device.

      -

      However, you can also declare that your application uses the camera, but does not -require it. In that case, your application must perform a check at runtime to determine -if the device has a camera and disable any features that use the camera if one is not available.

      +

      For example, if your app requires a camera and uses APIs introduced in Android 2.1 (API Level 7), +you should declare these as requirements in your manifest file like this:

      -

      Here are some of the important device characteristics that you should consider as you design and -develop your application:

      - -
      -
      Screen size and density
      -
      In order to categorize devices by their screen type, Android defines two characteristics for -each device: screen size (the physical dimensions of the screen) and screen density (the physical -density of the pixels on the screen, or dpi—dots per inch). To simplify all the different -types of screen configurations, the Android system generalizes them into select groups that make -them easier to target. -

      The screen sizes are: small, normal, large, and extra large.
      -The screen densities are: low density, medium density, high density, and extra high density.

      - -

      By default, your application is compatible with all screen sizes and densities, -because the Android system makes the appropriate adjustments to your UI layout and image -resources. However, you should create specialized layouts for certain screen sizes and provide -specialized images for certain densities, using alternative layout resources, and by declaring in -your manifest exactly which screen sizes your application supports with the {@code -<supports-screens>} element.

      -

      For more information, see the Supporting Multiple Screens -document.

      - -
      Input configurations
      -
      Many devices provide a different type of user input mechanism, such as a hardware keyboard, a -trackball, or a five-way navigation pad. If your application requires a particular kind of input -hardware, then you should declare it in your manifest with the {@code -<uses-configuration>} element. However, it is rare that an application should require -a certain input configuration.
      - -
      Device features
      -
      There are many hardware and software features that may or may not exist on a given -Android-powered device, such as a camera, a light sensor, bluetooth, a certain -version of OpenGL, or the fidelity of the touchscreen. You should never assume that a certain -feature is available on all Android-powered devices (other than the availability of the standard -Android library), so you should declare any features used by your application with the {@code <uses-feature>} -element.
      - -
      Platform Version
      -
      Different Android-powered devices often run different versions of the Android platform, -such as Android 1.6 or Android 2.3. Each successive version often includes additional APIs not -available in the previous version. In order to indicate which set of APIs are available, each -platform version specifies an API Level (for example, Android 1.0 is API Level -1 and Android 2.3 is API Level 9). If you use any APIs that were added to the platform after -version 1.0, you should declare the minimum API Level in which those APIs were introduced using the -{@code <uses-sdk>} -element.
      -
      - -

      It's important that you declare all such requirements for your application, because, when you -distribute your application on Google Play, the store uses these declarations to filter which -applications are available on each device. As such, your application should be available only to -devices that meet all your application requirements.

      - -

      For more information about how Google Play filters applications based on these (and other) -requirements, see the Filters on Google Play +

      +<manifest ... >
      +    <uses-feature android:name="android.hardware.camera.any"
      +                  android:required="true" />
      +    <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="19" />
      +    ...
      +</manifest>
      +
      + +

      Now, devices that do not have a camera and have an +Android version lower than 2.1 cannot install your app from Google Play.

      + +

      However, you can also declare that your app uses the camera, but does not +require it. In that case, your app must set the {@code required} +attribute to {@code "false"} and check at runtime whether +the device has a camera and disable any camera features as appropriate.

      + +

      More information about how you can manage your app's compatibility with different devices +is provided in the Device Compatibility document.

      -

      Application Resources

      +

      App Resources

      -

      An Android application is composed of more than just code—it requires resources that are +

      An Android app is composed of more than just code—it requires resources that are separate from the source code, such as images, audio files, and anything relating to the visual -presentation of the application. For example, you should define animations, menus, styles, colors, -and the layout of activity user interfaces with XML files. Using application resources makes it easy -to update various characteristics of your application without modifying code and—by providing -sets of alternative resources—enables you to optimize your application for a variety of +presentation of the app. For example, you should define animations, menus, styles, colors, +and the layout of activity user interfaces with XML files. Using app resources makes it easy +to update various characteristics of your app without modifying code and—by providing +sets of alternative resources—enables you to optimize your app for a variety of device configurations (such as different languages and screen sizes).

      For every resource that you include in your Android project, the SDK build tools define a unique -integer ID, which you can use to reference the resource from your application code or from -other resources defined in XML. For example, if your application contains an image file named {@code +integer ID, which you can use to reference the resource from your app code or from +other resources defined in XML. For example, if your app contains an image file named {@code logo.png} (saved in the {@code res/drawable/} directory), the SDK tools generate a resource ID named {@code R.drawable.logo}, which you can use to reference the image and insert it in your user interface.

      @@ -504,15 +452,45 @@ depending on the orientation, you can define two different layouts and apply the qualifier to each layout's directory name. Then, the system automatically applies the appropriate layout depending on the current device orientation.

      -

      For more about the different kinds of resources you can include in your application and how -to create alternative resources for various device configurations, see the Application Resources developer guide.

      - - - diff --git a/docs/html/guide/components/index.jd b/docs/html/guide/components/index.jd index 87bae53bf22a..37fb7e98e63c 100644 --- a/docs/html/guide/components/index.jd +++ b/docs/html/guide/components/index.jd @@ -1,6 +1,6 @@ page.title=App Components page.landing=true -page.landing.intro=Android's application framework lets you create extremely rich and innovative apps using a set of reusable components. This section explains how Android apps work and how you use components to build them. +page.landing.intro=Android's application framework lets you create rich and innovative apps using a set of reusable components. This section explains how you can build the components that define the building blocks of your app and how to connect them together using intents. page.landing.image=images/develop/app_components.png @jd:body diff --git a/docs/html/guide/guide_toc.cs b/docs/html/guide/guide_toc.cs index 6a2b1ba023cb..18b234eb2be8 100644 --- a/docs/html/guide/guide_toc.cs +++ b/docs/html/guide/guide_toc.cs @@ -6,17 +6,41 @@ localized titles are added in the language order specified below. ?>
    • +
    • + Processes and Threads + +
    • +
    + + + + + + + + + +
- - - - - diff --git a/docs/html/guide/index.jd b/docs/html/guide/index.jd new file mode 100644 index 000000000000..d78a1b11e943 --- /dev/null +++ b/docs/html/guide/index.jd @@ -0,0 +1,75 @@ +page.title=Introduction to Android + +@jd:body + + + + +

Android provides a rich application framework that allows you to build innovative apps and games +for mobile devices in a Java language environment. The documents listed in the left +navigation provide details about how to build apps using Android's various APIs.

+ +

If you're new to Android development, it's important that you understand +the following fundamental concepts about the Android app framework:

+ + +
+ +
+ +

Apps provide multiple entry points

+ +

Android apps are built as a combination of distinct components that can be invoked +individually. For instance, an individual activity provides a single +screen for a user interface, and a service independently performs +work in the background.

+ +

From one component you can start another component using an intent. You can even start +a component in a different app, such an activity in a maps app to show an address. This model +provides multiple entry points for a single app and allows any app to behave as a user's "default" +for an action that other apps may invoke.

+ + +

Learn more:

+ + +
+ + +
+ +

Apps adapt to different devices

+ +

Android provides an adaptive app framework that allows you to provide unique resources +for different device configurations. For example, you can create different XML +layout files for different screen sizes and the system +determines which layout to apply based on the current device's screen size.

+ +

You can query the availability of device features at runtime if any app features require +specific hardware such as a camera. If necessary, you can also declare features your app requires +so app markets such as Google Play Store do not allow installation on devices that do not support +that feature.

+ + +

Learn more:

+ + +
+ +
+ + + diff --git a/docs/html/guide/practices/compatibility.jd b/docs/html/guide/practices/compatibility.jd index 9e3d4613cdba..db1642e8aaca 100644 --- a/docs/html/guide/practices/compatibility.jd +++ b/docs/html/guide/practices/compatibility.jd @@ -1,248 +1,333 @@ -page.title=Android Compatibility +page.title=Device Compatibility excludeFromSuggestions=true @jd:body -

Android is designed to run on many different types of devices. For -developers, the range and number of devices means a huge potential audience: the -more devices that run Android apps, the more users who can access your app. In -exchange, however, it also means that your apps will have to cope with that same -variety of hardware.

+

Android is designed to run on many different types of devices, from phones +to tablets and televisions. As a developer, +the range of devices provides a huge potential audience for your app. In order for your app +to be successful on all these devices, it should tolerate some feature variability +and provide a flexible user interface that adapts to different screen +configurations.

+ +

To facilitate your effort toward that goal, Android provides a dynamic app framework in which +you can provide configuration-specific app resources in static files (such as different XML layouts +for different screen sizes). Android then loads the appropriate resources based on +the current device configuration. So with some forethought to your app design and some additional +app resources, you can publish a single application package (APK) that provides an optimized user +experience on a variety of devices. -

Fortunately, Android has built-in tools and support that make it easy for -your apps to do that, while at the same time letting you maintain control of -what types of devices your app is available to. With a bit of forethought and -some minor changes in your app's manifest file, you can ensure that users -whose devices can’t run your app will never see it on Google Play, and -will not get in trouble by downloading it. This page explains how you can -control which devices have access to your apps, and how to prepare your apps to -make sure they reach the right audience.

+

If necessary, however, you can specify your app's feature requirements and control +which types of devices can install your app from Google Play Store. This page explains how you can +control which devices have access to your apps, and how to prepare your apps to make sure they +reach the right audience. For more information about how you can make your app adapt +to different devices, read Supporting Different Devices.

-

What does “compatibility” mean?

-

A device is “Android compatible” if it can correctly run apps written for the +

What Does "Compatibility" Mean?

+ +

As you read more about Android development, you'll probably encounter the term "compatibility" +in various situations. There are two types of compatibility: device compatibility +and app compatibility. + +

Because Android is an open source project, any hardware manufacturer can build a device +that runs the Android operating system. Yet, a device is "Android compatible" only if +it can correctly run apps written for the Android execution environment. The exact details of the Android execution -environment are defined by the Android Compatibility Definition Document, -but the single most important characteristic of a compatible device is the -ability to install and correctly run an Android .apk file.

+environment are defined by the Android compatibility program and each device must pass the Compatibility +Test Suite (CTS) in order to be considered compatible.

-

There is exactly one Android API for each API level, and it’s the same -API no matter what kind of device it’s installed on. No parts of the API are -optional, and you never have to worry about parts of the API missing on some -devices. Every compatible Android device your app will land on will include -every class and every API for that API level.

+

As an app developer, you don't need to worry about whether a device is Android compatible, because +only devices that are Android compatible include Google Play Store. So you can rest assured that +users who install your app from Google Play Store are using an Android compatible device.

-

Of course, some APIs won’t work correctly if a particular device lacks the -corresponding hardware or feature. But that’s not a problem: we also designed -Android to prevent apps from being visible to devices which don’t have features -the apps require. We’ve built support for this right into the SDK tools, and -it’s part of the Android platform itself, as well as part of Google Play.

-

As a developer, you have complete control of how and where your apps are -available. Android provides tools as a first-class part of the platform that let -you manage this. You control the availability of your apps, so that they reach -only the devices capable of running them.

+

However, you do need to consider whether your app is compatible with each potential +device configuration. Because Android runs on a wide range of device configurations, some features are not +available on all devices. For example, some devices may not include a +compass sensor. If your app's core functionality requires the use +of a compass sensor, then your app is compatible only with devices that +include a compass sensor.

-

How does it work?

-

You manage your app’s availability through a simple three-step process:

-
    -
  1. You state the features your app requires by declaring <uses-feature> -elements its manifest file.
  2. -
  3. Devices are required to declare the features they include to Google -Play.
  4. -
  5. Google Play uses your app’s stated requirements to filter it from devices -that don’t meet those requirements.
  6. -
-

This way, users never even see apps that won’t work properly on their -devices. As long as you accurately describe your app’s requirements, you don’t -need to worry about users blaming you for compatibility problems.

- -

If you’re familiar with web development, you may recognize this model as -“capability detection”. Web developers typically prefer this approach to -“browser detection”, because it’s very difficult to keep up as new browsers and -new versions of current browsers are released. By checking for support for -specific required capabilities instead of the current browser, web developers -get better fine-grained control. That’s the same approach Android uses: since -it’s impossible to keep up with all the Android devices being released, you -instead use the fine-grained controls Android provides.

- -

Filtering for technical reasons

- - +

Controlling Your App's Availability to Devices

+ +

Android supports a variety of features your app can leverage through platform APIs. Some +features are hardware-based (such as a compass sensor), some are software-based (such as app +widgets), and some are dependent on the platform version. Not every device supports every feature, +so you may need to control your app's availability to devices based on your app's required +features.

-

Android includes support for a lot of features, some hardware and some -software. Examples include compass and accelerometer sensors, cameras, and Live -Wallpapers. However, not every device will support every feature. For instance, -some devices don’t have the hardware horsepower to display Live Wallpapers -well.

- -

To manage this, Android defines feature IDs. Every capability has a -corresponding feature ID defined by the Android platform. For instance, the -feature ID for compass is “android.hardware.sensor.compass”, -while the feature -ID for Live Wallpapers is “android.software.live_wallpapers”. Each of these IDs -also has a corresponding Java-language constant on the -{@link android.content.pm.PackageManager} class that you can use to query whether -feature is supported at runtime. As Android adds support for new features in -future versions, new feature IDs will be added as well.

- -

When you write your application, you specify which features your app requires -by listing their feature IDs in <uses-feature> elements in -the AndroidManifest.xml file. This is the information that Google -Play uses to match your app to devices that can run it. For instance, if you -state that your app requires android.software.live_wallpapers, it won’t be shown -to devices that don’t support Live Wallpapers.

- -

This puts you in total control of your app — because you don’t have to -declare these features. Consider an example involving cameras.

- -

If you’re building a really impressive next-generation augmented-reality app, -your app won’t function at all without a camera. However, if you’re building a -shopping app that only uses the camera for barcode scanning, users without -cameras might still find it useful even if they can’t scan barcodes. While both -apps need to acquire the permission to access the camera, only the first app -needs to state that it requires a camera. (The shopping app can simply check at -runtime and disable the camera-related features if there’s no camera -present.)

- -

Since only you can say what the best approach is for your app, Android -provides the tools and lets you make your own tradeoff between maximizing -audience size and minimizing development costs.

- - -

Filtering for business reasons

- -

It’s possible that you may need to restrict your app’s availability for -business or legal reasons. For instance, an app that displays train schedules -for the London Underground is unlikely to be useful to users outside the United -Kingdom. Other apps might not be permitted in certain countries for business or -legal reasons. For cases such as these, Google Play itself provides -developers with filtering options that allow them control their app’s -availability for non-technical reasons.

-

The help information for Google Play provides full details, but in a -nutshell, developers can use the Google Play publisher UI to:

+

To achieve the largest user-base possible for your app, you should strive to support as many +device configurations as possible using a single APK. In most situations, you can do so by +disabling optional features at runtime and providing app resources +with alternatives for different configurations (such as different layouts for different +screen sizes). +If necessary, however, you can restrict your app's availability to devices through Google Play +Store based on the following device characteristics:

-

Filtering for technical compatibility (such as required hardware components) -is always based on information contained within your .apk file. But -filtering for non-technical reasons (such as geographic restrictions) is always -handled in the Google Play user interface.

-

Future-proofing

+

Device features

+ +

In order for you to manage your app’s availability based on device features, +Android defines feature IDs for any hardware or software feature +that may not be available on all devices. For instance, the +feature ID for the compass sensor is {@link +android.content.pm.PackageManager#FEATURE_SENSOR_COMPASS} and the feature ID for app widgets +is {@link android.content.pm.PackageManager#FEATURE_APP_WIDGETS}.

+ +

If necessary, you can prevent users from installing your app when their devices don't provide a +given feature by declaring it with a {@code <uses-feature>} +element in your app's manifest +file.

+ +

For example, if your app does not make sense on a device that lacks a compass sensor, +you can declare the compass sensor as required with the following manifest tag:

+ +
+<manifest ... >
+    <uses-feature android:name="android.hardware.sensor.compass"
+                  android:required="true" />
+    ...
+</manifest>
+
+ +

Google Play Store compares the features your app requires to the features available on +each user's device to determine whether your app is compatible with each device. +If the device does not provide all the features your app requires, the user cannot install +your app.

+ +

However, if your app's primary functionality does not require +a device feature, you should set the {@code required} +attribute to {@code "false"} and check +for the device feature at runtime. If the app feature is not available on the current device, +gracefully degrade the corresponding app feature. For example, you can query whether +a feature is available by calling +{@link android.content.pm.PackageManager#hasSystemFeature hasSystemFeature()} like this:

+ +
+PackageManager pm = getPackageManager();
+if (!pm.hasSystemFeature(PackageManager.FEATURE_SENSOR_COMPASS)) {
+    // This device does not have a compass, turn off the compass feature
+    disableCompassFeature();
+}
+
+ +

For information about all the filters you can +use to control the availability of your app to users through Google Play Store, see the +Filters on Google Play +document.

+ +

Note: Some system permissions implicitly require the +availability of a device feature. For example, if your app requests permission to access to {@link +android.Manifest.permission#BLUETOOTH}, this implicitly requires the {@link +android.content.pm.PackageManager#FEATURE_BLUETOOTH} device feature. You can disable filtering based +on this feature and make your app available to devices without Bluetooth by setting the {@code required} attribute +to {@code "false"} in the {@code <uses-feature>} tag. +For more information about implicitly required device features, read Permissions that Imply +Feature Requirements.

+ + + + + + + +

Platform version

+ +

Different devices may run different versions of the Android platform, +such as Android 4.0 or Android 4.4. Each successive platform version often adds new APIs not +available in the previous version. To indicate which set of APIs are available, each +platform version specifies an API level. For instance, +Android 1.0 is API level 1 and Android 4.4 is API level 19.

+ +

The API level allows you to declare the minimum version with which your app is +compatible, using the {@code +<uses-sdk>} manifest tag and its {@code minSdkVersion} attribute.

+ +

For example, the Calendar +Provider APIs were added in Android 4.0 (API level 14). If your app cannot function without +these APIs, you should declare API level 14 as your app's minimum supported +version like this:

-

There’s one additional quirk that we haven’t yet addressed: protecting apps -from changes made to future versions of Android. If the Android platform -introduces a new feature or changes how existing features are handled, what -happens to existing apps that were written without any knowledge of the new -behavior?

+
+<manifest ... >
+    <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19" />
+    ...
+</manifest>
+
-

Simply put, Android commits to not making existing apps available to devices -where they won’t work properly, even when the platform changes. The best way to -explain this is through examples, so here are two:

+

The {@code +minSdkVersion} attribute declares the minimum version with which your app is compatible +and the {@code +targetSdkVersion} attribute declares the highest version on which you've optimized +your app.

+ +

Each successive version of Android provides compatibility for apps that were built using +the APIs from previous platform versions, so your app should always be compitible with future +versions of Android while using the documented Android APIs.

+ +

Note: +The {@code +targetSdkVersion} attribute does not prevent your app from being installed on platform +versions that are higher than the specified value, +but it is important because it indicates to the system whether your +app should inherit behavior changes in newer versions. If you don't update the +{@code +targetSdkVersion} to the latest version, the system assumes that your +app requires some backward-compatibility behaviors when running on the latest version. +For example, among the behavior changes in Android 4.4, alarms created with the {@link android.app.AlarmManager} APIs +are now inexact by default so the system can batch app alarms and preserve system power, +but the system will retain the previous API behavior for your app if your target API level +is lower than "19".

+ +

However, if your app uses APIs added in a more recent +platform version, but does not require them for its primary functionality, +you should check the API level at runtime and gracefully degrade +the corresponding features when the API level is too low. In this case, +set the {@code +minSdkVersion} to the lowest value possible for your app's primary functionality, +then compare the current system's version, {@link android.os.Build.VERSION#SDK_INT}, to one the +codename constants in {@link android.os.Build.VERSION_CODES} that corresponds to the +API level you want to check. For example:

+ +
+if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
+    // Running on something older than API level 11, so disable
+    // the drag/drop features that use {@link android.content.ClipboardManager} APIs
+    disableDragAndDrop();
+}
+
+ + + + + + +

Screen configuration

+ +

Android runs on devices of various sizes, from phones to tablets and TVs. +In order to categorize devices by their screen type, Android defines two characteristics for +each device: screen size (the physical size of the screen) and screen density (the physical +density of the pixels on the screen, known as DPI). +To simplify the different configurations, Android generalizes these variants into groups that make +them easier to target:

    -
  • Android 1.0 through 1.5 required a 2 megapixel camera with auto-focus. -However, with version 1.6, Android devices were permitted to omit the auto-focus -capability, though a (fixed-focus) camera was still required. Some apps such as -barcode scanners do not function as well with cameras that do not auto-focus. To -prevent users from having a bad experience with those apps, existing apps that -obtain permission to use the Camera were assumed by default to require -auto-focus. This allowed Google Play to filter those apps from devices that -lack auto-focus.
  • - -
  • Android 2.2, meanwhile, allowed the microphone to be optional on some -devices, such as set-top boxes. Android 2.2 included a new feature ID for the -microphone which allows developers to filter their apps if necessary, but -— as with camera — apps that obtain permission to record audio are -assumed to require the microphone feature by default. If your app can use a -microphone but doesn’t strictly need it, you can explicitly state that you don’t -require it; but unless you do that, your app won’t be shown to devices without -microphones.
  • +
  • Four generalized sizes: small, normal, large, and xlarge.
  • +
  • And several generalized densities: mdpi (medium), hdpi (hdpi), xhdpi (extra high), + xxhdpi (extra-extra high), and others.
-

In other words, whenever Android introduces new features or changes existing -ones, we will always take steps to protect existing applications so that they -don’t end up being available to devices where they won’t work.

+

By default, your app is compatible with all screen sizes and densities, +because the system makes the appropriate adjustments to your UI layout and image +resources as necessary for each screen. However, you should optimize the user experience for each +screen configuration by adding specialized layouts for different screen sizes and +optimized bitmap images for common screen densities.

+ +

For information about how to create alternative resources for different screens +and how to restrict your app to certain screen sizes when necessary, read Supporting Different Screens. +

+ + -

This is implemented, in part, using the aapt tool in the SDK. -To see which features your app explicitly requires or is implicitly assumed to -require, you can use the command aapt dump badging.

-

Conclusion

-

The goal of Android is to create a huge installed base for developers to take -advantage of. One of the ways we will achieve this is through different kinds of -hardware running the same software environment. But we also recognize that only -developers know which kinds of devices their apps make sense on. We’ve built in -tools to the SDK and set up policies and requirements to ensure that developers -remain in control of their apps, today and in the future. With the information -you just read, and the resources listed in the sidebar of this document, you -can publish your app with the confidence that only users who can run it will -see it.

-

For more information about Android device compatibility, please visit:

-

http://source.android.com/compatibility/index.html

+

Controlling Your App's Availability for Business Reasons

- \ No newline at end of file +

In addition to restricting your app's availability based on device characteristics, +it’s possible you may need to restrict your app’s availability for +business or legal reasons. For instance, an app that displays train schedules +for the London Underground is unlikely to be useful to users outside the United +Kingdom. For this type of situation, Google Play Store provides +filtering options in the developer console that allow you to control your app’s +availability for non-technical reasons such as the user's locale or wireless carrier.

+ +

Filtering for technical compatibility (such as required hardware components) +is always based on information contained within your APK file. But +filtering for non-technical reasons (such as geographic locale) is always +handled in the Google Play developer console.

+ + + + + + +
+
+

Continue reading about:

+
+
Providing Resources
+
Information about how Android apps are structured to separate app resources from the + app code, including how you can provide alternative resources for specific device + configurations. +
+
Filters on Google Play
+
Information about the different ways that Google Play Store can prevent your app + from being installed on different devices.
+
+
+
+

You might also be interested in:

+
+
System Permissions
+
How Android restricts app access to certain APIs with a permission system that requires + the user's consent for your app to use those APIs.
+
+
+
diff --git a/docs/html/guide/practices/screens_support.jd b/docs/html/guide/practices/screens_support.jd index ca29589b4204..8c76411bed28 100644 --- a/docs/html/guide/practices/screens_support.jd +++ b/docs/html/guide/practices/screens_support.jd @@ -25,8 +25,7 @@ page.title=Supporting Multiple Screens
  • Using configuration qualifiers
  • Designing alternative layouts and drawables
  • -
  • Declaring Tablet Layouts for Android 3.2 new! +
  • Declaring Tablet Layouts for Android 3.2
    1. Using new size qualifiers
    2. Configuration examples
    3. diff --git a/docs/html/guide/topics/manifest/manifest-intro.jd b/docs/html/guide/topics/manifest/manifest-intro.jd index d25a51335c24..76fe2a27f983 100644 --- a/docs/html/guide/topics/manifest/manifest-intro.jd +++ b/docs/html/guide/topics/manifest/manifest-intro.jd @@ -1,4 +1,4 @@ -page.title=The AndroidManifest.xml File +page.title=App Manifest @jd:body
      diff --git a/docs/html/guide/topics/security/permissions.jd b/docs/html/guide/topics/security/permissions.jd index 4ad9b7c9273c..6f919da1f195 100644 --- a/docs/html/guide/topics/security/permissions.jd +++ b/docs/html/guide/topics/security/permissions.jd @@ -1,4 +1,4 @@ -page.title=Permissions +page.title=System Permissions @jd:body
      @@ -20,10 +20,6 @@ page.title=Permissions
    -

    This document describes how application developers can use the -security features provided by Android. A more general Android Security -Overview is provided in the Android Open Source Project.

    Android is a privilege-separated operating system, in which each application runs with a distinct system identity (Linux user ID and group @@ -33,7 +29,13 @@ Linux thereby isolates applications from each other and from the system.

    Additional finer-grained security features are provided through a "permission" mechanism that enforces restrictions on the specific operations that a particular process can perform, and per-URI permissions for granting -ad-hoc access to specific pieces of data.

    +ad hoc access to specific pieces of data.

    + +

    This document describes how application developers can use the +security features provided by Android. A more general Android Security +Overview is provided in the Android Open Source Project.

    +

    Security Architecture

    @@ -42,10 +44,10 @@ ad-hoc access to specific pieces of data.

    application, by default, has permission to perform any operations that would adversely impact other applications, the operating system, or the user. This includes reading or writing the user's private data (such as contacts or -e-mails), reading or writing another application's files, performing -network access, keeping the device awake, etc.

    +emails), reading or writing another application's files, performing +network access, keeping the device awake, and so on.

    -

    Because Android sandboxes applications from each other, applications +

    Because each Android application operates in a process sandbox, applications must explicitly share resources and data. They do this by declaring the permissions they need for additional capabilities not provided by the basic sandbox. Applications statically declare the permissions they @@ -65,10 +67,10 @@ other.

    Application Signing

    -

    All Android applications (.apk files) must be signed with a certificate +

    All APKs ({@code .apk} files) must be signed with a certificate whose private key is held by their developer. This certificate identifies the author of the application. The certificate does not need to be -signed by a certificate authority: it is perfectly allowable, and typical, +signed by a certificate authority; it is perfectly allowable, and typical, for Android applications to use self-signed certificates. The purpose of certificates in Android is to distinguish application authors. This allows the system to grant or deny applications access to

    Because security enforcement happens at the -process level, the code of any two packages can not normally +process level, the code of any two packages cannot normally run in the same process, since they need to run as different Linux users. You can use the {@link android.R.attr#sharedUserId} attribute in the AndroidManifest.xml's @@ -114,7 +116,7 @@ been set appropriately so any other application can see it.

    Using Permissions

    A basic Android application has no permissions associated with it by default, -meaning it can not do anything that would adversely impact the user experience +meaning it cannot do anything that would adversely impact the user experience or any data on the device. To make use of protected features of the device, you must include in your AndroidManifest.xml one or more {@link android.R.styleable#AndroidManifestUsesPermission <uses-permission>} @@ -133,9 +135,9 @@ specify:

    granted to it by the package installer, based on checks against the signatures of the applications declaring those permissions and/or interaction with the user. No checks with the user -are done while an application is running: it either was granted a particular +are done while an application is running; the app is either granted a particular permission when installed, and can use that feature as desired, or the -permission was not granted and any attempt to use the feature will fail +permission is not granted and any attempt to use the feature fails without prompting the user.

    Often times a permission failure will result in a {@link @@ -146,6 +148,12 @@ being delivered to each receiver, after the method call has returned, so you will not receive an exception if there are permission failures. In almost all cases, however, a permission failure will be printed to the system log.

    +

    However, in a normal user situation (such as when the app is installed +from Google Play Store), an app cannot be installed if the user does not grant the app +each of the requested permissions. So you generally don't need to worry about runtime failures +caused by missing permissions because the mere fact that the app is installed at all +means that your app has been granted its desired permissions.

    +

    The permissions provided by the Android system can be found at {@link android.Manifest.permission}. Any application may also define and enforce its own permissions, so this is not a comprehensive list of all possible @@ -433,3 +441,37 @@ android:grantUriPermissions} attribute or {@link android.content.Context#checkUriPermission Context.checkUriPermission()} methods.

    + + + + +
    +
    +

    Continue reading about:

    +
    +
    Permissions that Imply Feature Requirements
    +
    Information about how requesting some permissions will implicitly restrict your app + to devices that include the corresponding hardware or software feature.
    +
    {@code + <uses-permission>}
    +
    API reference for the manifest tag that declare's your app's required system permissions. +
    +
    {@link android.Manifest.permission}
    +
    API reference for all system permissions.
    +
    +
    +
    +

    You might also be interested in:

    +
    +
    Device Compatibility
    +
    Information about Android works on different types of devices and an introduction + to how you can optimize your app for each device or restrict your app's availability + to different devices.
    +
    Android Security Overview
    +
    A detailed discussion about the Android platform's security model.
    +
    +
    +
    -- 2.11.0