android小功能实现之发送短信
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了android小功能实现之发送短信,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2110字,纯文字阅读大概需要4分钟。
内容图文
新建一个Android工程。一 布局
打开main.xml修改内容如下:
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/number" /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="text" android:id="@+id/number"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/content" /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="text" android:minLines="3" android:id="@+id/content"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button" android:id="@+id/button" />
如图:
二 定义字符串
打开strings.xml添加内容如下:
<string name="number">请输入手机号</string> <string name="content">请输入短信内容</string> <string name="button">发送短信</string> <string name="success">发送成功</string>
三 响应点击事件
打开MainActivity.java,添加如下代码:
public EditText numberText; public EditText contentText; public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); numberText = (EditText)this.findViewById(R.id.number); contentText = (EditText)this.findViewById(R.id.contentText); Button button = (Button) this.findViewById(R.id.button); button.setOnClickListener(new ButtonClickListener()); } private final class ButtonClickListener implements View.OnClickListener{ public void onClick(View v){ String number = numberText.getText().toString(); String content = contentText.getText().toString(); SmsManager manger = SmsManager.getDefault(); //分割短信字数,如果多余36字分条发送 ArrayList<String> texts=manger.divideMessage(content); for(String text:texts){ // 参数:号码,中心地址,内容,发送状态,对方是否收到状态 manger.sendTextMessage(number, null, text, null, null); } //短信发送完毕,通知用户 Toast.makeText(getApplicationContext(), R.string.success, Toast.LENGTH_LONG).show(); } }
四 添加权限
在Manifest.xml中添加权限:
<uses-permission android:name="android.permission.SEND_SMS"/>
原文:http://blog.csdn.net/xufeng0991/article/details/43983303
内容总结
以上是互联网集市为您收集整理的android小功能实现之发送短信全部内容,希望文章能够帮你解决android小功能实现之发送短信所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。