Chapter 5 Defining the Manifest

Similar documents
Android permissions Defining and using permissions Component permissions and related APIs

RUNTIME PERMISSIONS IN ANDROID 6.0 Lecture 10a

Configuring the Android Manifest File

Android System Architecture. Android Application Fundamentals. Applications in Android. Apps in the Android OS. Program Model 8/31/2015

Introduction To Android

Permissions. Lecture 18

Android. Operating System and Architecture. Android. Screens. Main features

Android Overview. Most of the material in this section comes from

Introduction to Android

CS 403X Mobile and Ubiquitous Computing Lecture 3: Introduction to Android Programming Emmanuel Agu

EMBEDDED SYSTEMS PROGRAMMING Application Basics

Multiple Activities. Many apps have multiple activities

Security Philosophy. Humans have difficulty understanding risk

How to support multiple screens using android? Synopsis

Mobile Application Development - Android

Intents and Intent Filters

Diving into Android. By Jeroen Tietema. Jeroen Tietema,

PAPER ON ANDROID ESWAR COLLEGE OF ENGINEERING SUBMITTED BY:

XML Tutorial. NOTE: This course is for basic concepts of XML in line with our existing Android Studio project.

Java & Android. Java Fundamentals. Madis Pink 2016 Tartu

Intents & Intent Filters. codeandroid.org

Programming Concepts and Skills. Creating an Android Project

Fig. 2.2 New Android Application dialog. 2.3 Creating an App 41

Lecture 08. Android Permissions Demystified. Adrienne Porter Felt, Erika Chin, Steve Hanna, Dawn Song, David Wagner. Operating Systems Practical

CS 193A. Multiple Activities and Intents

Android App Development. Muhammad Sharjeel COMSATS Institute of Information Technology, Lahore

Android Fundamentals - Part 1

Android Development Tutorial. Yi Huang

SHWETANK KUMAR GUPTA Only For Education Purpose

Login with Amazon. Getting Started Guide for Android apps

Android ATC Android Security Essentials Course Code: AND-402 version 5 Hands on Guide to Android Security Principles

Understand applications and their components. activity service broadcast receiver content provider intent AndroidManifest.xml

Midterm Examination. CSCE 4623 (Fall 2017) October 20, 2017

VMware AirWatch Software Development Kit (SDK) Plugin v1.1 for Xamarin

Mobile Application Development Android

BlackBerry Developer Global Tour. Android. Table of Contents

6.858 Quiz 2 Review. Android Security. Haogang Chen Nov 24, 2014

ATC Android Application Development

VMware AirWatch Android SDK Technical Implementation Guide Empowering your enterprise applications with MDM capabilities using

INTRODUCTION TO ANDROID

M.C.A. Semester V Subject: - Mobile Computing (650003) Week : 2

LECTURE NOTES OF APPLICATION ACTIVITIES

Overview. Android Apps (Partner s App) Other Partner s App Platform. Samsung Health. Server SDK. Samsung Health. Samsung Health Server

12 Publishing Android Applications

Introduction to Android Android Smartphone Programming. Outline University of Freiburg. What is Android? Background University of Freiburg.

VMware AirWatch SDK Plugin for Xamarin Instructions Add AirWatch Functionality to Enterprise Applicataions with SDK Plugins

CS378 -Mobile Computing. Intents

Introduction to Android Development

Android. Mobile operating system developed by Google A complete stack. Based on the Linux kernel Open source under the Apache 2 license

This document providesanoverview ofthestepsrequired to implement an android app which will call the ACH android SDK.

Security model. Marco Ronchetti Università degli Studi di Trento

VMware AirWatch SDK Plugin for Xamarin Instructions Add AirWatch Functionality to Enterprise Applicataions with SDK Plugins

Getting Started. Dr. Miguel A. Labrador Department of Computer Science & Engineering

Produced by. Mobile Application Development. Eamonn de Leastar David Drohan

Mobile Application Workbench. SAP Mobile Platform 3.0 SP02

Android. Lesson 1. Introduction. Android Developer Fundamentals. Android Developer Fundamentals. to Android 1

