0
  • 最佳答案
    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);
    }
    
    
    1493134649726197762  评论     打赏       erxiong3344
    • erxiong3344  回复 @erxiong3344
      我觉得我使用前台服务的代码,没错呀,并且也在功能清单文件中声明了权限,但就是一锁屏,就无法向文件中读写数据
      erxiong3344 2022-03-08 07:05:11   回复 1493134649726197762
  • 这个要看系统版本,系统版本还不够行,还得看手机~~

    你可以启动前提服务的同时给他加一个通知,类似音乐播放这种,通知在服务就不容易被杀。

    1139423796017500160  评论     打赏       断点-含光君
    • erxiong3344  回复 @断点-含光君
      但是好像不好使呀
      erxiong3344 2022-03-08 07:03:20   回复 1493134649726197762
    • erxiong3344  回复 @断点-含光君
      public int onStartCommand(Intent intent, int flags, int startId) { Intent notificationIntent = new Intent(this, NotificationActivity.class); PendingIntent pendingIntent =
      erxiong3344 2022-03-08 07:03:23   回复 1493134649726197762
相关问题
kissmyass · 安卓
2019-12-11 04:41 713 2
珂珂范范 · 安卓
2019-12-19 00:59 559 2
2020-01-31 00:31 693 2
谁都不许动我的砖 · 安卓 / xml
2020-02-05 19:16 1184 2
谁都不许动我的砖 · 安卓
2020-02-06 06:24 764 2
珂珂范范 · 安卓模拟器
2020-02-21 11:10 842 2
珂珂范范 · 安卓
2020-02-29 23:50 429 2
mercenary · 安卓
2020-03-22 02:34 358 2
哦豁! · 安卓报错
2020-03-22 23:17 684 4
Pancica · 安卓
2020-03-23 02:13 520 2
Pancica · 安卓
2020-03-30 08:22 452 2
kuro · 安卓
2020-04-04 00:17 417 4