QUESTION 1(10 Marks)
Q1a.Explain the following methods of ContentProvider class [5]
(Note: Full marks is awarded if methods parameters and return type is explained.)
Answer)
i.canonicalize(Uri url):
Answer)
QUESTION 2(10 Marks)
QUESTION 2a )Applications require various types of permission to be effective. Listed below are 5 permissions. Please indicate why each of these permissions would be required by the application giving an example of an application from your experience [5]
i)Receive text messages (android.permission.RECEIVE_SMS)
ii)install shortcuts (com.android.launcher.permission.INSTALL_SHORTCUT)
iii)precise (GPS) location (android.permission.ACCESS_FINE_LOCATION)
iv)Take pictures or videos (android.permission.CAMERA)
v)read phone status and identity (android.permission.READ_PHONE_STATE)
Answer)
Nowadays many android apps installs a shortcut on home screen when you install the app and run it for the first time. This is a nice strategy to engage user by compiling them to use your app. Most of times when a user install an app, the app is deep buried in list of apps making it almost difficult to discover. So its always a good idea to make a shortcut right on home screen.
Android provide us an intent class com.android.launcher.action.INSTALL_SHORTCUT which can be used to add shortcuts to home screen. In following code snippet we create a shortcut of activity MainActivity with the name HelloWorldShortcut.
QUESTION 2b)Indicate the code (androin.permission.xxxxxx) you would set for the following requirements : [5]
i)The application need permission to vibrate your phone to notify you of a new message.
Answer)“android.permission.VIBRATE”
To vibrate your phone when you have new incoming messages or calls.
ii)Provide permission to diagnose your network connection and have the app react accordingly to ensure you get your messages.
Answer)android.permission.ACCESS_NETWORK_STATE”
To diagnose network connection and have the app react accordingly to ensure you get the messages on time.
iii)We need this to make sure that when a friend sends you a file, it doesn't get broken by your phone going to sleep.
Answer)“android.permission.WAKE_LOCK”
To make sure the phone does not go to sleep while you are using Wire during certain situations, for example calling or recording audio-/video clips.
iv)We use this to add a WhatsApp account to your device to show your WhatsAppable contacts
Answer)Add or remove accounts (android.permission.MANAGE_ACCOUNTS)
Explanation: We use this to add a WhatsApp account to your device to show your WhatsAppable contacts. Permission: create accounts and set passwords (android.permission.AUTHENTICATE_ACCOUNTS)
v)We use this permission to allow you to record Voice Notes to send to your friends.
Answer)Microphone - “android.permission.RECORD_AUDIO”
To call and record audio messages.
QUESTION 3(20 Marks)
Case Study for ONLINE TEST APPLICATION.
(Even if you can answer parts of this question you will be given due credit for effort)
The Proposed App aims to be User centric. After registration, user can log in and can start the test upon selecting the subject. Each question will be given one minute. User has to answer the test within the time and after submission, correct answers will be shown. If the user doesn’t give the answer within specified time then next question will appear. Also user can view his/her previous results but administrator can view the results of all the users. Actual Users are the students, by logging in they can play quiz. Admin task is to add more questions and to keep track of previous as well as current results of quiz.
The Modules have been described as follows:
1. Login Module: In this module, user has to first register. User will be moved to Register activity after clicking register button on Login screen. User has to fill details like Username, Email-id, Mobile number, Password and Confirm Password Etc. Only registered user can play quiz by logging in.
2. Admin module: If the user log in as an Admin then user can add new questions by selecting a particular area and a subject related to that area or make any changes to database. Admin can display result of all users, datewise or name wise as the case may be.
3. Registration for new User: If the user wants to play quiz, first user must register by filling details like User name,Emailid,Password,Confirm Password etc. After successful Registration, user can login. After login, user can Play the quiz.
4. Results view: This module is used to display previous as well as current scores of users. By viewing the results, user can measure performance compared to last attempts
Please answer the following questions:
a. Divide the project into modules and show their relationship. [3]
b. Design a layout for the Login Screen and Registration Screen. Clearly indicate the type of layout you have used and why. [3]
c. Write the AndroidManifest.xml code for this application. Assume you have only two activity LoginActivity and RegisterActivity. [4]
d. Write out the code for activity_login.xml. Clearly bring out the layout manager which should reflect the answer you have given to (b) above. The following phrases must appear in your answer: android:orientation=" "; android:layout_width=" "; android:layout_height=" "; match_parent; wrap_content; @id/header; fill_parent; android:layout_marginTop=""; android:layout_marginBottom=""; android:textColor="#0b84aa"/> [5]
e. Write the code for LoginActivity.java and RegisterActivity.java. Appropriate packages are to be imported. Please assure that you create the following code in your answer: [5]
LoginActivity.java
// setting default screen to login.xml
// Listening to register new account link
// Switching to Register screen
RegisterActivity.java
// Set View to register.xml
// Listening to Login Screen link
// Closing registration screen
// Switching to Login Screen/closing register screen
Answer)
Switching from Registration screen to Login screen
LoginActivity.java file
package com.androidhive.loginandregister;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class LoginActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setting default screen to login.xml
setContentView(R.layout.login);
TextView registerScreen = (TextView) findViewById(R.id.link_to_register);
// Listening to register new account link
registerScreen.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Switching to Register screen
Intent i = new Intent(getApplicationContext(), RegisterActivity.class);
startActivity(i);
}
});
}
}
Open your RegisterActivity.java and modify your code to following. To switch back to login screen just call finish(). It will close the registration screen, so login screen will be shown:
RegisterActivity.java file
package com.androidhive.loginandregister;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class RegisterActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set View to register.xml
setContentView(R.layout.register);
TextView loginScreen = (TextView) findViewById(R.id.link_to_login);
// Listening to Login Screen link
loginScreen.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// Closing registration screen
// Switching to Login Screen/closing register screen
finish();
}
});
}
}
QUESTION 4(10 Marks)
QUESTION 4a)You are invited for the newly opened Wipro office in Bangalore. You have just arrived to Bangalore airport. You are searching the route for this new office on your android phone. You have traced the route on Google Map app and have started your navigation. But somewhere during your journey you lost route just because GPS has lost the connection. But after some time the GPS connection is recovered. You now realized that this has happened just because the GPS has re-registered your phone [1+1+3=5]
a.You need to find you current location. Write a code snippet for it.
b.How do you set the zoom to tightest beyond which user cannot zoom out?
c.How to set the library and internet permission in Androidmenifest.xml file?
QUESTION 4b)Write a code to create a SQLiteDatabase and display success message on UI? [5]
Q1a.Explain the following methods of ContentProvider class [5]
(Note: Full marks is awarded if methods parameters and return type is explained.)
Answer)
i.canonicalize(Uri url):
- A canonical URI is one that can be transported across devices, backup/restore, and other contexts, and still be able to refer to the same data item. Typically this is implemented by adding query params to the URI allowing the content provider to verify that an incoming canonical URI references the same data as it was originally intended for and, if it doesn't, to find that data (if it exists) in the current environment.
- Parameters Url: uri: the Uri to canonicalize. this value must never be null
- Returns : URI Return the canonical representation of url, or null if canonicalization of that Uri is not supported.
- Implement this to handle requests to delete one or more rows. The implementation should apply the selection clause when performing deletion, allowing the operation to affect multiple rows in a directory. As a courtesy, call notifyChange() after deleting. This method can be called from multiple threads, as described in Processes and Threads.
- The implementation is responsible for parsing out a row ID at the end of the URI, if a specific row is being deleted. That is, the client would pass in
- Parameters
- uri Uri: The full URI to query, including a row ID (if a specific record is requested).This value must never be null.
- selection String: An optional restriction to apply to rows when deleting.This value may be null.
- selectionArgs String .This value may be null.
- Returns
- int The number of rows affected.
iii.getCallingPackage():
- Return the package name of the caller that initiated the request being processed on the current thread. The returned package will have been verified to belong to the calling UID. Returns null if not currently processing a request.
- This will always return null when processing getType(Uri) or getStreamTypes(Uri, String) requests.
- Returns :String.This value may be null.
- Throws SecurityException: if the calling package doesn't belong to the calling UID.
iv.getContext():
- Context getContext ()
- Retrieves the Context this provider is running in. Only available once onCreate() has been called -- this will return null in the constructor.
- Return :Context.This value may be null.
v.bulkInsert(Uri uri, ContentValues[] values):
- int bulkInsert (Uri uri, ContentValues[] values)
- Override this to handle requests to insert a set of new rows, or the default implementation will iterate over the values and call insert(Uri, ContentValues) on each of them. As a courtesy, call notifyChange() after inserting. This method can be called from multiple threads, as described in Processes and Threads.
- Parameters
- Uri: The content:// URI of the insertion request.This value must never be null.
- ContentValues: An array of sets of column_name/value pairs to add to the database. This must not be null.
- Returns
- int The number of values that were inserted.
QUESTION 1b.Explain Content URI with respect to Content Provider.
Answer)
- A content URI is a URI that identifies data in a provider. Content URIs include the symbolic name of the entire provider (its authority) and a name that points to a table (a path). When you call a client method to access a table in a provider, the content URI for the table is one of the arguments.
- In the preceding lines of code, the constant CONTENT_URI contains the content URI of the user dictionary's "words" table. The ContentResolver object parses out the URI's authority, and uses it to "resolve" the provider by comparing the authority to a system table of known providers. TheContentResolver can then dispatch the query arguments to the correct provider.
- The ContentProvider uses the path part of the content URI to choose the table to access. A provider usually has a path for each table it exposes.
- Many providers allow you to access a single row in a table by appending an ID value to the end of the URI. For example, to retrieve a row whose _ID is 4from user dictionary, you can use this content URI:
- Uri singleUri = ContentUris.withAppendedId(UserDictionary.Words.CONTENT_URI,4);
- You often use id values when you've retrieved a set of rows and then want to update or delete one of them.
QUESTION 1c.How do you create content provider? [2]
QUESTION 1d.Provide the list of methods which you need to override in content provider class? [2]Answer)
QUESTION 2(10 Marks)
QUESTION 2a )Applications require various types of permission to be effective. Listed below are 5 permissions. Please indicate why each of these permissions would be required by the application giving an example of an application from your experience [5]
i)Receive text messages (android.permission.RECEIVE_SMS)
ii)install shortcuts (com.android.launcher.permission.INSTALL_SHORTCUT)
iii)precise (GPS) location (android.permission.ACCESS_FINE_LOCATION)
iv)Take pictures or videos (android.permission.CAMERA)
v)read phone status and identity (android.permission.READ_PHONE_STATE)
Answer)
Nowadays many android apps installs a shortcut on home screen when you install the app and run it for the first time. This is a nice strategy to engage user by compiling them to use your app. Most of times when a user install an app, the app is deep buried in list of apps making it almost difficult to discover. So its always a good idea to make a shortcut right on home screen.
Android provide us an intent class com.android.launcher.action.INSTALL_SHORTCUT which can be used to add shortcuts to home screen. In following code snippet we create a shortcut of activity MainActivity with the name HelloWorldShortcut.
QUESTION 2b)Indicate the code (androin.permission.xxxxxx) you would set for the following requirements : [5]
i)The application need permission to vibrate your phone to notify you of a new message.
Answer)“android.permission.VIBRATE”
To vibrate your phone when you have new incoming messages or calls.
ii)Provide permission to diagnose your network connection and have the app react accordingly to ensure you get your messages.
Answer)android.permission.ACCESS_NETWORK_STATE”
To diagnose network connection and have the app react accordingly to ensure you get the messages on time.
iii)We need this to make sure that when a friend sends you a file, it doesn't get broken by your phone going to sleep.
Answer)“android.permission.WAKE_LOCK”
To make sure the phone does not go to sleep while you are using Wire during certain situations, for example calling or recording audio-/video clips.
iv)We use this to add a WhatsApp account to your device to show your WhatsAppable contacts
Answer)Add or remove accounts (android.permission.MANAGE_ACCOUNTS)
Explanation: We use this to add a WhatsApp account to your device to show your WhatsAppable contacts. Permission: create accounts and set passwords (android.permission.AUTHENTICATE_ACCOUNTS)
v)We use this permission to allow you to record Voice Notes to send to your friends.
Answer)Microphone - “android.permission.RECORD_AUDIO”
To call and record audio messages.
QUESTION 3(20 Marks)
Case Study for ONLINE TEST APPLICATION.
(Even if you can answer parts of this question you will be given due credit for effort)
The Proposed App aims to be User centric. After registration, user can log in and can start the test upon selecting the subject. Each question will be given one minute. User has to answer the test within the time and after submission, correct answers will be shown. If the user doesn’t give the answer within specified time then next question will appear. Also user can view his/her previous results but administrator can view the results of all the users. Actual Users are the students, by logging in they can play quiz. Admin task is to add more questions and to keep track of previous as well as current results of quiz.
The Modules have been described as follows:
1. Login Module: In this module, user has to first register. User will be moved to Register activity after clicking register button on Login screen. User has to fill details like Username, Email-id, Mobile number, Password and Confirm Password Etc. Only registered user can play quiz by logging in.
2. Admin module: If the user log in as an Admin then user can add new questions by selecting a particular area and a subject related to that area or make any changes to database. Admin can display result of all users, datewise or name wise as the case may be.
3. Registration for new User: If the user wants to play quiz, first user must register by filling details like User name,Emailid,Password,Confirm Password etc. After successful Registration, user can login. After login, user can Play the quiz.
4. Results view: This module is used to display previous as well as current scores of users. By viewing the results, user can measure performance compared to last attempts
Please answer the following questions:
a. Divide the project into modules and show their relationship. [3]
b. Design a layout for the Login Screen and Registration Screen. Clearly indicate the type of layout you have used and why. [3]
c. Write the AndroidManifest.xml code for this application. Assume you have only two activity LoginActivity and RegisterActivity. [4]
d. Write out the code for activity_login.xml. Clearly bring out the layout manager which should reflect the answer you have given to (b) above. The following phrases must appear in your answer: android:orientation=" "; android:layout_width=" "; android:layout_height=" "; match_parent; wrap_content; @id/header; fill_parent; android:layout_marginTop=""; android:layout_marginBottom=""; android:textColor="#0b84aa"/> [5]
e. Write the code for LoginActivity.java and RegisterActivity.java. Appropriate packages are to be imported. Please assure that you create the following code in your answer: [5]
LoginActivity.java
// setting default screen to login.xml
// Listening to register new account link
// Switching to Register screen
RegisterActivity.java
// Set View to register.xml
// Listening to Login Screen link
// Closing registration screen
// Switching to Login Screen/closing register screen
Answer)
Switching from Registration screen to Login screen
LoginActivity.java file
package com.androidhive.loginandregister;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class LoginActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setting default screen to login.xml
setContentView(R.layout.login);
TextView registerScreen = (TextView) findViewById(R.id.link_to_register);
// Listening to register new account link
registerScreen.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Switching to Register screen
Intent i = new Intent(getApplicationContext(), RegisterActivity.class);
startActivity(i);
}
});
}
}
Open your RegisterActivity.java and modify your code to following. To switch back to login screen just call finish(). It will close the registration screen, so login screen will be shown:
RegisterActivity.java file
package com.androidhive.loginandregister;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class RegisterActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set View to register.xml
setContentView(R.layout.register);
TextView loginScreen = (TextView) findViewById(R.id.link_to_login);
// Listening to Login Screen link
loginScreen.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// Closing registration screen
// Switching to Login Screen/closing register screen
finish();
}
});
}
}
QUESTION 4(10 Marks)
QUESTION 4a)You are invited for the newly opened Wipro office in Bangalore. You have just arrived to Bangalore airport. You are searching the route for this new office on your android phone. You have traced the route on Google Map app and have started your navigation. But somewhere during your journey you lost route just because GPS has lost the connection. But after some time the GPS connection is recovered. You now realized that this has happened just because the GPS has re-registered your phone [1+1+3=5]
a.You need to find you current location. Write a code snippet for it.
b.How do you set the zoom to tightest beyond which user cannot zoom out?
c.How to set the library and internet permission in Androidmenifest.xml file?
QUESTION 4b)Write a code to create a SQLiteDatabase and display success message on UI? [5]
No comments:
Post a Comment