|
1 | 1 | package jwf.debugport; |
2 | 2 |
|
3 | 3 | import android.app.Notification; |
| 4 | +import android.app.NotificationChannel; |
| 5 | +import android.app.NotificationManager; |
4 | 6 | import android.app.PendingIntent; |
5 | 7 | import android.app.Service; |
6 | 8 | import android.content.Context; |
|
9 | 11 | import android.content.pm.PackageManager; |
10 | 12 | import android.content.res.Resources; |
11 | 13 | import android.os.AsyncTask; |
| 14 | +import android.os.Build; |
12 | 15 | import android.os.Bundle; |
13 | 16 | import android.os.IBinder; |
14 | 17 | import android.os.PowerManager; |
|
27 | 30 | */ |
28 | 31 | public class DebugPortService extends Service { |
29 | 32 | private static final String TAG = "DebugPortService"; |
| 33 | + private static final String NOTIFICATION_CHANNEL = "androiddebugport"; |
30 | 34 | public static final String METADATA_DEBUG_PORT = "jwf.debugport.METADATA_DEBUG_PORT"; |
31 | 35 | public static final String METADATA_SQLITE_PORT = "jwf.debugport.METADATA_SQLITE_PORT"; |
32 | 36 | public static final String METADATA_STARTUP_COMMANDS = "jwf.debugport.METADATA_STARTUP_COMMANDS"; |
@@ -163,6 +167,11 @@ public void onDestroy() { |
163 | 167 | } |
164 | 168 |
|
165 | 169 | private Notification buildNotification(@Nullable Params params) { |
| 170 | + NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); |
| 171 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
| 172 | + mgr.createNotificationChannel(new NotificationChannel(NOTIFICATION_CHANNEL, getString(R.string.debugport_notification_channel_name), NotificationManager.IMPORTANCE_MIN)); |
| 173 | + } |
| 174 | + |
166 | 175 | if (params == null) { |
167 | 176 | params = getManifestParams(this); |
168 | 177 | } |
@@ -191,6 +200,7 @@ private Notification buildNotification(@Nullable Params params) { |
191 | 200 | builder.setContentText(message); |
192 | 201 | builder.addAction(mServersStarted ? buildStopAction() : buildStartAction(params)); |
193 | 202 | builder.addAction(buildKillAction()); |
| 203 | + builder.setChannelId(NOTIFICATION_CHANNEL); |
194 | 204 |
|
195 | 205 | return builder.build(); |
196 | 206 | } |
|
0 commit comments