每天进步一点点~~~~~~~~ww.blog.chinaunix.net
superior_2008
全部博文(322)
2013年(5)
2012年(66)
2011年(87)
2010年(164)
小雅贝贝
wylhisto
split_tw
zyhualov
jcodeer
Unixtom9
wang2kk
格伯纳
Phyllis6
浪花小雨
tejorge
imliuqun
15107126
iOSrever
XPhenix
lstfyt
分类: Java
2010-12-31 11:07:55
一、拨号器
PhoneActivity.java
package com.wp.activity; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; public class PhoneActivity extends Activity { private EditText mobileText; private Button button; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mobileText = (EditText) this.findViewById(R.id.mobile); button = (Button) this.findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { String mobile = mobileText.getText().toString(); Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + mobile)); PhoneActivity.this.startActivity(intent); } }); } }
Xml代码
二、短信发送器
SMSActivity.java
Java代码
package org.wp.activity; import java.util.List; import android.app.Activity; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class SMSActivity extends Activity { private EditText mobileText; private EditText contentText; private Button button; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mobileText = (EditText) findViewById(R.id.mobile); contentText = (EditText) findViewById(R.id.content); button = (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { String mobile = mobileText.getText().toString(); String content = contentText.getText().toString(); SmsManager smsManager = SmsManager.getDefault(); if (content.length() > 70) { List contents = smsManager.divideMessage(content); for (String sms : contents) { smsManager.sendTextMessage(mobile, null, sms, null, null); } } else { smsManager.sendTextMessage(mobile, null, content, null, null); } Toast.makeText(SMSActivity.this, R.string.info, Toast.LENGTH_SHORT).show(); } }); } }
上一篇:关于 XML standalone 的解释
下一篇:Android学习笔记(二)
chinaunix网友2011-01-03 16:15:10
很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com
登录 注册