File tree Expand file tree Collapse file tree
java/com/tomatodev/timerdroid/service Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,8 +6,8 @@ android {
66 applicationId " com.tomatodev.timerdroid"
77 minSdkVersion 18
88 targetSdkVersion 26
9- versionCode 1412300
10- versionName " 3.0 .0"
9+ versionCode 1412310
10+ versionName " 3.1 .0"
1111 testInstrumentationRunner " android.support.test.runner.AndroidJUnitRunner"
1212 vectorDrawables. useSupportLibrary = true
1313 }
Original file line number Diff line number Diff line change 55 <uses-permission android : name =" android.permission.VIBRATE" />
66 <uses-permission android : name =" android.permission.WAKE_LOCK" />
77 <uses-permission android : name =" android.permission.READ_EXTERNAL_STORAGE" />
8+ <uses-permission android : name =" android.permission.ACCESS_NOTIFICATION_POLICY" />
89
910 <application
1011 android : allowBackup =" true"
Original file line number Diff line number Diff line change @@ -200,7 +200,7 @@ public void startNotificationForFinishedTimer(String timerName){
200200
201201 // set alarm volume (API < 26)
202202 // TODO problem when 2 alarms go off after each other, will overwrite the system volume
203- if (Build . VERSION . SDK_INT < Build . VERSION_CODES . O ){
203+ if (canSetVolume () ){
204204 mVolumeBefore = audio .getStreamVolume (SOUND_STREAM );
205205 int max = audio .getStreamMaxVolume (SOUND_STREAM );
206206 int volume = (int ) Math .round (prefs .getInt ("alarm_volume" , 5 ) * 0.1 * max );
@@ -213,11 +213,26 @@ public void startNotificationForFinishedTimer(String timerName){
213213 }
214214
215215 public void cancelSoundNotification (){
216- // reset alarm volume
217- if (Build . VERSION . SDK_INT < Build . VERSION_CODES . O ){
216+ // reset alarm volume if allowed
217+ if (canSetVolume () ){
218218 mAudioManager .setStreamVolume (AudioManager .STREAM_ALARM , mVolumeBefore , 0 );
219219 mAudioManager .setRingerMode (mRingerModeBefore );
220220 }
221+
221222 mNotificationManager .cancel (NOTIFICATION_ID_FINISHED );
222223 }
224+
225+ private boolean canSetVolume (){
226+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
227+ return false ;
228+ }
229+
230+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
231+ if (!mNotificationManager .isNotificationPolicyAccessGranted ()) {
232+ return false ;
233+ }
234+ }
235+
236+ return true ;
237+ }
223238}
Original file line number Diff line number Diff line change 2020 <string name =" about_author_label" >Author</string >
2121 <string name =" about_author" translatable =" false" >Martin Hoffmann</string >
2222 <string name =" about_version_label" >Version</string >
23- <string name =" about_version" translatable =" false" >3.0 .0</string >
23+ <string name =" about_version" translatable =" false" >3.1 .0</string >
2424 <string name =" about_link" ><a href =" https://github.com/hoffimar/timerdroid" >Website</a ></string >
2525 <string name =" menu_about_button_text" >OK</string >
2626
You can’t perform that action at this time.
0 commit comments