This commit is contained in:
Your Name
2024-03-04 01:13:29 -06:00
parent 54c32d7526
commit fc2268e1fe
73 changed files with 41 additions and 47 deletions

View File

@@ -66,31 +66,31 @@ class MyBroadcastReceiver : BroadcastReceiver(), TetheringManager.StartTethering
// */
// override fun onTetheringFailed(error: Int? = null) { }
private fun createNotificationChannel(context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val name = "Tethering Notification"
val descriptionText = "Notifications for tethering status"
val importance = NotificationManager.IMPORTANCE_DEFAULT
val channel = NotificationChannel("TETHERING_STATUS", name, importance).apply {
description = descriptionText
}
val notificationManager: NotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
}
}
private fun showNotification(context: Context, title: String, message: String) {
createNotificationChannel(context)
val notificationBuilder = NotificationCompat.Builder(context, "TETHERING_STATUS")
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle(title)
.setContentText(message)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
val notificationManager = ContextCompat.getSystemService(context, NotificationManager::class.java)
notificationManager?.notify(System.currentTimeMillis().toInt(), notificationBuilder.build())
}
// private fun createNotificationChannel(context: Context) {
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// val name = "Tethering Notification"
// val descriptionText = "Notifications for tethering status"
// val importance = NotificationManager.IMPORTANCE_DEFAULT
// val channel = NotificationChannel("TETHERING_STATUS", name, importance).apply {
// description = descriptionText
// }
// val notificationManager: NotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
// notificationManager.createNotificationChannel(channel)
// }
// }
//
// private fun showNotification(context: Context, title: String, message: String) {
// createNotificationChannel(context)
//
// val notificationBuilder = NotificationCompat.Builder(context, "TETHERING_STATUS")
// .setSmallIcon(R.drawable.ic_launcher_foreground)
// .setContentTitle(title)
// .setContentText(message)
// .setPriority(NotificationCompat.PRIORITY_DEFAULT)
//
// val notificationManager = ContextCompat.getSystemService(context, NotificationManager::class.java)
// notificationManager?.notify(System.currentTimeMillis().toInt(), notificationBuilder.build())
// }
override fun onReceive(context: Context, intent: Intent) {
@@ -107,19 +107,19 @@ class MyBroadcastReceiver : BroadcastReceiver(), TetheringManager.StartTethering
for (startable in config.startables.values) startable.start(App.app)
}
TetheringManager.startTethering(TetheringManager.TETHERING_WIFI, false, this)
showNotification(context, "Tethering Status", "Wi-Fi tethering started")
// showNotification(context, "Tethering Status", "Wi-Fi tethering started")
}
"WIFI_TETHER_STOP" -> {
TetheringManager.stopTethering(TetheringManager.TETHERING_WIFI)
}
TetheringManager.ACTION_TETHER_STATE_CHANGED -> {
val tetheredInterfaces = intent.getStringArrayListExtra(TetheringManager.EXTRA_ACTIVE_TETHER)
val message = if (tetheredInterfaces != null && tetheredInterfaces.isNotEmpty()) {
"Tethering interfaces changed. Monitoring service called for ${tetheredInterfaces.joinToString(", ")}"
} else {
"No active tethering interfaces found"
}
showNotification(context, "Tethering Status", message)
// val message = if (tetheredInterfaces != null && tetheredInterfaces.isNotEmpty()) {
// "Tethering interfaces changed. Monitoring service called for ${tetheredInterfaces.joinToString(", ")}"
// } else {
// "No active tethering interfaces found"
// }
// showNotification(context, "Tethering Status", message)
if (tetheredInterfaces != null && tetheredInterfaces.isNotEmpty()) {
Toast.makeText(context, "Tethering interfaces changed", Toast.LENGTH_SHORT).show()
tetheredInterfaces.forEach { iface ->
@@ -127,10 +127,10 @@ class MyBroadcastReceiver : BroadcastReceiver(), TetheringManager.StartTethering
putExtra(TetheringService.EXTRA_ADD_INTERFACES, arrayOf(iface))
context.startForegroundService(this)
}
Toast.makeText(context, "Monitoring service called for $iface", Toast.LENGTH_SHORT).show()
// Toast.makeText(context, "Monitoring service called for $iface", Toast.LENGTH_SHORT).show()
}
} else {
Toast.makeText(context, "No active tethering interfaces found", Toast.LENGTH_SHORT).show()
// Toast.makeText(context, "No active tethering interfaces found", Toast.LENGTH_SHORT).show()
}
}
}