码迷,mamicode.com
首页 > 其他好文 > 详细

打电话和发短信

时间:2015-02-04 00:45:47      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:position   public   parent   短信   电话   

一,拨打电话

 

 

  lv.setOnItemClickListener(new OnItemClickListener() {

 

                              @Override

                              public void onItemClick(AdapterView<?> parent, View view,

                                                  int position, long id) {

                                        //添加意图

                                        Intent intent = new Intent();

                                        //添加动作

                                        intent.setAction(intent.ACTION_CALL);

                                        //添加数据

                                        intent.setData(Uri.parse("tel:"+phones[position]));

                                        startActivity(intent);

                              }

                    });

注意:添加拨打电话的权限

 

 

三,发送短信

lv.setOnItemLongClickListener(new OnItemLongClickListener() {

 

                              @Override

                              public boolean onItemLongClick(AdapterView<?> parent, View view,

                                                  int position, long id) {

                                         

                                         Intent i=new Intent(getApplicationContext(), SmsActivity.class);

                                         i.putExtra("number", phones[position]);

                                         startActivity(i);

                                         

                                        return true;

                              }

                    });

注意:短信的权限

作为初学者,增加权限最容易忘记了

本文出自 “xmy” 博客,请务必保留此出处http://88649164.blog.51cto.com/9890093/1611274

打电话和发短信

标签:position   public   parent   短信   电话   

原文地址:http://88649164.blog.51cto.com/9890093/1611274

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!