Professional Documents
Culture Documents
SAMD Lab 11
SAMD Lab 11
SAMD Lab 11
Lab -
Introduction
A notification is a message you can display
to the user outside of your application's
normal UI. When you tell the system to issue
a notification, it first appears as an icon in
the notification area. To see the details of
the notification, the user opens the
notification drawer. Both the notification
area and the notification drawer are system-
controlled areas that the user can view at
any time.
Design Considerations
Design an interface that takes input from the user. The inputs are the name, age, and
gender of the person. The inputs should be stored in an object of a class named person.
The object should have the attributes of name, age and gender.
Design a notification that is displayed on the notification bar when user presses the ‘OK’
button to submit these inputs. Also, in the notification history list it should display if the
gender entered was male or female and whether the male is older than 30, and if a
female then if she is older than 40 or not.
Procedure:
The code for the person class is as shown below:
For designing the interface and binding the controls to the java file the code is as shown
below:
ok.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
PersonClass pclass = new PersonClass();
pclass.pName = name.getText().toString();
pclass.pGender = gender.getText().toString();
pclass.pAge = age.getText().toString();
checkMaleorFemale(pclass);
}
});
}
// Notification count
private int mNotificationCount;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mNotificationIntent = new
Intent(getApplicationContext(),NotificationActivity.class );
mContentIntent = PendingIntent.getActivity(getApplicationContext(),
0, mNotificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
initialize();
}
Notification.Builder notificationBuilder =
new Notification.Builder(getApplicationContext())
.setTicker(tickerText)
.setSmallIcon(R.drawable.samllnotification)
.setAutoCancel(true)
.setContentIntent(mContentIntent)
//.setSound(soundURI)
//.setVibrate(mVibratePattern)
.setContent(mContentViews);
Observations:
The Following snapshots show the execution of the application:
When user enter till button click:
Task 2: design an application which display a notification with sound and customize text.
When clicking on the notification it will take to your application another activity