Getting Started With Android Feature Flags

CMSC 436 Lab 10. App Widgets and Supporting Different Devices

EMBEDDED SYSTEMS PROGRAMMING Android Services

UNDERSTANDING ACTIVITIES

Android" Application Development SAMS. Sams Teach Yourself. Shane Conder. Lauren Darcey. Second Edition

Android Application Development. By : Shibaji Debnath

Google Maps Troubleshooting

Getting started: Installing IDE and SDK. Marco Ronchetti Università degli Studi di Trento

Pro Android 2. Sayed Y. Hashimi Satya Komatineni Dave Mac Lean. Apress

Android Market For Developers. Eric Chu (Android Developer Ecosystem)

Use the API or contact customer service to provide us with the following: General ios Android App Name (friendly one-word name)

Syllabus- Java + Android. Java Fundamentals

VMware AirWatch Android SDK Technical Implementation Guide Empowering your enterprise applications with MDM capabilities using

Oracle Database. Installation and Configuration of Real Application Security Administration (RASADM) Prerequisites

Safety First - Android sicher programmieren! Benjamin Reimold & Stephan Linzner

Mobile Development Lecture 8: Intents and Animation

User Interface Design & Development

CSCU9YH Development with Android

Real Application Security Administration

8/30/15 MOBILE COMPUTING. CSE 40814/60814 Fall How many of you. have implemented a command-line user interface?

Android Security Lab WS 2013/14 Lab 2: Android Permission System

MAD ASSIGNMENT NO 3. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

Android Application Development using Kotlin

1. Implementation of Inheritance with objects, methods. 2. Implementing Interface in a simple java class. 3. To create java class with polymorphism

ANDROID APPS (NOW WITH JELLY BEANS!) Jordan Jozwiak November 11, 2012

Android Online Training

Intents. Repo:

Group B: Assignment No 8. Title of Assignment: To verify the operating system name and version of Mobile devices.

stolen from Intents and Intent Filters

SD Module-1 Android Dvelopment

Mobile Programming Lecture 5. Composite Views, Activities, Intents and Filters

Required Core Java for Android application development

Android. (XKE Mars 2009) Erwan Alliaume.

Android & iphone. Amir Eibagi. Localization

CHAPTER 1: HELLO, ANDROID 1

Introduction to Android

CS 528 Mobile and Ubiquitous Computing Lecture 2a: Android UI Design in XML + Examples. Emmanuel Agu

Android Exam AND-401 Android Application Development Version: 7.0 [ Total Questions: 129 ]

CS Android. Vitaly Shmatikov

EMBEDDED SYSTEMS PROGRAMMING UI and Android

ANDROID SYLLABUS. Advanced Android

COSC 3P97 Mobile Computing

Android Camera. Alexander Nelson October 6, University of Arkansas - Department of Computer Science and Computer Engineering

Lecture 2 Android SDK

Transcription:

Introduction to Android Application Development, Android Essentials, Fifth Edition Chapter 5 Defining the Manifest

Chapter 5 Overview Use the Android manifest file for configuring Android applications Manage the application s name and icon with the Android manifest file Enforce application system requirements by targeting specific devices Register activities in the Android manifest Work with permissions Explore additional manifest file settings

Configuring Android Applications Using the Android Manifest What is the Android manifest file? Specially formatted XML file required for each Android application Defines application name Defines components the application relies on Defines permissions the application requires to run Named AndroidManifest.xml

Configuring the Android Manifest AndroidManifest.xml information is used by the Android system to Install and upgrade the application package Display the application s name, description, and icon to users Specify application system requirements Device configurations required (e.g., D-pad navigation) Platform features relied upon (e.g., multitouch) Specify features required by the application for market filtering Register application activities and when they should be launched Manage application permissions Configure and define services, broadcast receivers, and content providers Specify intent filters for activities, services, and broadcast receivers Enable application settings and configurations

Editing the Android Manifest File Use Android Studio to manually edit the manifest XML. Android manifest files include a single <manifest> tag with a single <application> tag.

