Skip to content

Commit

Permalink
notification permission
Browse files Browse the repository at this point in the history
  • Loading branch information
rikaaa0928 committed Dec 23, 2024
1 parent efb93cc commit e6c690d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />

<uses-permission android:name="com.wireguard.android.permission.CONTROL_TUNNELS" />
Expand Down
21 changes: 8 additions & 13 deletions app/src/main/java/moe/rikaaa0928/uot/UogGrpc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,18 @@ class UogGrpc : Service() {
}

private fun createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel =
NotificationChannel(channelId, "uog", NotificationManager.IMPORTANCE_DEFAULT);
val notificationManager: NotificationManager =
getSystemService(NOTIFICATION_SERVICE) as NotificationManager;
notificationManager.createNotificationChannel(channel);
}
val channel =
NotificationChannel(channelId, "uog", NotificationManager.IMPORTANCE_LOW);
val notificationManager: NotificationManager =
getSystemService(NOTIFICATION_SERVICE) as NotificationManager;
notificationManager.createNotificationChannel(channel);
}

private fun startForegroundService() {
try {
createNotificationChannel();
val notification = NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.ic_notification)
.setSmallIcon(R.mipmap.ic_launcher_foreground)
.setContentTitle("uog")
.setContentText("uog is running")
// Create the notification to display while the service is running
Expand All @@ -101,11 +99,8 @@ class UogGrpc : Service() {
/* foregroundServiceType = */
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
} else {
0
},
} else
ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE,
)
} catch (e: Exception) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/res/drawable/ic_notification.xml

This file was deleted.

0 comments on commit e6c690d

Please sign in to comment.