-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aditya
committed
Apr 28, 2021
1 parent
7045b39
commit 4fedb8c
Showing
15 changed files
with
267 additions
and
174 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
243 changes: 125 additions & 118 deletions
243
app/src/main/java/com/aditya/smartplantwateringsystem/MainActivity.java
Large diffs are not rendered by default.
Oops, something went wrong.
71 changes: 71 additions & 0 deletions
71
app/src/main/java/com/aditya/smartplantwateringsystem/backgroundNotificationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.aditya.smartplantwateringsystem; | ||
|
||
import android.app.NotificationChannel; | ||
import android.app.NotificationManager; | ||
import android.app.PendingIntent; | ||
import android.app.Service; | ||
import android.content.Intent; | ||
import android.os.IBinder; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.core.app.NotificationCompat; | ||
import androidx.core.app.NotificationManagerCompat; | ||
|
||
import com.google.firebase.database.DataSnapshot; | ||
import com.google.firebase.database.DatabaseError; | ||
import com.google.firebase.database.DatabaseReference; | ||
import com.google.firebase.database.FirebaseDatabase; | ||
import com.google.firebase.database.ValueEventListener; | ||
|
||
|
||
public class backgroundNotificationService extends Service { | ||
private int moisturepercentage = 100; | ||
|
||
@Nullable | ||
@Override | ||
public IBinder onBind(Intent intent) { | ||
return null; | ||
} | ||
|
||
public void createNotificationChannel() { | ||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { | ||
NotificationChannel channel = new NotificationChannel("plantnotification", "moistureChannel", NotificationManager.IMPORTANCE_DEFAULT); | ||
channel.setDescription("Channel for smart plant watering system notification"); | ||
NotificationManager notificationManager = getSystemService(NotificationManager.class); | ||
notificationManager.createNotificationChannel(channel); | ||
} | ||
} | ||
|
||
@Override | ||
public int onStartCommand(Intent intent, int flags, int startId) { | ||
createNotificationChannel(); | ||
DatabaseReference moistureRef = FirebaseDatabase.getInstance().getReference().child("Plant").child("Moisture"); | ||
Intent notificationIntent = new Intent(this, MainActivity.class); | ||
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | ||
| Intent.FLAG_ACTIVITY_SINGLE_TOP); | ||
PendingIntent intentz = PendingIntent.getActivity(this, 0, notificationIntent, 0); | ||
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "plantnotification") | ||
.setSmallIcon(R.drawable.ic_baseline_warning_24) | ||
.setContentTitle("Moisture Level is Low") | ||
.setContentIntent(intentz) | ||
.setContentText("Please water the plant") | ||
.setPriority(NotificationCompat.PRIORITY_DEFAULT); | ||
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); | ||
moistureRef.addValueEventListener(new ValueEventListener() { | ||
@Override | ||
public void onDataChange(@NonNull DataSnapshot snapshot) { | ||
moisturepercentage = Integer.parseInt(snapshot.getValue().toString()); | ||
if (moisturepercentage <= 15) { | ||
notificationManager.notify(100, builder.build()); | ||
} | ||
} | ||
|
||
@Override | ||
public void onCancelled(@NonNull DatabaseError error) { | ||
} | ||
}); | ||
return START_STICKY; | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:tint="#FF5252" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M1,21h22L12,2 1,21zM13,18h-2v-2h2v2zM13,14h-2v-4h2v4z" /> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
<resources> | ||
<string name="app_name">Smart Plant Watering System</string> | ||
<string name="releaseTxt">Release to Stop</string> | ||
<string name="wateringTxt">Hold to Water the Plant</string> | ||
<string name="notifications">Notifications</string> | ||
<string name="dark_mode">Dark Mode</string> | ||
<string name="soil_moisture_content">Soil Moisture Content</string> | ||
<string name="not_available">NaN</string> | ||
<string name="automatic_mode">Automatic Mode</string> | ||
<string name="minimum_level">Minimum level:</string> | ||
<string name="default_minval">0</string> | ||
<string name="set">Set</string> | ||
<string name="hold_to_water_the_plant">Hold to Water the Plant</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<full-backup-content> | ||
<!-- TODO Remove the following "exclude" elements to make them a part of the auto backup --> | ||
<!-- Exclude the shared preferences file that contains the GCM registrationId --> | ||
<exclude | ||
domain="sharedpref" | ||
path="sharedPrefs.xml" /> | ||
</full-backup-content> |