Create notification channel on Application subclass
app/src/main/AndroidManifest.xml
6 | 6 | <uses-permission android:name="android.permission.INTERNET" /> | |
7 | 7 | ||
8 | 8 | <application | |
9 | + | android:name=".App" | |
9 | 10 | android:allowBackup="true" | |
10 | 11 | android:icon="@mipmap/ic_launcher" | |
11 | 12 | android:label="@string/app_name" |
app/src/main/java/eu/lepiller/nani/App.java unknown status 1
1 | + | package eu.lepiller.nani; | |
2 | + | ||
3 | + | import android.app.Application; | |
4 | + | import android.app.NotificationChannel; | |
5 | + | import android.app.NotificationManager; | |
6 | + | ||
7 | + | public class App extends Application { | |
8 | + | public static final String DICTIONARY_DOWNLOAD_NOTIFICATION_CHANNEL = "dictionaryDownloadChannel"; | |
9 | + | ||
10 | + | @Override | |
11 | + | public void onCreate() { | |
12 | + | super.onCreate(); | |
13 | + | ||
14 | + | createNotificationChannel(); | |
15 | + | } | |
16 | + | ||
17 | + | private void createNotificationChannel() { | |
18 | + | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { | |
19 | + | NotificationChannel channel = new NotificationChannel(DICTIONARY_DOWNLOAD_NOTIFICATION_CHANNEL, | |
20 | + | "Nani's dictionary download notification", NotificationManager.IMPORTANCE_DEFAULT); | |
21 | + | ||
22 | + | NotificationManager manager = | |
23 | + | (NotificationManager) getSystemService(NOTIFICATION_SERVICE); | |
24 | + | if(manager != null) | |
25 | + | manager.createNotificationChannel(channel); | |
26 | + | } | |
27 | + | } | |
28 | + | } |
app/src/main/java/eu/lepiller/nani/MainActivity.java
55 | 55 | ||
56 | 56 | Button radical_button = findViewById(R.id.radical_button); | |
57 | 57 | ||
58 | - | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { | |
59 | - | NotificationChannel channel = new NotificationChannel("dico_dll", | |
60 | - | "Nani's dictionary download notification", NotificationManager.IMPORTANCE_DEFAULT); | |
61 | - | NotificationManager manager = | |
62 | - | (NotificationManager) getSystemService(NOTIFICATION_SERVICE); | |
63 | - | if(manager != null) | |
64 | - | manager.createNotificationChannel(channel); | |
65 | - | } | |
66 | - | ||
67 | 58 | PreferenceManager.setDefaultValues(this, R.xml.preferences, false); | |
68 | 59 | ||
69 | 60 | SharedPreferences sharedPref = |