当前位置:   article > 正文

关于Service使用startForeground()方法_startforegroundservice使用

startforegroundservice使用

这里需要记录一下startForeground使用的注意事项,示例代码来自于Repeater(RPT)源码 com.wudayu.repeater.services.PlayService,代码如下:

  1. public void useForeground(CharSequence tickerText, String currSong) {
  2. Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);
  3. PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0);
  4. /* Method 01
  5. * this method must SET SMALLICON!
  6. * otherwise it can't do what we want in Android 4.4 KitKat,
  7. * it can only show the application info page which contains the 'Force Close' button.*/
  8. NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(PlayService.this)
  9. .setSmallIcon(R.drawable.ic_launcher)
  10. .setTicker(tickerText)
  11. .setWhen(System.currentTimeMillis())
  12. .setContentTitle(getString(R.string.app_name))
  13. .setContentText(currSong)
  14. .se
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/464543
推荐阅读
相关标签
  

闽ICP备14008679号