02 - Android入门程序 电话与短信
来源:互联网 发布:软件退税政策 编辑:程序博客网 时间:2024/06/07 02:53
电话程序:
/phone/src/cn/itcast/phone/MainActivity.java
public class MainActivity extends Activity {/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);Button button = (Button) this.findViewById(R.id.button);button.setOnClickListener(new ButtonClickListener());}private final class ButtonClickListener implements View.OnClickListener {@Overridepublic void onClick(View v) {EditText mobileText = (EditText) findViewById(R.id.mobile);String number = mobileText.getText().toString();Intent intent = new Intent();intent.setAction("android.intent.action.CALL");//intent.addCategory("android.intent.category.DEFAULT");intent.setData(Uri.parse("tel:"+number));startActivity(intent);}}}
/phone/res/layout/main.xml 控制布局并定义元件
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/mobile" /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/mobile" /><Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button" android:id="@+id/button" /><!-- 添加一个常量 --></LinearLayout>
/phone/res/values/strings.xml
<?xml version="1.0" encoding="utf-8"?><resources> <string name="hello">Hello World, MainActivity!</string> <string name="app_name">电话拨号器</string> <string name="mobile">请输入手机号</string> <string name="button">请拨号</string> </resources>
/phone/AndroidManifest.xml
<!-- 添加拨打电话权限 系统安装的时候就会提示 --><uses-permission android:name="android.permission.CALL_PHONE"/>"
短信发送程序:
public class SmsActivity extends Activity {private EditText numberText;private EditText contentText;/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);numberText = (EditText) this.findViewById(R.id.number_text);contentText = (EditText) this.findViewById(R.id.content_text);Button sendButton = (Button) this.findViewById(R.id.send_button);sendButton.setOnClickListener(new ButtonClickListener());}private final class ButtonClickListener implements View.OnClickListener {@Overridepublic void onClick(View v) {String number = numberText.getText().toString();String content = contentText.getText().toString();SmsManager manager = SmsManager.getDefault();ArrayList<String> texts = manager.divideMessage(content);// 过大则拆分for (String text : texts) {manager.sendTextMessage(number, null, text, null, null);}Toast.makeText(getApplicationContext(), R.string.send_sucuess, 3).show(); }}}<uses-permission android:name="android.permission.SEND_SMS"/>
0 0
- 02 - Android入门程序 电话与短信
- Android入门(4) 电话拨打与发送短信
- Android开发入门之电话拨打与发送短信
- Android入门:短信和拨打电话
- Android 短信发送与拨打电话实现
- android 拨打电话与发送短信
- Android短信与电话:简易实例
- Android电话监听与短信监听
- android 拨打电话与发送短信
- Android 电话 短信
- Android电话、短信相关
- Android 电话,短信,录音
- Android拨打电话和发短信的简单程序
- Android电话及短信的监听程序源码
- Android 手机应用开发经验 之电话与短信服务
- Android 之 ACTION_CALL 拨打电话 与 发送短信
- android 添加菜单 开发流程 短信发送与拨打电话
- android 中电话记录,通讯录与短信的查询
- 使用JDK的javaagent机制时候,遇到的蛋疼无比的ClassNotFoundException
- [转]为什么你应该(从现在开始就)写博客
- linux clone
- gdb调试命令使用说明
- JUDE
- 02 - Android入门程序 电话与短信
- eclipse4.3及myeclipse10添加反编译插件
- 单链表的基本操作
- XCode工程内多Targets教程
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps
- 链式队列基本操作之code_legend
- XTU OJ 1210 Happy Number (暴力+打表)
- No embedded stylesheet instruction for file
- python3实现域名查询和whois查询