1

How to write intent to send email in android?

  • Intent email = new Intent(Intent.ACTION_SEND);
    email.setType("message/rfc822");
    email.putExtra(Intent.EXTRA_EMAIL, new String[] {"info@coders-hub.com"});
    email.putExtra(Intent.EXTRA_SUBJECT, "Hi, This is a test mail..");
    startActivity(Intent.createChooser(email, "Choose an Email Client"));
  • Intent email = new Intent(Intent.ACTION_EMAIL);
    email.setType("message/rfc822");
    email.putExtra(Intent.EMAIL, new String[] {"info@coders-hub.com"});
    email.putExtra(Intent.SUBJECT, "Hi, This is a test mail..");
    startActivity(Intent.createChooser(email, "Choose an Email Client"));
  • Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("message/rfc822");
    i.putExtra(Intent.EXTRA_EMAIL , new String[]{"info@coders-hub.com"});
    i.putExtra(Intent.EXTRA_SUBJECT, "test mail");
    i.putExtra(Intent.EXTRA_TEXT , "Did you get this mail? if so please reply back");
    startActivity(Intent.createChooser(i, "Send mail..."));
  • both option 1 and option 3 are correct

Answer: D both option 1 and option 3 are correct

2

What are the functionalities of HTTPClient interface in android?

  • connection management
  • authentication management
  • cookies management
  • all of the above

Answer: D all of the above
Description: connection, authentication, Cookies management are the functionalities of HTTPClient interface.

3

Which of the below options are true about HTTP requests in android applications.

  • i. To fetch some data from a server , then use HTTPGet request.
  • ii. for sending a mail use HTTPPost Request.
  • iii. For updating a blog written on phone, use HTTPGet request.
  • i
  • i & ii
  • i, ii, & iii
  • none

Answer: B i & ii
Description: For posting some data like sending an email content we have to use HTTPPost Request. For getting some data from the server we have to use HTTPGet Request.

4

To use HTTPClient, which permission is required in an android application?

  • android.permission.INTERNET
  • android.permission.FINE_LOCATION
  • android.permission.READ_CONTACTS
  • All of the above

Answer: A android.permission.INTERNET
Description: android.permission.INTERNET is mandatory for any HTTPRequest, as we are fetching or posting information using internet or by using network connection.

5

If internet permission is not taken to use HTTP Client, then what will happen?

  • It will throw run time exception, i.e IOException
  • It will throw compile time exception, i.e IOException
  • It will throw run time exception, i.e CLientProtocolException.
  • It will not compile only.

Answer: A It will throw run time exception, i.e IOException
Description: With out internet permission, it will throw UnknownHostException which is part of IOException.

6

If the URL given in HTTPGet request is not valid then what is the exception that will be thrown, in an android application?

  • It will throw run time exception, i.e IOException
  • It will throw compile time exception, i.e IOException
  • It will throw run time exception, i.e CLientProtocolException.
  • It will not compile only.

Answer: A It will throw run time exception, i.e IOException
Description: If url is wrong then, it will throw UnknownHostException which is part of IOException.

7

What is the use of httpclient class?

  • can execute httprequests (get/post).
  • can execute httprequests(get/post) and returns response from server

Answer: B all of the above
Description: httpclient has a function execute(), which can execute httprequests(get/post) and returns response from server.
eg:
HttpGet get = new HttpGet("http://google.com");
HttpClient c = getDefaultHttpClient();
c.execute(get);

HttpClient can also handle
1. Cookies
2. Authentication
3. Connection management to the server

8

In RESTFUL API What is the difference between httpget() and httppost() methods in android, when to use what?

  • httpget() - use it when we want to get some information from an URL.
  • option 1 is true & httppost() - use it when we want to post some infromation from mobile to a server mentioned by URL
  • httpget() - use it when we want to get some information from a mobile to a server mentioned by an URL.
  • option 3 is true & , httppost() - use it when we want to post some information from a server mentioned by an URL to mobile.

Answer: B option 1 is true & httppost() - use it when we want to post some infromation from mobile to a server mentioned by URL
Description: httpget() - use it when we want to get some information from an URL of a server.
httppost() - use it when we want to post some infromation to a server mentioned by URL from mobile.

eg: Use HttpGet, if you want to get google.com page. Use HttpGet if you want to get all employee details from server.
eg: Use HttpPost, if you want to post some data like posting email to gmail server, or posting a blog to blog server.

9

What does httpclient.execute() return?

  • HttpResponse
  • HttpEntity
  • Boolean - success or failure
  • void

Answer: A HttpResponse
Description: on executing a request (httpget/ httppost), httpclient.execute will return httpresponse which will contain httpentity(which is the actual response from the server).

10

What is the package name of JSONObject, JSONArray.

  • com.android.json
  • org.json
  • net.json
  • com.json

Answer: B org.json
Description:

11

What is the package name of HTTPClient?

  • org.apache.http.client
  • com.android.http.client
  • org.http
  • com.http.client

Answer: A org.apache.http.client
Description:

12

How to read data from an xml file in xml folder of resources, in Android application?

  • Use XMLResource parser to read the resource file, and parse it.
  • Use XMLPullParser to read the resource file, and parse it.
  • We can either use option 1 or option 2 to read xml resource files.
  • Use layoutinflater to inflate xml file and then read the data.

Answer: A Use XMLResource parser to read the resource file, and parse it.
Description: For pulling data from an XML file which is stored in xml folder or resources, then we have to use XMLResourceParser.

Eg: XmlResourceParser xp = getResources().getXml(R.xml.myfile);

13

