打电话和发短信

一,拨打电话

 

 

  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;

                              }

                    });

注意:短信的权限

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章