├── .gitattributes ├── .gitignore ├── .idea ├── .gitignore ├── .name ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── compiler.xml ├── deploymentTargetSelector.xml ├── gradle.xml ├── kotlinc.xml ├── migrations.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro ├── releases │ └── download │ │ ├── v1.0.1 │ │ └── alertly-1.0.1.apk │ │ └── v1.1.0 │ │ └── alertly-1.1.0.apk └── src │ ├── main │ ├── AndroidManifest.xml │ ├── kotlin │ │ └── com │ │ │ └── example │ │ │ └── notificationalerter │ │ │ ├── AppAdapter.kt │ │ │ ├── AppInfo.kt │ │ │ ├── MainActivity.kt │ │ │ └── MyNotificationListenerService.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_launcher_background.xml │ │ └── logo.jpg │ │ ├── layout │ │ ├── activity_main.xml │ │ └── list_item_app.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── values-night │ │ └── themes.xml │ │ ├── values │ │ ├── colors.xml │ │ ├── ids.xml │ │ ├── strings.xml │ │ └── themes.xml │ │ └── xml │ │ ├── backup_rules.xml │ │ └── data_extraction_rules.xml │ └── src.7z ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── metadata └── en-US │ ├── changelogs │ └── 2.txt │ ├── full_description.txt │ ├── images │ ├── featureGraphic.jpg │ ├── icon.jpg │ └── phoneScreenshots │ │ └── 1.jpg │ ├── short_description.txt │ └── title.txt └── settings.gradle /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .salive 3 | .gradle 4 | /local.properties 5 | /.idea/caches 6 | /.idea/libraries 7 | /.idea/modules.xml 8 | /.idea/workspace.xml 9 | /.idea/navEditor.xml 10 | /.idea/assetWizardSettings.xml 11 | .DS_Store 12 | /build 13 | /captures 14 | .externalNativeBuild 15 | .cxx 16 | local.properties 17 | .kotlin -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | Alertly -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 119 | 120 | 122 | 123 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/deploymentTargetSelector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/kotlinc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/migrations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 17 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2024 Daniel Saynov 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Notification Listener App 2 | 3 | ### Overview 4 | This Android application enhances user experience by filtering and highlighting important notifications. It allows users to specify a sound effect and a keyword. When enabled, the app monitors notifications from selected apps for occurrences of the keyword. Upon detection, it replaces the default notification sound with the user-selected sound, ensuring important notifications are never overlooked. 5 | 6 | ### Features 7 | - **Keyword Detection:** Specify a keyword that the app will watch for in incoming notifications. 8 | - **Custom Sound Effects:** Choose a unique sound effect to play when the keyword is detected. 9 | - **Selective Listening:** Select which apps the listener should monitor for notifications. 10 | - **Enhanced Notification Management:** Ensures that notifications containing the keyword stand out from others. 11 | 12 | ### Usage 13 | 1. **Select Sound Effect:** Choose a preferred sound effect for notifications. 14 | 2. **Set Keyword:** Enter a specific keyword that the app will search for in notifications. 15 | 3. **Choose Apps:** Select the apps from which notifications should be monitored. 16 | 4. **Activate Listener:** Enable the app's listener to start monitoring incoming notifications. 17 | 5. **Permission Requirements:** Make sure to enable necessary permissions for the app to function properly. 18 | 19 | ### Download 20 | - **F-Droid:** You can download the latest version of the app from [F-Droid](https://f-droid.org/en/packages/com.example.notificationalerter/). 21 | 22 | ### Purpose 23 | This app aims to improve user productivity by prioritizing important notifications and reducing distractions from less critical alerts. It ensures that users are promptly notified of crucial information, making daily smartphone use more efficient and focused. 24 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'kotlin-android' 4 | } 5 | 6 | android { 7 | dependenciesInfo { 8 | // Disables dependency metadata when building APKs. 9 | includeInApk = false 10 | // Disables dependency metadata when building Android App Bundles. 11 | includeInBundle = false 12 | } 13 | 14 | namespace 'com.example.notificationalerter' 15 | compileSdk 35 16 | 17 | defaultConfig { 18 | applicationId "com.example.notificationalerter" 19 | minSdk 28 20 | targetSdk 35 21 | versionCode 2 22 | versionName "1.1.0" 23 | 24 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 25 | } 26 | 27 | buildTypes { 28 | release { 29 | minifyEnabled true 30 | vcsInfo.include false 31 | } 32 | } 33 | kotlinOptions { 34 | jvmTarget = "1.8" // Make sure Kotlin targets JVM 1.8 35 | } 36 | } 37 | 38 | dependencies { 39 | implementation "org.jetbrains.kotlin:kotlin-stdlib:2.0.21" 40 | implementation 'androidx.appcompat:appcompat:1.7.0' 41 | implementation 'com.google.android.material:material:1.12.0' 42 | implementation 'androidx.constraintlayout:constraintlayout:2.2.0' 43 | testImplementation 'junit:junit:4.13.2' 44 | androidTestImplementation 'androidx.test.ext:junit:1.2.1' 45 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' 46 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /app/releases/download/v1.0.1/alertly-1.0.1.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightningcpu/Alertly/1f14d616ef39c642163b6d786fda6aa0c8f36d16/app/releases/download/v1.0.1/alertly-1.0.1.apk -------------------------------------------------------------------------------- /app/releases/download/v1.1.0/alertly-1.1.0.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightningcpu/Alertly/1f14d616ef39c642163b6d786fda6aa0c8f36d16/app/releases/download/v1.1.0/alertly-1.1.0.apk -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 27 | 28 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /app/src/main/kotlin/com/example/notificationalerter/AppAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.example.notificationalerter 2 | 3 | import android.content.Context 4 | import android.view.LayoutInflater 5 | import android.view.View 6 | import android.view.ViewGroup 7 | import android.widget.ArrayAdapter 8 | import android.widget.CheckBox 9 | import android.widget.CompoundButton 10 | import android.widget.ImageView 11 | import android.widget.TextView 12 | 13 | class AppAdapter(context: Context?, private val appList: List) : ArrayAdapter(context!!, 0, appList) { 14 | private val inflater: LayoutInflater = LayoutInflater.from(context) 15 | private var listener: OnCheckedChangeListener? = null 16 | 17 | fun setOnCheckedChangeListener(listener: OnCheckedChangeListener?) { 18 | this.listener = listener 19 | } 20 | 21 | override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { 22 | var convertView = convertView 23 | val holder: ViewHolder 24 | if (convertView == null) { 25 | convertView = inflater.inflate(R.layout.list_item_app, parent, false) 26 | holder = ViewHolder() 27 | holder.iconImageView = convertView.findViewById(R.id.icon_image_view) 28 | holder.nameTextView = convertView.findViewById(R.id.name_text_view) 29 | holder.checkBox = convertView.findViewById(R.id.checkbox) 30 | convertView.setTag(holder) 31 | } else { 32 | holder = convertView.tag as ViewHolder 33 | } 34 | 35 | val appInfo = appList[position] 36 | 37 | holder.iconImageView!!.setImageDrawable(appInfo.icon) 38 | holder.nameTextView!!.text = appInfo.name 39 | 40 | holder.checkBox!!.setOnCheckedChangeListener(null) 41 | holder.checkBox!!.isChecked = appInfo.isChecked 42 | holder.checkBox!!.setOnCheckedChangeListener { compoundButton: CompoundButton?, isChecked: Boolean -> 43 | appInfo.isChecked = isChecked 44 | if (listener != null) { 45 | listener!!.onCheckedChange(appInfo.packageName, isChecked) 46 | } 47 | } 48 | 49 | return convertView!! 50 | } 51 | 52 | internal class ViewHolder { 53 | var iconImageView: ImageView? = null 54 | var nameTextView: TextView? = null 55 | var checkBox: CheckBox? = null 56 | } 57 | 58 | interface OnCheckedChangeListener { 59 | fun onCheckedChange(packageName: String?, isChecked: Boolean) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /app/src/main/kotlin/com/example/notificationalerter/AppInfo.kt: -------------------------------------------------------------------------------- 1 | package com.example.notificationalerter 2 | 3 | import android.graphics.drawable.Drawable 4 | 5 | // This is the info of each listed app 6 | class AppInfo { 7 | @JvmField 8 | var name: String? = null 9 | @JvmField 10 | var packageName: String? = null 11 | @JvmField 12 | var icon: Drawable? = null 13 | var isChecked: Boolean = false 14 | } -------------------------------------------------------------------------------- /app/src/main/kotlin/com/example/notificationalerter/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.notificationalerter 2 | 3 | import android.app.NotificationChannel 4 | import android.app.NotificationManager 5 | import android.content.ComponentName 6 | import android.content.Intent 7 | import android.content.pm.PackageManager 8 | import android.media.RingtoneManager 9 | import android.net.Uri 10 | import android.os.Build 11 | import android.os.Bundle 12 | import android.preference.PreferenceManager 13 | import android.provider.Settings 14 | import android.view.View 15 | import android.widget.Button 16 | import android.widget.EditText 17 | import android.widget.ListView 18 | import android.widget.Toast 19 | import androidx.appcompat.app.AppCompatActivity 20 | 21 | class MainActivity : AppCompatActivity() { 22 | private var toggleListenerButton: Button? = null 23 | private var appListView: ListView? = null 24 | private var appAdapter: AppAdapter? = null 25 | private var isListenerEnabled = false 26 | private var searchInput: EditText? = null 27 | 28 | private var chooseNotificationButton: Button? = null 29 | 30 | override fun onCreate(savedInstanceState: Bundle?) { 31 | super.onCreate(savedInstanceState) 32 | setContentView(R.layout.activity_main) 33 | 34 | toggleListenerButton = findViewById(R.id.toggle_listener_button) 35 | appListView = findViewById(R.id.app_list_view) 36 | searchInput = findViewById(R.id.search_input) 37 | chooseNotificationButton = findViewById(R.id.choose_notification_button) 38 | 39 | isListenerEnabled = false 40 | 41 | toggleListenerButton?.setOnClickListener(View.OnClickListener { toggleListener() }) 42 | 43 | chooseNotificationButton?.setOnClickListener(View.OnClickListener { openNotificationSoundPicker() }) 44 | 45 | appAdapter = AppAdapter(this, installedApps) 46 | appAdapter!!.setOnCheckedChangeListener(object : AppAdapter.OnCheckedChangeListener { 47 | override fun onCheckedChange(packageName: String?, isChecked: Boolean) { 48 | if (packageName != null) { 49 | if (isChecked) { 50 | MyNotificationListenerService.addSelectedApp(packageName) 51 | // Toast.makeText(this@MainActivity, "Selected: $packageName", Toast.LENGTH_SHORT).show() 52 | } else { 53 | MyNotificationListenerService.removeSelectedApp(packageName) 54 | // Toast.makeText(this@MainActivity, "Deselected: $packageName", Toast.LENGTH_SHORT).show() 55 | } 56 | } 57 | } 58 | }) 59 | appListView?.setAdapter(appAdapter) 60 | 61 | if (isNotificationAccessGranted) { 62 | toggleListenerButton?.setVisibility(View.VISIBLE) 63 | } else { 64 | toggleListenerButton?.setVisibility(View.GONE) 65 | requestNotificationAccessPermission() 66 | } 67 | 68 | // Retrieve the selected sound URI from SharedPreferences 69 | val preferences = PreferenceManager.getDefaultSharedPreferences(this) 70 | val selectedSoundUriString = preferences.getString(PREF_SELECTED_SOUND_URI, null) 71 | if (selectedSoundUriString != null) { 72 | val selectedSoundUri = Uri.parse(selectedSoundUriString) 73 | MyNotificationListenerService.customSoundUri = selectedSoundUri 74 | } 75 | 76 | createNotificationChannel() 77 | } 78 | 79 | private val installedApps: List 80 | get() { 81 | val appList: MutableList = ArrayList() 82 | val packageManager = packageManager 83 | val applications = packageManager.getInstalledApplications(PackageManager.GET_META_DATA) 84 | val appPackageName = packageName 85 | 86 | for (applicationInfo in applications) { 87 | val packageName = applicationInfo.packageName 88 | 89 | // Exclude the app itself 90 | if (packageName != appPackageName && isLaunchable(packageManager, packageName)) { 91 | val appInfo = AppInfo() 92 | appInfo.packageName = packageName 93 | appInfo.name = applicationInfo.loadLabel(packageManager).toString() 94 | appInfo.icon = applicationInfo.loadIcon(packageManager) 95 | appList.add(appInfo) 96 | } 97 | } 98 | 99 | return appList 100 | } 101 | 102 | private fun isLaunchable(packageManager: PackageManager, packageName: String): Boolean { 103 | val launchIntent = packageManager.getLaunchIntentForPackage(packageName) 104 | return launchIntent != null 105 | } 106 | 107 | private fun requestNotificationAccessPermission() { 108 | val intent = Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS) 109 | startActivityForResult(intent, REQUEST_NOTIFICATION_ACCESS) 110 | } 111 | 112 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 113 | super.onActivityResult(requestCode, resultCode, data) 114 | 115 | if (requestCode == REQUEST_NOTIFICATION_ACCESS) { 116 | if (isNotificationAccessGranted) { 117 | toggleListenerButton!!.visibility = View.VISIBLE 118 | } else { 119 | Toast.makeText(this, "Notification access not granted", Toast.LENGTH_SHORT).show() 120 | } 121 | } else if (requestCode == REQUEST_SOUND_PICKER) { 122 | if (resultCode == RESULT_OK) { 123 | val selectedSoundUri = data!!.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) 124 | if (selectedSoundUri != null) { 125 | // Save the selected sound URI to SharedPreferences 126 | val preferences = PreferenceManager.getDefaultSharedPreferences(this) 127 | val editor = preferences.edit() 128 | editor.putString(PREF_SELECTED_SOUND_URI, selectedSoundUri.toString()) 129 | editor.apply() 130 | 131 | // Handle the selected sound URI here 132 | // You can save it or use it to set the notification sound for your app 133 | MyNotificationListenerService.customSoundUri = selectedSoundUri 134 | Toast.makeText(this, "Sound selected", Toast.LENGTH_SHORT).show() 135 | } 136 | } else { 137 | Toast.makeText(this, "No sound selected", Toast.LENGTH_SHORT).show() 138 | } 139 | } 140 | } 141 | 142 | private val isNotificationAccessGranted: Boolean 143 | get() { 144 | val cn = ComponentName(this, MyNotificationListenerService::class.java) 145 | val flat = Settings.Secure.getString(contentResolver, "enabled_notification_listeners") 146 | return flat != null && flat.contains(cn.flattenToString()) 147 | } 148 | 149 | private fun toggleListener() { 150 | if (isListenerEnabled) { 151 | stopListener() 152 | } else { 153 | startListener() 154 | } 155 | } 156 | 157 | private fun startListener() { 158 | toggleListenerButton!!.text = "Stop Listener" 159 | isListenerEnabled = true 160 | Toast.makeText(this, "Listener started", Toast.LENGTH_SHORT).show() 161 | 162 | // Get the search word from the input field 163 | val searchWord = searchInput!!.text.toString().trim { it <= ' ' } 164 | 165 | // Pass the search word to the notification listener service 166 | MyNotificationListenerService.setSearchWord(searchWord) 167 | 168 | // Start the notification listener service 169 | startService(Intent(this, MyNotificationListenerService::class.java)) 170 | } 171 | 172 | private fun stopListener() { 173 | toggleListenerButton!!.text = "Start Listener" 174 | isListenerEnabled = false 175 | Toast.makeText(this, "Listener stopped", Toast.LENGTH_SHORT).show() 176 | 177 | // Stop the notification listener service 178 | stopService(Intent(this, MyNotificationListenerService::class.java)) 179 | // (applicationContext as MyNotificationListenerService).onListenerDisconnected() // Explicitly call it 180 | // finishAffinity() // This will finish all activities and close the app properly 181 | MyNotificationListenerService.setSearchWord(null) 182 | } 183 | 184 | private fun createNotificationChannel() { 185 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 186 | val name: CharSequence = "Alerter Channel" 187 | val description = "Channel for alerter notifications" 188 | val importance = NotificationManager.IMPORTANCE_HIGH 189 | 190 | val channel = NotificationChannel(NOTIFICATION_CHANNEL_ID, name, importance) 191 | channel.description = description 192 | 193 | val notificationManager = getSystemService(NotificationManager::class.java) 194 | notificationManager.createNotificationChannel(channel) 195 | } 196 | } 197 | 198 | private fun openNotificationSoundPicker() { 199 | val intent = Intent(RingtoneManager.ACTION_RINGTONE_PICKER) 200 | intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION) 201 | intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Notification Sound") 202 | intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, null as Uri?) 203 | startActivityForResult(intent, REQUEST_SOUND_PICKER) 204 | } 205 | 206 | companion object { 207 | private const val REQUEST_NOTIFICATION_ACCESS = 1 208 | private const val REQUEST_SOUND_PICKER = 2 209 | private const val NOTIFICATION_CHANNEL_ID = "alerter_channel_id" 210 | 211 | private const val PREF_SELECTED_SOUND_URI = "selected_sound_uri" 212 | } 213 | } 214 | 215 | 216 | -------------------------------------------------------------------------------- /app/src/main/kotlin/com/example/notificationalerter/MyNotificationListenerService.kt: -------------------------------------------------------------------------------- 1 | package com.example.notificationalerter 2 | 3 | import android.R 4 | import android.app.Notification 5 | import android.app.NotificationChannel 6 | import android.app.NotificationManager 7 | import android.app.PendingIntent 8 | import android.content.Intent 9 | import android.media.AudioAttributes 10 | import android.media.AudioManager 11 | import android.media.RingtoneManager 12 | import android.net.Uri 13 | import android.os.Build 14 | import android.service.notification.NotificationListenerService 15 | import android.service.notification.StatusBarNotification 16 | import android.util.Log 17 | import androidx.annotation.RequiresApi 18 | import androidx.core.app.NotificationCompat 19 | import androidx.core.app.NotificationManagerCompat 20 | import com.example.notificationalerter.MainActivity 21 | import java.util.Locale 22 | 23 | @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) 24 | class MyNotificationListenerService : NotificationListenerService() { 25 | override fun onCreate() { 26 | super.onCreate() 27 | Log.d(TAG, "NotificationListenerService onCreate") 28 | createNotificationChannel() 29 | } 30 | 31 | override fun onDestroy() { 32 | super.onDestroy() 33 | searchWord = null 34 | stopListening() 35 | Log.d(TAG, "NotificationListenerService onDestroy") 36 | } 37 | 38 | override fun onListenerConnected() { 39 | super.onListenerConnected() 40 | Log.d(TAG, "NotificationListenerService onListenerConnected") 41 | 42 | // Service is connected, start listening to notifications 43 | startListening() 44 | } 45 | 46 | override fun onListenerDisconnected() { 47 | super.onListenerDisconnected() 48 | Log.d(TAG, "NotificationListenerService onListenerDisconnected") 49 | 50 | // Service is disconnected, stop listening to notifications 51 | stopListening() 52 | } 53 | 54 | override fun onNotificationPosted(sbn: StatusBarNotification) { 55 | super.onNotificationPosted(sbn) 56 | Log.d(TAG, "Notification posted: " + sbn.packageName) 57 | 58 | val packageName = sbn.packageName 59 | if (isAppSelected(packageName)) { 60 | val title = sbn.notification.extras.getString(Notification.EXTRA_TITLE) 61 | val text = sbn.notification.extras.getString(Notification.EXTRA_TEXT) 62 | Log.d(TAG, "Title: $title") 63 | Log.d(TAG, "Text: $text") 64 | 65 | if (containsSearchWord(text)) { 66 | if (customSoundUri != null) { 67 | playCustomNotificationSound(customSoundUri) 68 | } else { 69 | playDefaultNotificationSound() 70 | } 71 | 72 | sendNotificationBroadcast(packageName, title, text) 73 | } 74 | } 75 | } 76 | 77 | private fun containsSearchWord(text: String?): Boolean { 78 | if (searchWord == null || searchWord!!.isEmpty()) { 79 | return false 80 | } 81 | 82 | val words = text!!.lowercase(Locale.getDefault()).split("\\W+".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() 83 | val lowercaseSearchWord = searchWord!!.lowercase(Locale.getDefault()) 84 | for (word in words) { 85 | if (word == lowercaseSearchWord) { 86 | return true 87 | } 88 | } 89 | 90 | return false 91 | } 92 | 93 | 94 | private fun isAppSelected(packageName: String): Boolean { 95 | return selectedApps.contains(packageName) 96 | } 97 | 98 | private fun containsSearchWord(sbn: StatusBarNotification): Boolean { 99 | if (searchWord == null || searchWord!!.isEmpty()) { 100 | return true 101 | } 102 | 103 | val title = sbn.notification.extras.getString(Notification.EXTRA_TITLE) 104 | val text = sbn.notification.extras.getString(Notification.EXTRA_TEXT) 105 | 106 | return ((title != null && title.lowercase(Locale.getDefault()).contains(searchWord!!.lowercase(Locale.getDefault()))) 107 | || (text != null && text.lowercase(Locale.getDefault()).contains(searchWord!!.lowercase(Locale.getDefault())))) 108 | } 109 | 110 | private fun playDefaultNotificationSound() { 111 | try { 112 | val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) 113 | playNotificationSound(defaultSoundUri) 114 | } catch (e: Exception) { 115 | Log.e(TAG, "Error playing default notification sound: " + e.message) 116 | } 117 | } 118 | 119 | private fun playCustomNotificationSound(soundUri: Uri?) { 120 | if (soundUri == null) { 121 | return 122 | } 123 | 124 | try { 125 | playNotificationSound(soundUri) 126 | } catch (e: Exception) { 127 | Log.e(TAG, "Error playing custom notification sound: " + e.message) 128 | } 129 | } 130 | 131 | private fun playNotificationSound(soundUri: Uri) { 132 | try { 133 | val context = applicationContext 134 | val ringtone = RingtoneManager.getRingtone(context, soundUri) 135 | 136 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { 137 | ringtone.audioAttributes = AudioAttributes.Builder() 138 | .setUsage(AudioAttributes.USAGE_NOTIFICATION) 139 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) 140 | .build() 141 | } else { 142 | ringtone.streamType = AudioManager.STREAM_NOTIFICATION 143 | } 144 | 145 | ringtone.play() 146 | } catch (e: Exception) { 147 | Log.e(TAG, "Error playing notification sound: " + e.message) 148 | } 149 | } 150 | 151 | private fun sendNotificationBroadcast(packageName: String, title: String?, text: String?) { 152 | // Create an explicit intent for MainActivity 153 | val intent = Intent(applicationContext, MainActivity::class.java) 154 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK) 155 | 156 | // Create a PendingIntent for the notification 157 | val pendingIntent = PendingIntent.getActivity(applicationContext, 0, intent, PendingIntent.FLAG_IMMUTABLE) 158 | 159 | // Build the notification 160 | val builder = NotificationCompat.Builder(applicationContext, CHANNEL_ID) 161 | .setSmallIcon(R.drawable.ic_lock_idle_low_battery) 162 | .setContentTitle(title) 163 | .setContentText(text) 164 | .setPriority(NotificationCompat.PRIORITY_DEFAULT) 165 | .setContentIntent(pendingIntent) 166 | .setAutoCancel(true) 167 | 168 | // Get the notification manager 169 | val notificationManager = NotificationManagerCompat.from(applicationContext) 170 | 171 | // Post the notification 172 | notificationManager.notify(NOTIFICATION_ID, builder.build()) 173 | } 174 | 175 | private fun startListening() { 176 | setSearchWord(searchWord) 177 | } 178 | 179 | private fun stopListening() { 180 | setSearchWord(null) 181 | } 182 | 183 | private fun createNotificationChannel() { 184 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 185 | val name: CharSequence = "Alerter Channel" 186 | val description = "Channel for alerter notifications" 187 | val importance = NotificationManager.IMPORTANCE_HIGH 188 | 189 | val channel = NotificationChannel(CHANNEL_ID, name, importance) 190 | channel.description = description 191 | 192 | val notificationManager = getSystemService(NotificationManager::class.java) 193 | notificationManager.createNotificationChannel(channel) 194 | } 195 | } 196 | 197 | companion object { 198 | private const val TAG = "NotificationListener" 199 | private const val ACTION_NOTIFICATION_POSTED = "com.example.notificationalerter.NOTIFICATION_POSTED" 200 | private const val EXTRA_SOUND_URI = "sound_uri" 201 | 202 | private val selectedApps: MutableSet = HashSet() 203 | private var searchWord: String? = null 204 | var customSoundUri: Uri? = null 205 | 206 | private const val CHANNEL_ID = "alerter" 207 | private const val NOTIFICATION_ID = 175 208 | 209 | fun addSelectedApp(packageName: String) { 210 | selectedApps.add(packageName) 211 | } 212 | 213 | fun removeSelectedApp(packageName: String) { 214 | selectedApps.remove(packageName) 215 | } 216 | 217 | fun setSearchWord(word: String?) { 218 | searchWord = word 219 | } 220 | } 221 | } 222 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightningcpu/Alertly/1f14d616ef39c642163b6d786fda6aa0c8f36d16/app/src/main/res/drawable/logo.jpg -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 |