首页 > 其他 > 详细

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

时间:2015-05-21 02:14:41      阅读:389      评论:0      收藏:0      [点我收藏+]

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图片,现在我们看下实现效果图


bubuko.com,布布扣

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

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


bubuko.com,布布扣

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

  • 短信发送系统

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

布局函数:


bubuko.com,布布扣


?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();
	}
}

?
?实现效果如下:


bubuko.com,布布扣
?
?
bubuko.com,布布扣

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

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

原文:http://429899791.iteye.com/blog/2212878

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!