现在的位置: 首页 > 综合 > 正文

Android打电话&发短信

2017年12月19日 ⁄ 综合 ⁄ 共 1411字 ⁄ 字号 评论关闭

 

  1. public void onCreate(Bundle savedInstanceState) {  
  2.     super.onCreate(savedInstanceState);  
  3.     setContentView(R.layout.main);  
  4.     mobileEditText = (EditText) this.findViewById(R.id.app_name);  
  5.     mobileButton = (Button) this.findViewById(R.id.button);  
  6.     mobileButton.setOnClickListener(new View.OnClickListener() {  
  7.           
  8.         @Override 
  9.             public void onClick(View v) {  
  10.             // TODO Auto-generated method stub  
  11.             String mobile = mobileEditText.getText().toString();  
  12.             Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+mobile));  
  13.             androidTest2Activity.this.startActivity(intent);  
  14.         }  
  15.     });  
  16. }  
  17. --------------------------------------------------------------------------------------  
  18.  
  19. public void onClick(View v) {  
  20.     // TODO Auto-generated method stub  
  21.     String mobile = mobileText.getText().toString();  
  22.     String content = contentText.getText().toString();  
  23.     SmsManager smsManager = SmsManager.getDefault();  
  24.     if(content.length()>70){  
  25.         List<String> contents=smsManager.divideMessage(content);  
  26.         for(String sms:contents){  
  27.             smsManager.sendTextMessage(mobile, null, sms, nullnull);  
  28.         }  
  29.     }  
  30.     else{  
  31.         smsManager.sendTextMessage(mobile, null, content, nullnull);  
  32.     }  
  33.     Toast.makeText(SMSActivity.this"发送成功"2).show();  
  34. }   
  35.  
  36.  

 

本文出自 “阿凡达” 博客,请务必保留此出处http://shamrock.blog.51cto.com/2079212/702527

抱歉!评论已关闭.