Professional Documents
Culture Documents
MOBILE PROGRAMMING
LECTURE 5
To maintain security for the system and users, Android requires apps to
request permission before the apps can use certain system data and
features.
Depending on how sensitive the area is, the system may grant the
permission automatically, or it may ask the user to approve the request.
Note: These permissions are Android permissions; they grant access to
device features.
Requesting Permissions
3
Depending on how sensitive the area is, the system may grant the
permission automatically, or may prompt the user to approve or reject the
request.
A basic Android app has no permissions associated with it by default.
It cannot do anything that would adversely impact the user experience or
any data on the device.
Requesting Permissions
5
Eg.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.app.myapp" >
<uses-permission android:name="android.permission.RECEIVE_SMS" />
...
</manifest>
Normal and Dangerous Permissions
6
Normal Permissions:
Cover areas where your app needs to access data or resources outside the app's
sandbox,
But where there's very little risk to the user's privacy or the operation of other
apps.
Normal and Dangerous Permissions
7
Dangerous permissions
Cover areas where the app wants data or resources that involve the user's
private information,
Or could potentially affect the user's stored data or the operation of other
apps.
Eg. Reading users contact information is a dangerous permission
Both sending and receiving broadcasts, to control who can receive your
broadcast or who can send a broadcast to you.
When accessing and operating on a content provider.
Binding to or starting a service.
Permission Groups
10
…
User Interface Design Overview
UI Overview
12
All user interface elements in an app are built using View &
ViewGroup objects
View: object that draws something on the screen that the use
interacts with
Buttons, text fields, Checkboxes, RadioButtons etc
UI Overview
13
Either of:
Instantiate view object with java code
Define layout in XML file (Recommended and easy way)
Declaring or Instantiating a Layout
16
You don’t have to built all your UI using View and ViewGroup
Android provides several app components that offer a standard UI
layout
Each have unique set of APIs
Eg:
App Bar
Dialogs and Notifications etc
Layouts
21
The android system gives you the flexibility to use either of this
Layouts
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a TextView" />
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a Button" />
</LinearLayout>
Loading XML Resource
26
You should load the layout resource from your application code
In your Activity.onCreate() callback implementation.
Do so by calling setContentView(), passing in the reference to your
layout resource in the form of: R.layout.layout_file_name.
Loading XML Resource
27
Yo
n k
h a