1 package com.android.cts.verifier.bluetooth; 2 3 import android.app.Notification; 4 import android.app.NotificationChannel; 5 import android.app.NotificationManager; 6 import android.app.Service; 7 import android.content.Context; 8 import android.content.Intent; 9 import android.os.IBinder; 10 import com.android.cts.verifier.R; 11 12 public class FocusLossPreventionService extends Service { 13 14 public static final String TAG = "FocusLossPreventionService"; 15 16 private static final String NOTIFICATION_CHANNEL_ID = "ctsVerifier/" + TAG; 17 18 @Override onCreate()19 public void onCreate() { 20 super.onCreate(); 21 } 22 23 @Override onStartCommand(Intent intent, int flags, int startId)24 public int onStartCommand(Intent intent, int flags, int startId) { 25 Context context = getApplicationContext(); 26 String title = getResources().getString(R.string.app_name); 27 String channelId = "default"; 28 29 NotificationManager notificationManager = getSystemService(NotificationManager.class); 30 31 if (notificationManager != null) { 32 notificationManager.createNotificationChannel( 33 new NotificationChannel( 34 NOTIFICATION_CHANNEL_ID, 35 NOTIFICATION_CHANNEL_ID, 36 NotificationManager.IMPORTANCE_DEFAULT)); 37 38 Notification notification = 39 new Notification.Builder(context, NOTIFICATION_CHANNEL_ID) 40 .setContentTitle(title) 41 .setSmallIcon(android.R.drawable.stat_sys_data_bluetooth) 42 .build(); 43 44 startForeground(1, notification); 45 } 46 47 return START_NOT_STICKY; 48 } 49 50 @Override onDestroy()51 public void onDestroy() { 52 super.onDestroy(); 53 stopForeground(true /* removeNotification */); 54 } 55 56 @Override onBind(Intent intent)57 public IBinder onBind(Intent intent) { 58 return null; 59 } 60 } 61