1.消息提醒功能:
public class NotifyTest {
public static final int ID=1;
private List<Homework>list;
private Context context;
private HomeworkDto dto;
public NotifyTest(Context context,List<Homework> list) {
super();
this.list = list;
this.context=context;
}
public void addNotificaction() {
NotificationManager manager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
// 创建一个Notification
Notification notification = new Notification();
notification.icon = R.drawable.notify;// 设置显示在手机最上边的状态栏的图标
notification.tickerText = "亲,你有信息啦~~~"; // 当前的notification被放到状态栏上的时候,提示内容
notification.defaults=Notification.DEFAULT_SOUND;// 添加声音提示
notification.audioStreamType= android.media.AudioManager.ADJUST_LOWER;//audioStreamType的值必须AudioManager中的值,代表着响铃的模式
Intent intent = new Intent(context, HomeworkActivity.class);//从一个activity跳到另外一个activity
Bundle mBundle = new Bundle();
dto=new HomeworkDto(list);
mBundle.putSerializable("homework", dto);
intent.putExtras(mBundle);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);
// 点击状态栏的图标出现的提示信息设置
notification.setLatestEventInfo(context, "通知:", "你最近有"+list.size()+"个作业要交,点击查看", pendingIntent);
manager.notify(ID, notification);
}
2.拨打电话功能:
listView.setOnItemClickListener(new OnItemClickListener() {//监听点击事件
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
String string_phoneNum =numberList.get(arg2).getNumber();//得到电话号码
Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+string_phoneNum));//调用系统拨打电话服务
startActivity(intent);//
}
});
本文介绍了如何在Android平台上实现消息提醒功能和拨打电话的功能。首先,详细讲解了利用Notification API创建和显示消息提醒的过程,包括设置通知的标题、内容、图标以及触发行为。接着,阐述了使用Intent和ACTION_CALL权限来启动电话拨打界面的方法,确保用户能够顺利拨出电话。这两个功能在许多Android应用中都具有实用价值。
2707

被折叠的 条评论
为什么被折叠?



