Professional Documents
Culture Documents
Android lets your application connect to the internet or any other local network and allows you
to perform network operations.
A device can have various types of network connections. This chapter focuses on using either a
Wi-Fi or a mobile network connection.
Sr.No State
1 Connecting
2 Disconnected
3 Disconnecting
4 Suspended
5 Unknown
InputStream is = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
String webPage = "",data="";
1
disconnect()
This method releases this connection so that its resources may be either reused
or closed
2
getRequestMethod()
This method returns the request method which will be used to make the request
to the remote HTTP server
3
getResponseCode()
This method returns response code returned by the remote HTTP server
4
setRequestMethod(String method)
This method Sets the request command which will be sent to the remote HTTP
server
5
usingProxy()
This method returns whether this connection uses a proxy server or not
CONNECTING TO REST
REST stands for REpresentational State Transfer. Restful Web Service, expose
API from your application in a secure, uniform, stateless manner to the calling
client.
REST architecture will be useful to build client/server network applications. REST
represents Representational State Transfer. Implementing REST is very simple compared to
other methods like SOAP, CORBA, WSDL etc., It basically works on HTTP protocol.
Following are the list of things should be considered while building a REST api.
» HTTP Methods
A well-designed RESTful API should support most commonly used HTTP methods (GET,
POST, PUT and DELETE). There are other HTTP methods like OPTIONS, HEAD but these are
used most often. Each method should be used depending on the type of operation you are
performing.
GET
To fetch a resource
POST
PUT
To delete a resource
SOAP refers to the Simple Object Access Protocol and is an XML-based web service
protocol for exchanging data or documents over HTTP (Hypertext transfer protocol) or SMTP
(Simple Message Transfer Protocol). It allows separate processes on different platforms to
communicate with one another.
Advantages of SOAP
SOAP is the protocol used for data interchange between applications. Below are some of
the reasons as to why SOAP is used.
When developing SOAP based Web services, you need to have some of language which
can be used for web services to talk with client applications.
SOAP is a light-weight protocol that is used for data interchange between applications.
Note the keyword ‘light.’
SOAP is designed to be platform independent and is also designed to be operating system
independent. So the SOAP protocol can work any programming language based
applications on both Windows and Linux platform.
It works on the HTTP protocol –SOAP works on the HTTP protocol, which is the default
protocol used by all web applications. SOAP Building Blocks
The SOAP specification defines something known as a “SOAP message” which is what is sent
to the web service and the client application.
SOAP architecture
SOAP Message Building Blocks
The SOAP message is nothing but a mere XML document which has the below components.
An Envelope element that identifies the XML document as a SOAP message – This is the
containing part of the SOAP message and is used to encapsulate all the details in the
SOAP message. This is the root element in the SOAP message.
A Header element that contains header information – The header element can contain
information such as authentication credentials which can be used by the calling
application.
It can also contain the definition of complex types which could be used in the SOAP
message. By default, the SOAP message can contain parameters which could be of
simple types such as strings and numbers, but can also be a complex object type.
BROADCAST RECEIVER
Broadcast in android is the system-wide events that can occur when the device starts,
when a message is received on the device or when incoming calls are received, or when a
device goes to airplane mode, etc.
Broadcast Receivers are used to respond to these system-wide events.
Broadcast Receivers allow us to register for the system and application events, and
when that event happens, then the register receivers get notified. There are mainly two types of
Broadcast Receivers:
Static Broadcast Receivers: These types of Receivers are declared in the manifest file and
works even if the app is closed.
Dynamic Broadcast Receivers: These types of receivers work only if the app is active or
minimized.
Local Broadcast Manager is used to register and send a broadcast of intents to local
objects in your process. It has lots of advantages:
1. You broadcasting data will not leave your app. So, if there is some leakage in your app
then you need not worry about that.
2. Another thing that can be noted here is that other applications can’t send any kind of
broadcasts to your app. So, you need not worry about security holes.
To use LocalBroadcastReceiver, all you need to do is create an instance of
LocalBroadcastManager, then send the broadcast and finally receive the broadcast. So, firstly,
create an instance of the LocalBroadcastManager:
var localBroadcastManager = LocalBroadcastManager.getInstance(context)
Now, by using the sendBroadcast() method, you can send the broadcast as below:
val localIntent = Intent("YOUR_ACTION")
.putExtra("DATA", "MindOrks")
localBroadcastManager.sendBroadcast(localIntent)
Our final task is to receive the broadcast using the onReceive() method on
MyBroadCastReceiver. You can perform the desired action after receiving the broadcast in
the onReceive() method as below:
private val listener = MyBroadcastReceiver()
}
}
DYNAMIC BROADCAST RECEIVER IN ANDROID
Report this ad
1. Communication Processor
2. Radio Interface Layer (RIL)
3. Framework Services
4. Applications
Let us try to understand them briefly one by one :
1. Communication Processor
It is an input/output processor to distribute and collect data from a number of remote terminals. It
is a specialized processor designed to communicate with the data communication network.
RIL Daemon– It starts when the android system starts. It reads the system properties to find
a library that is to be used for Vendor RIL.
Vendor RIL– It is also known as RIL Driver. It can be understood as a library that is
specific to each modem.
3. Framework Services
The telephony Framework starts and initializes along with the system. All the queries by
Application API are directed to RIL using these services.
4. Application
These are the Application UI related to telephony such as Dialer, SMS, MMS, Call tracker, etc.
These applications start with the android system boot up. These are tied with framework services
of telephony.