.
This commit is contained in:
15
.idea/deploymentTargetDropDown.xml
generated
15
.idea/deploymentTargetDropDown.xml
generated
@@ -3,20 +3,7 @@
|
||||
<component name="deploymentTargetDropDown">
|
||||
<value>
|
||||
<entry key="app">
|
||||
<State>
|
||||
<targetSelectedWithDropDown>
|
||||
<Target>
|
||||
<type value="QUICK_BOOT_TARGET" />
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="VIRTUAL_DEVICE_PATH" />
|
||||
<value value="C:\Users\ADITYA\.android\avd\Aditya_Pie.avd" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</targetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2024-02-26T09:39:48.641124800Z" />
|
||||
</State>
|
||||
<State />
|
||||
</entry>
|
||||
</value>
|
||||
</component>
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <!-- For app blocking -> open new window over other apps to deny access -->
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <!-- permissions for app blocking -->
|
||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
|
||||
|
||||
<uses-feature
|
||||
android:name="android.hardware.telephony"
|
||||
@@ -259,6 +260,9 @@
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths" />
|
||||
</provider>
|
||||
|
||||
<receiver android:name=".patient_dashboard.FoodAlarmReceiver"
|
||||
android:enabled="true"/>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -5,6 +5,8 @@ import static com.app.simplitend.apputils.NotificationService.CONTENT_TYPE_KEY;
|
||||
import static com.app.simplitend.patientgeofencing.GeoFenceHelper.GEOFENCE_TAG;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.role.RoleManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -12,6 +14,7 @@ import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.telecom.TelecomManager;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -20,6 +23,7 @@ import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.app.simplitend.BuildConfig;
|
||||
@@ -30,6 +34,9 @@ import com.app.simplitend.apputils.PatientDataCache;
|
||||
import com.app.simplitend.caregiverdashboard.mvvm.CgHomeContracts;
|
||||
import com.app.simplitend.caregiverdashboard.mvvm.models.GeoFenceDetails;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import io.socket.client.IO;
|
||||
import io.socket.client.Socket;
|
||||
|
||||
@@ -40,9 +47,12 @@ public class DashBoardActivity extends AppCompatActivity implements CgHomeContra
|
||||
protected PatientMainViewModel viewModel;
|
||||
|
||||
protected ActivityResultLauncher<String> finePermissionLauncher;
|
||||
protected ActivityResultLauncher<Intent> alarmPermissionLauncher;
|
||||
|
||||
private Socket mSocket;
|
||||
|
||||
private AlarmManager alarmManager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -50,10 +60,30 @@ public class DashBoardActivity extends AppCompatActivity implements CgHomeContra
|
||||
|
||||
viewModel = new ViewModelProvider(this).get(PatientMainViewModel.class);
|
||||
|
||||
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
|
||||
|
||||
updateGeofenceDetails();
|
||||
|
||||
alarmPermissionLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
|
||||
isGranted -> {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
if (alarmManager != null && alarmManager.canScheduleExactAlarms()) {
|
||||
scheduleFoodAlarms();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
finePermissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(),
|
||||
isGranted -> {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
|
||||
&& alarmManager != null
|
||||
&& !alarmManager.canScheduleExactAlarms()) {
|
||||
Intent intent = new Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM);
|
||||
alarmPermissionLauncher.launch(intent);
|
||||
} else {
|
||||
scheduleFoodAlarms();
|
||||
}
|
||||
|
||||
if (isGranted) {
|
||||
// getting location updates
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
@@ -102,6 +132,24 @@ public class DashBoardActivity extends AppCompatActivity implements CgHomeContra
|
||||
}, false);
|
||||
}
|
||||
|
||||
private void scheduleFoodAlarms() {
|
||||
if (alarmManager == null) return;
|
||||
if (true) return;
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || alarmManager.canScheduleExactAlarms()) {
|
||||
alarmManager.setExact(
|
||||
AlarmManager.RTC_WAKEUP,
|
||||
System.currentTimeMillis() + 10_000,
|
||||
PendingIntent.getBroadcast(this,
|
||||
0,
|
||||
new Intent(getApplicationContext(), FoodAlarmReceiver.class),
|
||||
PendingIntent.FLAG_IMMUTABLE)
|
||||
);
|
||||
|
||||
Log.d("FoodAlarmReceiver", "ALARM SCHEDULED for ");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context newBase) {
|
||||
final Configuration configuration = new Configuration(newBase.getResources().getConfiguration());
|
||||
@@ -113,7 +161,7 @@ public class DashBoardActivity extends AppCompatActivity implements CgHomeContra
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mSocket != null){
|
||||
if (mSocket != null) {
|
||||
mSocket.disconnect();
|
||||
}
|
||||
|
||||
@@ -136,11 +184,11 @@ public class DashBoardActivity extends AppCompatActivity implements CgHomeContra
|
||||
String content_type = (String) args[0];
|
||||
Log.d(TAG, "call: " + content_type);
|
||||
Intent broadcastIntent = new Intent(NOTIFICATION_ACTION);
|
||||
if ("0".equals(content_type)){
|
||||
if ("0".equals(content_type)) {
|
||||
// medications
|
||||
PatientMainViewModel.remindersList = null;
|
||||
broadcastIntent.putExtra(CONTENT_TYPE_KEY, Constants.MEDICINE_TIME);
|
||||
}else if ("1".equals(content_type)){
|
||||
} else if ("1".equals(content_type)) {
|
||||
// activities
|
||||
PatientMainViewModel.activityList = null;
|
||||
broadcastIntent.putExtra(CONTENT_TYPE_KEY, Constants.ACTIVITY_TIME);
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.app.simplitend.patient_dashboard;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
public class FoodAlarmReceiver extends BroadcastReceiver {
|
||||
|
||||
private static final String TAG = "FoodAlarmReceiver";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.d(TAG, "onReceive: ");
|
||||
AlarmManager alarmManager = context.getSystemService(AlarmManager.class);
|
||||
|
||||
if (alarmManager == null) return;
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || alarmManager.canScheduleExactAlarms()) {
|
||||
alarmManager.setExact(
|
||||
AlarmManager.RTC_WAKEUP,
|
||||
System.currentTimeMillis() + 10_000,
|
||||
PendingIntent.getBroadcast(context,
|
||||
0,
|
||||
new Intent(context, FoodAlarmReceiver.class),
|
||||
PendingIntent.FLAG_IMMUTABLE)
|
||||
);
|
||||
|
||||
Log.d("FoodAlarmReceiver", "ALARM SCHEDULED");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user