Skip to content

Commit

Permalink
notificatin added
Browse files Browse the repository at this point in the history
  • Loading branch information
mhRumi committed Aug 12, 2019
1 parent d1d5c24 commit ff50417
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<activity android:name=".FinalCalculation"></activity>
<activity android:name=".Notification"></activity>
<activity android:name=".FinalCalculation" />
<activity android:name=".ShowBazarList" />
<activity android:name=".BazarListCreate" />
<activity android:name=".Personal_info" />
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/java/com/example/messmanagement/Notification.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
34 changes: 34 additions & 0 deletions app/src/main/java/com/example/messmanagement/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -193,4 +202,29 @@ protected Map<String, String> 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());
}
}
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_message_black_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M20,2L4,2c-1.1,0 -1.99,0.9 -1.99,2L2,22l4,-4h14c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM18,14L6,14v-2h12v2zM18,11L6,11L6,9h12v2zM18,8L6,8L6,6h12v2z"/>
</vector>
20 changes: 20 additions & 0 deletions app/src/main/res/layout/activity_notification.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="300dp"
android:padding="50dp"
android:background="@color/colorPrimaryDark"
tools:context=".Notification">

<TextView
android:id="@+id/notification"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000"
android:textAlignment="center"
android:textSize="25sp"
/>

</LinearLayout>

0 comments on commit ff50417

Please sign in to comment.