Android O不显示前置服务通知

时间:2017-06-22 14:57:12

标签: android-8.0-oreo

根据文档,我在应用程序中进行了更改,以便使用context.startForegroundService(Intent)在后​​台启动服务,然后像以前一样在服务中调用startForeground

NotificationCompat.Builder notification = new 
NotificationCompat.Builder(getApplicationContext())
            .setSmallIcon(R.mipmap.icon)
            .setContentText("Content")
            .setOngoing(true)
            .setContentInfo("Info")
            .setContentTitle("Title");
startForeground(1, notification.build());

这会在Android N设备上正确显示通知,但在Android O设备上,它不会显示通知,只显示新的"正在后台运行...点击了解有关电池和数据使用情况的详细信息"

是否缺少某些内容才能在Android O上正确显示通知?

2 个答案:

答案 0 :(得分:3)

上面的答案对我不起作用。您必须创建频道才能工作,然后传递频道ID。

new NotificationCompat.Builder(this, channelId)

然后使用相同的cannelId

创建一个notfication
add_shortcode('bookmaker', 'bookmaker_shortcode_query');

function bookmaker_shortcode_query($atts, $content){
  $args = shortcode_atts(array( // a few default values
   'posts_per_page' => '1',
   'post_type' => 'your_custom_post_type',
   'p' => '1',
   'caller_get_posts' => 1)
   , $atts);


  global $post;

  $posts = new WP_Query($args);
  $output = '';
    if ($posts->have_posts())
        while ($posts->have_posts()):
            $posts->the_post();
            $out = '        <div class="bookmaker">
        <div class="bookmakerinner">



            <div class="afbeeldingbm">
            <div class="afbeeldingbminner">
                <a target="_blank" href="'.get_post_meta($post->ID, 'claimlink', true).'">
                '.get_the_post_thumbnail().'
                </a>
            </div>
            </div>

            <div class="rightbm">

            <h4>'.get_the_title() .'</h4>

            <div class="stars">
                <p><img src="https://bonusbookmakers.nl/wp-content/themes/Parbosnack/stars/'.get_post_meta($post->ID, 'stars', true).'.png"></p>
            </div>

            <div class="voorwaarden">
                <strong class="bolder">Voorwaarden:</strong> '.get_the_content().'
            </div>

            <div class="maxeur">
                <p><strong class="bolder">Max:</strong> &euro;'.get_post_meta($post->ID, 'maxeur', true).'</p>
            </div>

            <div class="maxbonus">
                <p><strong class="bolder">Bonus:</strong> '.get_post_meta($post->ID, 'maxbonus', true).'%</p>
            </div>

            <div class="odds">
                <p><strong class="bolder">Odds:</strong> '.get_post_meta($post->ID, 'odds', true).'</p>
            </div>

            <div class="lang">
                <p><strong class="bolder">Taal:</strong> '.get_post_meta($post->ID, 'taal', true).'</p>
            </div>

            <div class="priceclaimrow"> 

            <div class="betaalmethodes">
                <p>'.get_post_meta($post->ID, 'betaalmethodes', true).'</p>
            </div>

            <div class="visitwebsite">
                <p><a target="_blank" class="knpbezoeksite" href="'.get_post_meta($post->ID, 'claimlink', true).'">Bonus claimen</a></p>
            </div>

            </div>

            </div>

        </div>

                ';
            $out .='</div>';
    endwhile;
  else
    return; // no posts found

  wp_reset_query();
  return html_entity_decode($out);
}

答案 1 :(得分:2)

是的,使用频道作为{{1}}类的构造函数参数。