我使用前台服务的方式,每隔1s写入一条数据到文件中,但是手机锁屏后,好像服务停止了
您的每一个用心回答,都会让这个世界变得更美好一些!
public int onStartCommand(Intent intent, int flags, int startId) { Intent notificationIntent = new Intent(this, NotificationActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); String id = "mNotification"; Notification notification = null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { notification = new Notification.Builder(this,id) .setContentTitle("getSignalStrength") .setContentText("我是信号检测软件,请不要关闭我") .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.icon)) .setSmallIcon(R.drawable.ic_baseline_event_note_24) .setContentIntent(pendingIntent) .build(); } // Notification ID cannot be 0. startForeground(110, notification); return super.onStartCommand(intent, flags, startId); }
这个要看系统版本,系统版本还不够行,还得看手机~~
你可以启动前提服务的同时给他加一个通知,类似音乐播放这种,通知在服务就不容易被杀。
这个要看系统版本,系统版本还不够行,还得看手机~~
你可以启动前提服务的同时给他加一个通知,类似音乐播放这种,通知在服务就不容易被杀。