Skip to content

Commit e116717

Browse files
committed
🔨 FIX: 通知へのアクセス許可がない場合、権限管理画面に遷移するように変更。
1 parent 43617c0 commit e116717

5 files changed

Lines changed: 24 additions & 5 deletions

File tree

AndroidApp/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ dependencies {
4444
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
4545
implementation 'androidx.core:core-ktx:1.1.0'
4646
implementation 'androidx.appcompat:appcompat:1.1.0'
47-
implementation 'com.google.android.material:material:1.0.0'
47+
implementation 'com.google.android.material:material:1.3.0'
4848
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
4949
implementation 'androidx.navigation:navigation-fragment-ktx:2.1.0'
5050
implementation 'androidx.navigation:navigation-ui-ktx:2.1.0'

AndroidApp/app/src/main/java/me/nya_n/notificationnotifier/views/activities/MainActivity.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package me.nya_n.notificationnotifier.views.activities
22

3+
import android.content.Intent
34
import android.os.Bundle
5+
import android.provider.Settings
6+
import androidx.appcompat.app.AlertDialog
47
import androidx.appcompat.app.AppCompatActivity
8+
import androidx.core.app.NotificationManagerCompat
59
import me.nya_n.notificationnotifier.R
610

711
class MainActivity : AppCompatActivity() {
@@ -10,5 +14,21 @@ class MainActivity : AppCompatActivity() {
1014
super.onCreate(savedInstanceState)
1115
setContentView(R.layout.activity_main)
1216
setSupportActionBar(findViewById(R.id.toolbar))
17+
permissionCheck()
18+
}
19+
20+
private fun permissionCheck() {
21+
if (NotificationManagerCompat.getEnabledListenerPackages(this)
22+
.contains(packageName)) {
23+
return
24+
}
25+
AlertDialog.Builder(this)
26+
.setMessage(R.string.require_permission)
27+
.setPositiveButton(R.string.next) { _, _ ->
28+
Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS).apply {
29+
startActivity(this)
30+
}
31+
}
32+
.show()
1333
}
1434
}

AndroidApp/app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
android:id="@+id/toolbar"
1717
android:layout_width="match_parent"
1818
android:layout_height="?attr/actionBarSize"
19-
android:background="?attr/colorPrimary"
20-
app:popupTheme="@style/AppTheme.PopupOverlay" />
19+
android:background="?attr/colorPrimary" />
2120

2221
</com.google.android.material.appbar.AppBarLayout>
2322

AndroidApp/app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@
1313
<string name="notify_test">通知テスト</string>
1414
<string name="loading">読み込み中</string>
1515
<string name="search_by_app_name">アプリ名で検索</string>
16+
<string name="next">[次へ]</string>
17+
<string name="require_permission">次の画面で「通知へのアクセス」を許可してください。</string>
1618
</resources>

AndroidApp/app/src/main/res/values/styles.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,4 @@
1414

1515
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
1616

17-
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
18-
1917
</resources>

0 commit comments

Comments
 (0)