第一行代码 第二版 前台服务 Android(安卓)8.0开发代码修改
16lz
2022-07-23
@Overridepublic void onCreate() { super.onCreate(); Log.d("MyService", "onCreate executed"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel("fore_service", "前台服务", NotificationManager.IMPORTANCE_HIGH); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.createNotificationChannel(channel); Intent intentForeSerive = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intentForeSerive, 0); Notification notification = new NotificationCompat.Builder(this, "fore_service") .setContentTitle("This is content title") .setContentText("This is content text") .setWhen(System.currentTimeMillis()) .setSmallIcon(R.mipmap.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) .setContentIntent(pendingIntent) .build(); startForeground(1, notification); }}
更多相关文章
- 浅析android通过jni控制service服务程序的简易流程
- Android(安卓)Service AIDL
- Android架构分析之使用自定义硬件抽象层(HAL)模块
- android 定位服务
- 【安卓笔记】android客户端与服务端交互的三种方式
- android手机客户端上传文件,java servlet服务器端接收并保存到服
- android 定位服务
- Android例子—直接通过Binder的onTransact完成跨进程通信
- Android(安卓)启动过程(2)