Editing the Manifest File Manually Here is a summary of what this file tells us about the SimpleHardware application: The package name is com.introtoandroid.simplehardware. The application name is stored in the resource string @string/app_name within the res/values/strings.xml resource file. The application icon is the file called ic_launcher found in the /res/mipmap-* directory. The application has four activities. SimpleHardwareActivity is the primary entry point. Requires the following permission: battery stats. Uses the following device features: accelerometer, barometer, compass, gyroscope, light, proximity, stepcounter, and stepdetector.

Managing Your Application s Identity <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.introtoandroid.simplehardware" >

Setting the Application Name and Icon Overall application settings are configured with the <application> tag of the Android manifest file. Here, you set information such as the application icon (android:icon) and friendly name (android:label). These settings are attributes of the <application> tag. You can also set optional application settings as attributes in the <application> tag: android:description android:debuggable="true"

Setting the Application Name and Icon (Cont d) <application android:icon="@mipmap/ic_launcher" android:label="@string/app_name" >

Enforcing Application System Requirements System requirements can be defined and enforced in the Android manifest file. When an application is installed on a device, the Android platform checks these requirements and will error out if necessary. The Google Play store uses information in the Android manifest file to filter which applications to offer to which devices so that users install applications that work on their devices.

Enforcing Application System Requirements (Cont d) Developers can configure some application system requirements in the manifest: Android SDK versions supported Platform features used Hardware configurations required Screen sizes and pixel densities supported External libraries

Enforcing Application Platform Requirements Android devices have different hardware and software configurations: Some have built-in keyboards. Others rely on the software keyboard. Some support the latest 3D graphics libraries. Others provide little or no graphics support. The Android manifest file has several informational tags for flagging the system features and hardware configurations supported or required by an Android application.

Specifying Supported Input Methods <uses-configuration> For specifying hardware and software input methods There are different configuration attributes for five-way navigation: Hardware keyboard and keyboard types Directional pad Trackball Wheel Touchscreen settings There is no OR support! What if you want to support many input configurations? Define multiple <uses-configuration> tags

Specifying Supported Input Methods (Cont d) <uses-configuration android:reqhardkeyboard="true" android:reqtouchscreen="finger" /> <uses-configuration android:reqhardkeyboard="true" android:reqtouchscreen="stylus" />

Specifying Required Device Features The <uses-feature> tag is used to specify features your application needs to run properly. These settings are for informational purposes only. Android does not enforce these settings. Publication channels such as Google Play use this information to filter the applications available to a given user. Other applications might check this information as well.

Specifying Required Device Features (Cont d) <uses-feature android:name="android.hardware.sensor.light" /> <uses-feature android:name="android.hardware.sensor.proximity" />

Specifying Required Device Features (Cont d) One common reason to use the <uses-feature> tag: It specifies the OpenGL ES versions supported. All applications function with OpenGL ES 1.0 by default. However, if your app requires features available in later versions of OpenGL ES (such as 2.0), you must specify this feature. Do this with the android:glesversion attribute of <uses-feature>. Specify the lowest version of OpenGL ES that the application requires.

Specifying Supported Screen Sizes Android devices come in many shapes and sizes. Screen sizes and pixel densities vary. The <supports-screens> tag can be used to specify the types of screens supported. Android categorizes screen types in terms of: Sizes Small, normal, large, and xlarge Pixel density LDPI, MDPI, HDPI, XHDPI, XXHDPI, and XXXHDPI Or, rather, low-, medium-, high-, extra-high-, extraextra-high-, and extra-extra-extra-high density displays

Specifying Supported Screen Sizes (Cont d) <supports-screens android:resizable= false android:smallscreens= true android:normalscreens= true android:largescreens= false android:xlargescreens= false android:compatiblewidthlimitdp= 320 android:anydensity= true />

Working with External Libraries You can register shared libraries your application links to within the Android manifest file. Every application is linked to the standard Android packages (such as android.app) and is aware of its own package. However, if your application links to additional packages, register them within the <application> tag using <uses-library>.

Working with External Libraries (Cont d) <uses-library android:name="com.sharedlibrary.sharedstuff" />

