转自:google搜索 android startForeground
如http://blog.csdn.net/yyingwei/article/details/8509402

运行一个service

    @Override    public void onDestroy() {        // Make sure our notification is gone.        stopForegroundCompat(R.string.system_message_title);        super.onDestroy();    }    @Override    public int onStartCommand(Intent intent, int flags, int startId) {        Builder builder = new Notification.Builder(this);          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, DeskSetting.class), 0);        builder.setContentIntent(pendingIntent)                .setSmallIcon(R.drawable.ic_launcher)// 设置状态栏里面的图标(小图标)                // .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.i5))//下拉下拉列表里面的图标(大图标)        //                 .setTicker("this is bitch!") //设置状态栏的显示的信息                .setOngoing(false)                .setOnlyAlertOnce(true)                .setShowWhen(false)                .setOnlyAlertOnce(true)                .setPriority(Notification.PRIORITY_MIN)                .setWhen(System.currentTimeMillis())// 设置时间发生时间                .setAutoCancel(true)// 设置可以清除                .setContentTitle(getText(R.string.fetion_launcher_started))// 设置下拉列表里的标题                .setContentText(getText(R.string.about_desk));// 设置上下文内容          Notification notification = builder.getNotification();        notification.flags = Notification.FLAG_ONGOING_EVENT;        notification.flags |= Notification.FLAG_NO_CLEAR;        notification.flags |= Notification.FLAG_FOREGROUND_SERVICE;        Log.d(TAG, "notification.flags " + notification.flags);        startForeground(3030, notification);//        startForegroundCompat(1166, notification);        mNM.cancel(3030);        return super.onStartCommand(intent, flags, startId);    }



PS:system应用的话,直接在AndroidManifest中的application标签加入android:persistent="true"就好

更多相关文章

  1. 【Flutter】修改图标、应用名称、包名等
  2. Android 4.0 对通知栏图标的尺寸有要求
  3. Android开发—利用FrameLayout实现图标中间显示文字
  4. Android SDK and AVD Manage图标没找到
  5. android每隔5s显示时间
  6. 关机充电图标
  7. Android中实现日期时间选择器(DatePicker和TimePicker)

随机推荐

  1. AndroidStudio打包出现问题: `Error:Exec
  2. Android复选框(CheckBox)的现实
  3. Android(安卓)Http请求失败解决方法
  4. Glide的with()方法和生命周期的源码分析
  5. Android(安卓)事件中 OnTouch 事件
  6. Android稳定性优化--概括
  7. Android-BLE低功耗蓝牙开发
  8. android获取屏幕大小
  9. 通过Setters方式对日期属性及日期格式进
  10. 仿PHP中文网右侧部分