首页 > 学院 > 开发设计 > 正文

安卓之通知栏

2019-11-07 23:53:51
字体:
来源:转载
供稿:网友

通知栏,这个很好理解吧,不理解的加QQ592977585。 主要class:NotificationCompat(通知栏),然后在给它设置参数。根据你的需要来设置,再通知管理器 NotificationManager发送通知。一个简单的通知栏就完成了。它自带左右拖动可以清除。 直接上代码:

public class RingActivity extends AppCompatActivity { PRivate MediaPlayer mediaPlayer; private PendingIntent pendingIntent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ring); //显示通知栏 NotificationCompat.Builder notificationCompat=new NotificationCompat.Builder(this); //设置参数 notificationCompat.setDefaults(NotificationCompat.DEFAULT_ALL); notificationCompat.setContentTitle("闹钟"); notificationCompat.setContentText("一大波僵尸正在来袭"); notificationCompat.setSmallIcon(android.R.drawable.ic_lock_idle_alarm); Intent intent=new Intent(RingActivity.this,RingActivity.class); pendingIntent = PendingIntent.getBroadcast(RingActivity.this,0x101,intent,0); //notificationCompat.setDeleteIntent(pendingIntent); notificationCompat.setContentIntent(pendingIntent); Notification notification=notificationCompat.build(); //通知管理器 NotificationManager notificationManager= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); //发送通知 notificationManager.notify(0x101,notification); }} $(function () { $('pre.prettyprint code').each(function () { var lines = $(this).text().split('/n').length; var $numbering = $('').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表