fix(android): resolve permission request and status display issues

- Add requestPermissions method alias to fix Vue app compatibility
- Fix permission response format to include both string and boolean values
- Add comprehensive debugging for permission request flow
- Implement permission request throttling to prevent app crashes
- Fix capacitor.settings.gradle plugin path configuration
- Enhance Vue app logging for permission status debugging

Resolves permission dialog not appearing and UI showing incorrect status.
All permission functionality now works end-to-end with proper status updates.
This commit is contained in:
Matthew Raymer
2025-10-23 11:47:55 +00:00
parent 7185c87e93
commit 6aaeaf7808
3 changed files with 96 additions and 11 deletions

View File

@@ -1118,6 +1118,26 @@ public class DailyNotificationPlugin extends Plugin {
}
}
/**
* Request notification permissions (alias for requestNotificationPermissions)
*
* @param call Plugin call
*/
@PluginMethod
public void requestPermissions(PluginCall call) {
Log.d(TAG, "DEBUG: requestPermissions method called");
Log.d(TAG, "DEBUG: Method call received from JavaScript");
Log.d(TAG, "DEBUG: Delegating to requestNotificationPermissions");
try {
// Delegate to the main permission request method
requestNotificationPermissions(call);
} catch (Exception e) {
Log.e(TAG, "DEBUG: Error in requestPermissions delegation", e);
call.reject("Error in requestPermissions: " + e.getMessage());
}
}
/**
* Request notification permissions
*
@@ -1126,18 +1146,25 @@ public class DailyNotificationPlugin extends Plugin {
@PluginMethod
public void requestNotificationPermissions(PluginCall call) {
try {
Log.d(TAG, "DEBUG: requestNotificationPermissions method called");
Log.d(TAG, "DEBUG: Android SDK version: " + Build.VERSION.SDK_INT);
Log.d(TAG, "DEBUG: TIRAMISU version: " + Build.VERSION_CODES.TIRAMISU);
Log.d(TAG, "Requesting notification permissions");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
Log.d(TAG, "DEBUG: Android 13+ detected, requesting POST_NOTIFICATIONS permission");
// Request POST_NOTIFICATIONS permission for Android 13+
requestPermissionForAlias("notifications", call, "notificationPermissions");
requestPermissionForAlias("notifications", call, "onPermissionResult");
} else {
Log.d(TAG, "DEBUG: Pre-Android 13, checking notification manager");
// For older versions, check if notifications are enabled
boolean enabled = NotificationManagerCompat.from(getContext()).areNotificationsEnabled();
Log.d(TAG, "DEBUG: Notifications enabled: " + enabled);
if (enabled) {
Log.i(TAG, "Notifications already enabled");
call.resolve();
} else {
Log.d(TAG, "DEBUG: Opening notification settings");
// Open notification settings
openNotificationSettings();
call.resolve();
@@ -1145,6 +1172,7 @@ public class DailyNotificationPlugin extends Plugin {
}
} catch (Exception e) {
Log.e(TAG, "DEBUG: Exception in requestNotificationPermissions", e);
Log.e(TAG, "Error requesting notification permissions", e);
call.reject("Error requesting permissions: " + e.getMessage());
}
@@ -1156,14 +1184,17 @@ public class DailyNotificationPlugin extends Plugin {
* @param call Plugin call containing permission result
*/
@PermissionCallback
private void notificationPermissions(PluginCall call) {
private void onPermissionResult(PluginCall call) {
try {
Log.d(TAG, "Notification permission callback received");
Log.d(TAG, "DEBUG: onPermissionResult callback received");
Log.d(TAG, "Permission callback received");
// Check if POST_NOTIFICATIONS permission was granted
boolean permissionGranted = getContext().checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS)
== PackageManager.PERMISSION_GRANTED;
Log.d(TAG, "DEBUG: Permission granted: " + permissionGranted);
if (permissionGranted) {
Log.i(TAG, "Notification permission granted");
call.resolve();
@@ -1173,11 +1204,31 @@ public class DailyNotificationPlugin extends Plugin {
}
} catch (Exception e) {
Log.e(TAG, "Error in notification permission callback", e);
Log.e(TAG, "DEBUG: Exception in onPermissionResult callback", e);
Log.e(TAG, "Error in permission callback", e);
call.reject("Error processing permission result: " + e.getMessage());
}
}
/**
* Check current permission status (alias for checkPermissionStatus)
*
* @param call Plugin call
*/
@PluginMethod
public void checkPermissions(PluginCall call) {
Log.d(TAG, "DEBUG: checkPermissions method called (alias)");
Log.d(TAG, "DEBUG: Delegating to checkPermissionStatus");
try {
// Delegate to the main permission check method
checkPermissionStatus(call);
} catch (Exception e) {
Log.e(TAG, "DEBUG: Error in checkPermissions delegation", e);
call.reject("Error in checkPermissions: " + e.getMessage());
}
}
/**
* Check current permission status
*
@@ -1193,6 +1244,7 @@ public class DailyNotificationPlugin extends Plugin {
// Check notification permissions
boolean notificationsEnabled = areNotificationsEnabled();
result.put("notificationsEnabled", notificationsEnabled);
result.put("notifications", notificationsEnabled ? "granted" : "denied");
// Check exact alarm permissions (Android 12+)
boolean exactAlarmEnabled = true;