模拟qq发送通告信息提示;自己的短信发送系统

本文详细介绍了如何使用Android平台上的Notification类和SmsManager类来模拟QQ消息提示功能以及实现短信发送功能。通过创建PendingIntent对象并设置Notification,用户可以直接在设备的通知栏接收到模拟的消息提示。同时,通过短信发送系统的实现,用户可以了解短信发送的基本流程。文章还提供了实现的效果图,帮助读者直观理解各个功能的实现过程。

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

qq收到信息后,总会在标题栏以上通知窗口通知你,这是怎么做到的呢,接下来我们来学习一个

发送通知:Notification

用户可直接使用android.app.Notification  android.app.NotificationManager;

这两个进行消息管理,这里我们来实现一个模拟qq消息提示功能。

这里不需用到界面

直接

Activity:

public class MyNotificationDemo extends Activity {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		super.setContentView(R.layout.main);
		NotificationManager notificationManager = (NotificationManager) super
				.getSystemService(Activity.NOTIFICATION_SERVICE);
		Notification notification = new Notification(R.drawable.a1,
				"您的好友", System.currentTimeMillis()); // 立刻发送一个消息
		PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
				super.getIntent(), PendingIntent.FLAG_UPDATE_CURRENT); // 创建了一个PendingIntent对象
		notification.setLatestEventInfo(this, "TJ",
				"去哪里吃饭啊", contentIntent);
		notificationManager.notify("qq", R.drawable.a1, notification);
	}
}

 这里准备好了qq图片,现在我们看下实现效果图


最上面的qq萌萌图标就是我们放置的

现在下拉消息提示框看看:


是不是可以以假乱真啊,成功骗过舍友,开心get,虽然是个简单的小功能,却体验了一些知名软件一点点小小功能的组成,相信当小小学完就是大大的你

  • 短信发送系统

之前用intent调用了短信系统,现在我们来自我实现

布局函数:



 Activity:

public class MySMSDemo extends Activity {
	String content =null;
	EditText edit=null;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		super.setContentView(R.layout.main);
		edit=(EditText)super.findViewById(R.id.edit);
		
		
	}
	public void send(View v){
		content=edit.getText().toString();
		SmsManager smsManager = SmsManager.getDefault();
		PendingIntent sentIntent = PendingIntent.getActivity(this, 0,
				super.getIntent(), PendingIntent.FLAG_UPDATE_CURRENT);
		if (content.length() > 70) { // 大于70个字,拆分
			List<String> msgs = smsManager.divideMessage(content); // 拆分
			Iterator<String> iter = msgs.iterator();
			while (iter.hasNext()) {
				String msg = iter.next();
				smsManager.sendTextMessage("10086", null, msg, sentIntent, null);
			}
		} else {
			smsManager.sendTextMessage("18229875477", null, content, sentIntent, null);
		}
		Toast.makeText(this, "短信发送完成", Toast.LENGTH_SHORT).show();
	}
}

 
 实现效果如下:



 
 

这里成功完成了发送,遗憾的是无法显示你发送了什么,你可以自己设立已发送的功能模块

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值