I’m quite new on android studio and I’m trying to create a service that collects every notification that arrives at the phone, writing it on firebase and another application that shows the content of the firebase.
Everything works as expected (The collection & uploading to firebase, fetch when the permissions are granted manually).
The only thing that I’m missing – is to verify in runtime if the application have the needed permissions or not (It’s always false, like I’m asking the wrong thing).
This is what I’m trying to do:
// Check and request notification permission if not granted
if (ContextCompat.checkSelfPermission(this, Manifest.permission.FOREGROUND_SERVICE)
!= PackageManager.PERMISSION_GRANTED) {
Log.d("MainActivity", "Permissions not granted, asking for it from user!");
requestNotificationAccess();
} else {
Log.d("MainActivity", "Permissions are granted, running service!");
startNotificationService();
}
On my AndroidManifest.xml I have:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" />
<service
android:name=".NotificationService"
android:label="Notification Service"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"
android:exported="true">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
Thanks