我在代码中使用NotificationCompat ,可是NotificationCompat 老是出现横线,运行后也没有效果,我的android 版本是3.0.1import android.support.v4.app.NotificationCompat;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button sendNotice = (Button) findViewById(R.id.send_notice);
        sendNotice.setOnClickListener(this);
    }            public void onClick(View v) {
                switch (v.getId()){
                    case R.id.send_notice:
                        Intent intent=new Intent(this,NotificationActivity.class);
                        PendingIntent pi=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
                        NotificationManager manager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                       NotificationCompat.Builder builder=new NotificationCompat.Builder(this);
                       Notification notification=builder.setSmallIcon(R.mipmap.ic_launcher)
                                 .setContentTitle("this is content title")
                                 .setContentText("this is content text")
                                 .setWhen(System.currentTimeMillis())
                                 .setContentIntent(pi)
                                .setAutoCancel(true)
                             //   .setDefaults(NotificationCompat.DEFAULT_ALL)                                .build();
                        manager.notify(1,notification);
                        break;
                        default:
                            break;                }
            }

解决方案 »

  1.   

    现在Android开发最低适配4.4的,你手机版本不行
      

  2.   


    您是指的我的android studio版本不行还是我的手机版本不行呢。
      

  3.   


    您是指的我的android studio版本不行还是我的手机版本不行呢。
    我的android studio版本是3.0.1,手机版本是5.1
      

  4.   

     Notification.Builder mBuilder = new Notification.Builder(this);
      

  5.   

    不清楚,我给你一个我项目经常使用的Notification工具类,兼容高版本
    https://github.com/linglongxin24/NotificationUtil
      

  6.   

    Builder方法我这一直是不接受第二个参数,是什么问题呢??