From ff50417e31fe6fd775a12965d3e5f96145b1f395 Mon Sep 17 00:00:00 2001 From: mhRumi Date: Tue, 13 Aug 2019 01:55:04 +0600 Subject: [PATCH] notificatin added --- app/src/main/AndroidManifest.xml | 3 +- .../example/messmanagement/Notification.java | 22 ++++++++++++ .../com/example/messmanagement/Profile.java | 34 +++++++++++++++++++ .../res/drawable/ic_message_black_24dp.xml | 9 +++++ .../main/res/layout/activity_notification.xml | 20 +++++++++++ 5 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/example/messmanagement/Notification.java create mode 100644 app/src/main/res/drawable/ic_message_black_24dp.xml create mode 100644 app/src/main/res/layout/activity_notification.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 19051d7..8faa32f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,7 +12,8 @@ android:supportsRtl="true" android:theme="@style/AppTheme" android:usesCleartextTraffic="true"> - + + diff --git a/app/src/main/java/com/example/messmanagement/Notification.java b/app/src/main/java/com/example/messmanagement/Notification.java new file mode 100644 index 0000000..cc94c39 --- /dev/null +++ b/app/src/main/java/com/example/messmanagement/Notification.java @@ -0,0 +1,22 @@ +package com.example.messmanagement; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; +import android.widget.TextView; + +public class Notification extends AppCompatActivity { + private TextView textView; + String message; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_notification); + + message = getIntent().getStringExtra("Message"); + + textView = findViewById(R.id.notification); + textView.setText(message); + } +} diff --git a/app/src/main/java/com/example/messmanagement/Profile.java b/app/src/main/java/com/example/messmanagement/Profile.java index 573eae6..bf43d19 100644 --- a/app/src/main/java/com/example/messmanagement/Profile.java +++ b/app/src/main/java/com/example/messmanagement/Profile.java @@ -2,7 +2,12 @@ import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.NotificationCompat; +import androidx.core.app.NotificationManagerCompat; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.Menu; @@ -36,6 +41,8 @@ public class Profile extends AppCompatActivity implements View.OnClickListener { private ProgressBar updateprogress; private DatePicker datePicker; public static String Name, Date; + private final String channel_id = "public notifications"; + private final int notification_id = 001; @Override protected void onCreate(Bundle savedInstanceState) { @@ -155,10 +162,12 @@ public void onResponse(String response) { Toast.makeText(getApplicationContext(),response.toString(),Toast.LENGTH_SHORT).show(); if(response.toString().equals("Updated successfully")){ + setNotification(); date.setText(null); amount.setText(null); meal.setText(null); + }else{ //progressBar.setVisibility(View.GONE); } @@ -193,4 +202,29 @@ protected Map getParams() throws AuthFailureError { } + + public void setNotification(){ + String message = "Bazar is done by "+Name+"\n and the cost is "+amount.getText().toString().trim()+" Tk"; + + NotificationCompat.Builder builder = new NotificationCompat.Builder(this) + + .setSmallIcon(R.drawable.ic_message_black_24dp) + .setContentTitle("Bazar done !!!") + .setContentText(message) + .setAutoCancel(true); + + Intent intent = new Intent(this,Notification.class); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + intent.putExtra("Message",message); + + PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT); + builder.setContentIntent(pendingIntent); + + + NotificationManager notificationManager =(NotificationManager) getSystemService( + Context.NOTIFICATION_SERVICE + ); + + notificationManager.notify(0,builder.build()); + } } diff --git a/app/src/main/res/drawable/ic_message_black_24dp.xml b/app/src/main/res/drawable/ic_message_black_24dp.xml new file mode 100644 index 0000000..d2876bf --- /dev/null +++ b/app/src/main/res/drawable/ic_message_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/activity_notification.xml b/app/src/main/res/layout/activity_notification.xml new file mode 100644 index 0000000..12942ca --- /dev/null +++ b/app/src/main/res/layout/activity_notification.xml @@ -0,0 +1,20 @@ + + + + + + \ No newline at end of file