Other Application Configuration Settings and Filters <supports-gl-texture> This tag is used to specify the GL texture compression format supported. It is used by applications that use the graphics libraries and are intended to be compatible only with devices that support a specific compression format. <compatible-screens> This tag is used solely by the Google Play store to restrict installation of your application to devices with specific screen sizes. It is not checked by Android and usage is discouraged unless you absolutely need to restrict the installation to certain devices.

Registering Activities in the Android Manifest Each Activity within the application must be defined with an <activity> tag. The following XML excerpt registers an Activity class called SensorsActivity: <activity android:name= SensorsActivity" /> This Activity must be defined as a class within the application package, in this case: com.introtoandroid.simplehardware

Designating an Entry Point Activity Using an Intent Filter You can designate an Activity class as the primary entry point. Just configure an intent filter, such as <intentfilter>, with the following options: MAIN action type The LAUNCHER category

Designating an Entry Point Activity Using an Intent Filter (Cont d) <activity android:name=".simplehardwareactivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.main"/> <category android:name="android.intent.category.launcher"/> </intent-filter> </activity>

Configuring Other Intent Filters Android uses intent filters to resolve implicit intents, that is, intents that do not have a specific Activity or other component to launch. Intent filters can be applied to activities, services, and broadcast receivers. An intent filter declares that this component is capable of handling or processing a specific type of Intent when it matches the filter s criteria. Different applications have the same types of intent filters and are able to process the same types of requests.

Configuring Other Intent Filters (Cont d) <intent-filter> <action android:name="android.intent.action.view"/> <category android:name="android.intent.category.browsable"/> <category android:name="android.intent.category.default" /> <data android:scheme="geoname"/> </intent-filter>

Registering Other Application Components All application components must be defined within the Android manifest file. In addition to activities, all services and broadcast receivers must be registered within the Android manifest file. Services are registered using the <service> tag. Broadcast receivers are registered using the <receiver> tag. Content providers are registered using the <provider> tag. Services and broadcast receivers use intent filters. If your application acts as a content provider, it must declare this capability using the <provider> tag.

Working with Permissions Android has been locked down so that applications have limited capability to adversely affect operations outside their process space. Instead, Android applications run within the bubble of their own virtual machine: With their own Linux user account And related permissions

Registering Permissions Your Application Requires Android applications have no permissions by default. Instead, permissions for shared resources or privileged access whether it s shared data, such as the Contacts database, or access to underlying hardware, such as the built-in camera must be explicitly registered within the Android manifest file.

Registering Permissions Your Application Requires (Cont d) For devices running versions of Android prior to Marshmallow 6.0 API Level 23, these permissions are granted when the application is installed. For devices running Android Marshmallow 6.0 API Level 23 and newer, permissions with a level of PROTECTION_NORMAL, and some with PROTECTION_SIGNATURE, are granted at installation. Those permissions with a PROTECTION_DANGEROUS must be requested and verified at runtime.

Registering Permissions Your Application Requires (Cont d) <uses-permission android:name= android.permission.read_contacts /> <uses-permission android:name="android.permission.write_contacts"/>

Requesting Permissions at Runtime Android Marshmallow introduced a new permission model allowing users to install your application and to accept your application s permissions once interaction occurs with the features that require them. This new permission model is important because it reduces the amount of friction permissions may have caused in the past, such as users abandoning the installation of your application because they are not comfortable accepting a particular permission.

Requesting Permissions at Runtime (Cont d) With the Android Marshmallow permission model, users do not need to grant permissions prior to installing, allowing them to install and start interacting with your application. Once users come across a feature that requires a particular permission, they are presented with a dialog requesting them to grant the permission. If the permission is granted, the system notifies the application and permission is then granted to the users. If the permission is not granted, the users will not be able to access the particular functional area of your application that requires the denied permission. Permissions are declared as normal with the <usespermission> tag in the Android manifest file.

Requesting Permissions at Runtime (Cont d) Your application s code is where you check to see if the permission has been granted. This permission model allows users to revoke access to particular permissions in the application settings, without having to uninstall your application. Even if users grant a particular permission, they are able to revoke permissions at anytime, so your application must always check if a particular permission is granted, and if not, make a request for the permission.

