0% found this document useful (0 votes)
11 views2 pages

Assignment 9 MC 007

Uploaded by

sujata
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Assignment 9 MC 007

Uploaded by

sujata
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

SIES College of Management Studies SYMCA (Revised), Sem III,

Roll No: 07

Assignment - 9

Write an android program for Notification.


Code:
MainActivity.java:
package com.example.p9;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
NotificationManager nm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn_show;
btn_show = findViewById(R.id.btn_notif);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
{
NotificationChannel ch = new NotificationChannel("CHANNEL1","SIES",
NotificationManager.IMPORTANCE_HIGH);
ch.setDescription("Channel");
nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.createNotificationChannel(ch);
}
btn_show.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Notify();
}
});
}
private void Notify() {
NotificationCompat.Builder bld = new NotificationCompat.Builder(this, "CHANNEL1")
.setSmallIcon(R.drawable.baseline_accessible_forward_24)
.setContentTitle("Ultimate Racing")
.setContentText("Race with Amazing Wheelchairs!")

Subject: MCAL34 Mobile Computing Lab Academic Year


First Half 2023_24
SIES College of Management Studies SYMCA (Revised), Sem III,
Roll No: 07

.setAutoCancel(true)
.setPriority(NotificationManager.IMPORTANCE_HIGH);
Intent notify_intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.google.co.in"));
notify_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent PendInt =
PendingIntent.getActivity(this,0,notify_intent,PendingIntent.FLAG_IMMUTABLE);
bld.setContentIntent(PendInt);
nm.notify(0,bld.build());
}
}
Output:

Subject: MCAL34 Mobile Computing Lab Academic Year


First Half 2023_24

You might also like