Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chad #1

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified README.md
Binary file not shown.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ android {
buildFeatures {
viewBinding true
}
namespace 'com.ar.application'
}

dependencies {
Expand All @@ -43,7 +44,9 @@ dependencies {
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.android.gms:play-services-maps:18.1.0'
implementation 'com.google.android.gms:play-services-location:20.0.0'
implementation 'com.google.firebase:firebase-messaging-ktx:23.0.8'
implementation 'com.google.firebase:firebase-database-ktx:20.0.6'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand Down
16 changes: 9 additions & 7 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.ar.application">
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
Expand All @@ -32,7 +33,7 @@
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="${MAPS_API_KEY}" />
android:value="AIzaSyBesYoZOX1GYDg1n5JySelTKaTPafyfm1w" />

<activity
android:name=".TracingRoute"
Expand All @@ -54,6 +55,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".GeofenceReceiver" />
</application>

</manifest>
7 changes: 7 additions & 0 deletions app/src/main/java/com/ar/application/Fence.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.ar.application

data class Fence(
var key: String = "",
var lat: Double = 0.0,
var lng: Double = 0.0,
)
54 changes: 54 additions & 0 deletions app/src/main/java/com/ar/application/GeofenceReceiver.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.ar.application

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.ar.application.Geofencing.Companion.showNotification
import com.google.android.gms.location.Geofence
import com.google.android.gms.location.GeofencingEvent
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
import com.google.firebase.database.ValueEventListener
import com.google.firebase.database.ktx.database
import com.google.firebase.database.ktx.getValue
import com.google.firebase.ktx.Firebase

class GeofenceReceiver: BroadcastReceiver() {
lateinit var key: String
lateinit var message: String
override fun onReceive(p0: Context?, p1: Intent?) {
if (p0 != null) {
val geofencingEvent = p1?.let { GeofencingEvent.fromIntent(it) }
val geofenceTransition = geofencingEvent?.geofenceTransition

if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER
|| geofenceTransition == Geofence.GEOFENCE_TRANSITION_DWELL) {
if (p1 != null) {
key = p1.getStringExtra("key")!!
message = p1.getStringExtra("message")!!
}

// retrieving data from database
val database = Firebase.database
val reference = database.getReference("fences")
val fenceListener = object : ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
val fence = snapshot.getValue<Fence>()
if (fence != null) {
showNotification(
p0.applicationContext,
message
)
}
}

override fun onCancelled(error: DatabaseError) {
println("Fence: onCancelled: ${error.details}")
}
}
val child = reference.child(key)
child.addValueEventListener(fenceListener)
}
}
}
}
Loading