Requesting Permissions at Runtime (Cont d) compile 'com.android.support:support-v4:23.0.0' compile 'com.android.support:appcompat-v7:23.0.0'

Requesting Permissions at Runtime (Cont d) public class PermissionsActivity extends AppCompatActivity implements ActivityCompat.OnRequestPermissionsResultCallback { } // Activity code here

Requesting Permissions at Runtime (Cont d) if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS)!= PackageManager.PERMISSION_GRANTED ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_CONTACTS)!= PackageManager.PERMISSION_GRANTED) { Log.i(DEBUG_TAG, "Contact permissions not granted. Requesting permissions."); ActivityCompat.requestPermissions(GridListMenuActivity.this, { Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS}, 0); } else { Log.i(DEBUG_TAG, "Contact permissions granted. Displaying contacts."); // Do work here }

Requesting Permissions at Runtime (Cont d) @Override public void onrequestpermissionsresult(int requestcode, @NonNull String[] permissions, @NonNull int[] grantresults) { if (requestcode == REQUEST_CONTACTS) { Log.d(DEBUG_TAG, "Received response for contact permissions request."); // All Contact permissions must be checked if (verifypermissions(grantresults)) { // All required permissions granted, proceed as usual Log.d(DEBUG_TAG, "Contacts permissions were granted."); Toast.makeText(this, "Contacts Permission Granted", Toast.LENGTH_SHORT).show(); } else { Log.d(DEBUG_TAG, "Contacts permissions were denied."); Toast.makeText(this, "Contacts Permission Denied", Toast.LENGTH_SHORT).show(); } } else { super.onrequestpermissionsresult(requestcode, permissions, grantresults); } }

Registering Permissions Your Application Enforces Applications can also define and enforce their own permissions via the <permission> tag. These are used by other applications. Permissions must be described and then applied to specific application components, such as activities using the android:permission attribute.

Registering Permissions Your Application Enforces (Cont d) Permissions can be enforced at several points: When starting an Activity or Service When accessing data provided by a content provider At the method call level When sending or receiving broadcasts by an Intent

Registering Permissions Your Application Enforces (Cont d) Permissions can have three primary protection levels: normal, dangerous, and signature. Normal is a good default for fine-grained permission enforcement within the application. Dangerous is used for higher-risk activities. Signature permits any application signed with the same certificate to use that component for controlled application interoperability.

Registering Permissions Your Application Enforces (Cont d) Permissions can be broken down into categories: Permission groups, which describe or warn why specific activities require permission Permissions might be applied for activities that Expose sensitive user data such as location and personal information android.permission-group.location and android.permission-group.personal_info Access underlying hardware android.permission-group.hardware_controls Perform operations that might incur fees to the user android.permission-group.cost_money A complete list of permission groups is available within the Manifest.permission_group class.

Exploring Other Manifest File Settings Some other features you can configure: Setting application-wide themes using the <application> tag attributes Configuring unit-testing features using the <instrumentation> tag Aliasing activities using the <activity-alias> tag Creating broadcast receivers using the <receiver> tag Creating content providers using the <provider> tag Managing content provider permissions using the <grant-uri-permission> and <path-permission> tags Including other data within your Activity, Service, or receiver component registrations with the <meta-data> tag

Chapter 5 Summary We have learned how to use the Android manifest file for configuring Android applications. We have learned how to manage the application s name and icon with the Android manifest file. We are now able to enforce application system requirements by targeting specific devices. We covered registering activities in the Android manifest. We should now be able to work with permissions as well as additional manifest file settings.

References and More Information Android Developers Guide: The AndroidManifest.xml File : http://d.android.com/guide/topics/manifest/manifest-intro.html Android Developers Guide: Supporting Multiple Screens : http://d.android.com/guide/practices/screens_support.html Android Developers Guide: Security Tips: Using Permissions : http://d.android.com/training/articles/securitytips.html#permissions Android Google Services: Filters on Google Play : http://d.android.com/google/play/filters.html Android Preview: Permissions : http://d.android.com/preview/features/runtimepermissions.html