新的效果,在android5.0以后可以使用
直接上代码:
public class MainActivity extends AppCompatActivity { Context myContext; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button_1=findViewById(R.id.bt_1); Button button_2=findViewById(R.id.bt_2); button_1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { NotificationManager mNotificationManager = (NotificationManager) myContext.getSystemService(NOTIFICATION_SERVICE); long when = System.currentTimeMillis(); Notification notification = new Notification(R.mipmap.ic_launcher, "110", when); notification.flags = Notification.FLAG_ONGOING_EVENT; notification.flags = Notificat