android:通知

来源:互联网 发布:秃鹰配件名称及数据 编辑:程序博客网 时间:2024/05/22 10:42

android程序代码片段:

public void onClick(View v) {EditText tv_shorttile = (EditText)findViewById(R.id.tv_shorttile);//通知的概要EditText et_title = (EditText)findViewById(R.id.et_title);//通知的标题EditText et_content = (EditText)findViewById(R.id.et_content);//通知的内容String shorttile = tv_shorttile.getText().toString();String title = et_title.getText().toString();String content = et_content.getText().toString();int icon = R.drawable.ic_launcher;Notification notification = new Notification(icon,shorttile,System.currentTimeMillis());//创建通知的类Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:110"));//这是点击通知后要做的事情,可以启动Activity//Intent intent = new Intent(this,TestActivity.class);PendingIntent pIntent = PendingIntent.getActivity(this, 10, intent, 0);//创建Intent描述,别的程序会通过这个描述启动要做的事情//PendingIntent.getBroadcast(context, requestCode, intent, flags);//从广播启动//PendingIntent.getService(context, requestCode, intent, flags);//从服务中启动notification.setLatestEventInfo(this, title, content, pIntent);notification.defaults = Notification.DEFAULT_SOUND;notification.flags = Notification.FLAG_AUTO_CANCEL;NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);//获取通知管理器manager.notify(100, notification);//发送通知}


0 0
原创粉丝点击