android:通知

本文介绍了一个具体的Android应用程序如何创建并显示通知的过程。该应用通过获取用户输入的通知标题、内容及概要信息,并设置通知图标,创建了Notification实例。此外,还详细展示了如何使用Intent来定义点击通知后的操作,如拨打电话等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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);//发送通知
		
	}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值