我在代码中使用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; }
}
。
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; }
}
您是指的我的android studio版本不行还是我的手机版本不行呢。
您是指的我的android studio版本不行还是我的手机版本不行呢。
我的android studio版本是3.0.1,手机版本是5.1
https://github.com/linglongxin24/NotificationUtil