Chapter 5 Communication Via Network
Chapter 5 Communication Via Network
1 Connecting
2 Disconnected
3 Disconnecting
4 Suspended
5 Unknown
AndroidManifest.xml
<uses-permission android:name=”android.permission.INTERNET”>
</uses-permission>
<uses-permission
android:name=”android.permission.ACCESS_NETWORK_STATE”>
</uses-permission>
Data Fetching using web API
• Lab 3 and https://worldtimeapi.org/
# curl http://worldtimeapi.org/api/timezone/Europe/Amsterdam
{ "abbreviation": "CEST",
"client_ip": "198.16.76.28",
"datetime": "2023-03-31T08:30:07.588830+02:00",
"day_of_week": 5,
"day_of_year": 90,
"dst": true,
"dst_from": "2023-03-26T01:00:00+00:00", "dst_offset": 3600, "dst_until": "2023-10-
29T01:00:00+00:00", "raw_offset": 3600, "timezone": "Europe/Amsterdam", "unixtime":
1680244207, "utc_datetime": "2023-03-31T06:30:07.588830+00:00", "utc_offset": "+02:00",
"week_number": 13 }
JSON
• JSON stands for JavaScript Object Notation
• structured, light weight, human readable and easy to parse.
• best alternative to xml
• shorter, quicker and easier way to interchange data from server
• four different classes to manipulate JSON data. These classes are
JSONObject, JSONArray, JSONStringer and JSONTokenizer
some common components.
1. Array([): In a JSON, square bracket ([) represents a JSONArray.
JSONArray values may be any mix of JSONObjects, other JSONArrays,
Strings, Booleans, Integers, Longs, Doubles, null or NULL. Values may not be
NaNs, infinities, or of any type not listed here.
2. Objects({): In a JSON, curly bracket ({) represents a JSONObject. A
JSONObject represents the data in the form of key and value pair.
JSONObject values may be any mix of other JSONObjects, JSONArrays,
Strings, Booleans, Integers, Longs, Doubles, null or NULL.
If JSON starts from square bracket ([) we use getJSONArray() method and if
it start from curly bracket ({) then we should use the getJSONObject()
method.
Android Telephony
• A telephony application in Android is responsible for voice
communication through the telephone network
• provides information about the device and its details, including the
IMEI and network type
• Telephony used to mean speaking on an analog telephone, but with
the advent of digital phones, it expanded to include voicemail and
video conferencing, as well as video conferencing with multiple
people
android.telephony.TelephonyManager
• TelephonyManager class provides information about the telephony
services such as subscriber id, sim serial number, phone network type
etc
• provided by Android to operate and get information about the
network interfaces and device details
• getSystemService() to create the TelephonyManager object
• TelephonyManager tm=(TelephonyManager)getSystemService(Conte
xt.TELEPHONY_SERVICE);
AndroidManifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
MainActivity.java
String info="Phone Details:\n";
info+="\n IMEI Number:"+IMEINumber;
info+="\n SubscriberID:"+subscriberID;
info+="\n Sim Serial Number:"+SIMSerialNumber;
info+="\n Network Country ISO:"+networkCountryISO;
info+="\n SIM Country ISO:"+SIMCountryISO;
info+="\n Software Version:"+softwareVersion;
info+="\n Voice Mail Number:"+voiceMailNumber;
info+="\n Phone Network Type:"+strphoneType;
info+="\n In Roaming? :"+isRoaming;
Architecture of Android Telephony
• four layers. These four layers help it interact with users and low-level devices like your network
adapters
1. Communication Processor
The communication processor is used to communicate and collect data from various peripherals
2. Radio Interface Layer (RIL)
The Radio Interface Layer is an interface through which the hardware components interact with
the frameworks
3. Framework Services
Framework services consist of various packages and assists the Telephony Manager in directing
all the application API requests to RIL
4. Application
Applications are the last layer of the Telephony architecture. The applications are used directly by
the user to interact with the Telephony Services
Deciding Scope of an App
scope of an app - how long it will take the app development team to design,
build and deliver an application
• a timeline that is set by developers with input from the client or sales team
and project managers
five key steps followed during the scope defining process
1. define the goals of the app
2. identify potential issues or hurdles to overcome
3. decide which resources are needed to achieve the set goals
4. set up a milestone schedule to stay on track
5. list all the important stakeholders that have say in the project
Wireless Connectivity and Mobile Apps
• wireless connectivity between a mobile device and another device
requires a physical layer networking technology
• two types of connectivity to the network: strong and weak.
• Besides enabling communication with the cloud, Android’s wireless
APIs also enable communication with other devices on the same local
network
• This functionality into your application helps you provide a wide range
of features, such as playing games with users in the same room
• transfer data reliably and securely between devices using a
combination of Wi-Fi and Bluetooth,
Performance Memory Management
• Memory management is the hardest facet of mobile development.
Mobile/tablet devices.
• limited amount of dynamic memory compared to our personal computers
• developing app developing need to consider this constraint by freeing the
resources do not need and minimize them not to hinder the user experience.
• If fail to manage app memory resources ,will end up with frozen UI, abrupt
crashes, and dissatisfied users
• will affect other idle background apps
• Memory management requires that the programmer provides ways to
dynamically allocate portions of memory to programs when requested