Which of the below are not an event of XMLPullparser?

  • XMLPullParser.START_DOCUMENT
  • XMLPullParser.START_TAG
  • XMLPullParser.START_TEXT
  • XMLPullParser.END_TAG

Answer: C XMLPullParser.START_TEXT
Description: Below are the available event types available for an xml pull parser.
1. START_DOCUMENT
2.START_TAG
3.TEXT
4.END_TAG
5. END_DOCUMENT.

14

In which library MapView class is located?

  • android.location
  • android.hardware
  • com.google.android.maps
  • none of the above.

Answer: C com.google.android.maps
Description: MapView is not available in default android packages. It is proprietary software of Google which is not included into default android package. If we want to use it then we have to use com.google.android.maps library by selecting Google APIs while creating the project.

Note : MapView is deprecated which is version 1. Latest Android Google maps comes with MapFragment in version 2.

15

If I want to use MapView, what all the steps I have to follow.

  • Use MapActivity with MapView and use library "com.google.android.maps". App should have internet permission as well.
  • along with option 1 , we have to register our application with Google maps service, by providing md5 finger print of the debug certificate of the application.
  • along with option 1 , we have to register our application with Google maps service, by providing md5 finger print of the final digital certificate with which application will be signed.
  • No need to use maps library, it is part of android framework.

Answer: C along with option 1 , we have to register our application with Google maps service, by providing md5 finger print of the final digital certificate with which application will be signed.
Description: Step 1: Use MapActivity with MapView and use library "com.google.android.maps". App should have internet permission as well. Step 2: we have to register our application with Google maps service, by providing md5 finger print of the final digital certificate with which application will be signed.

Note : MapView is deprecated, and not recommended to use. Use MapFragment in place of it.

16

How the result will be sent from a webserver to phone, for a HTTPRequest sent from an android application to a webserver?

  • Result will be sent in the form of HTTPEntity, which is embedded as body in HTTPResponse.
  • HTTPEntity will contain the encoded data that is coming from server to client.
  • Option 2 is true, but option 1 is false. Result will be sent in the form of HTTPResponse, which is embedded as body in HTTPEntity..
  • Both option 1 and 2 are right.

Answer: A Result will be sent in the form of HTTPEntity, which is embedded as body in HTTPResponse.
Description: Result from server will be coming as HTTPResponse, which contains HTTPEntity, which contains encoded data embodied in it.

17

Which of the below technique uses dynamic content refresh with out refreshing the whole page?

  • AJAX
  • only HTML

Answer: A AJAX
Description: AJAX technology uses dynamic content refresh for the webpages. Refreshing the whole page is very heavy and tedious technique, which may irritate the user of that web site.

18

Q1 : How many JSONObjects, & JSONArrays are there in below file.
Q2 : contacts is JSONArray or JSONObject?

{
"contacts": [
{
"id": "p001",
"name": "Mohsin",
"email": " info@coders-hub.com",
"address": "New Delhi",
"gender" : "male",
"phone": {
"mobile": "+91 8527801400",
"home": "080 4164536x",
"office": "080 4144232x"
}
}
]
}
  • 2 json objects, 1 json array. contacts is json array
  • 3 json objects, 1 json array. contacts is json object.
  • 3 json objects, 1 json array. contacts is json array.
  • 2 json objects, 1 json array. contacts is json object.

Answer: C 3 json objects, 1 json array. contacts is json array.
Description: Any thing that starts with { is JSONObject and that starts with [ is JSONArray. So here total 3 objects and 1 array is there.
In the above example contacts is json array as it starts with [

19

JSON : assume that str is string holding below json string, then which of the below code will fetch mobile no of "Mohsin"?

{
 "contacts": [
  {
   "id": "p001",
   "name": "Mohsin",
   "email": " info@coders-hub.com",
   "address": "New Delhi",
   "gender" : "male",
   "phone": {
   "mobile": "+91 8527801400",
   "home": "080 4164536x",
   "office": "080 4144232x"
  }
  }
 ]
}
  • JSONObject root = new JSONObject(str);
    JSONArray arr = root.getJSONArray("contacts");
    String ph = arr.getJSONObject(0).getString("mobile");
  • JSONArray root = new JSONArray (str);
    String ph = arr.getJSONObject(0).getJSONObject("phone").getString("mobile");
  • JSONObject root = new JSONObject(str);
    JSONArray arr = root.getJSONArray("contacts");
    String ph = arr.getJSONObject(0).getJSONObject("phone").getString("mobile");
  • JSONObject root = new JSONObject(str);
    JSONObject obj= root.JSONObject("contacts");
    String ph = obj.getJSONObject("phone").getString("mobile");

Answer: C JSONObject root = new JSONObject(str);
JSONArray arr = root.getJSONArray("contacts");
String ph = arr.getJSONObject(0).getJSONObject("phone").getString("mobile"); Description:

20

JSON : Assume that below json is in string str. How to fetch username of this person?

{
  "id": "676248615",
  "name": "Md Mohsin",
  "first_name": "Md",
  "last_name": "Mohsin",
  "link": "https://www.facebook.com/jmi.mohsin",
  "username": "jmi.mohsin",
  "locale": "en_US"
}
  • JSONObject root = getJSONObject(str);
    String name = root.getString("username");
  • JSONObject root = new JSONObject(str);
    String name = root.getString("username");
  • Since there is no name to this JSON object, it is not possible to fetch data from this kind of JSON strings. These are called as anonymous JSON Objects which don't have name. This is used for security purposes.
  • none of the above are true.

Answer: B JSONObject root = new JSONObject(str);
String name = root.getString("username"); Description: