Android实现短信息发送
来源:互联网 发布:横幅飘窗java 编辑:程序博客网 时间:2024/06/10 06:14
对于短信发送器的实现,也是较简单的,总体来说只需要设置好布局文件和Activity类就可以了,但在此基础上,还需要进行对配置文件的设置,下面就让我们来进行演示:
在创建好项目之后,配置布局文件代码如下所示:
其中使用了组件AutoCompleteTextView组件,能够有提示的出现语句,在这儿我们用于提示电话号码,比如输入188时,再输入1时就会有提示188这个电话号码,在内容输入区,我们使用一个文本编辑框进行信息内容的传送,最后来一个发送按钮就可以完成布局了
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.wusu.android_002_Message.MainActivity" > <AutoCompleteTextView android:id="@+id/editText_receive" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginTop="5dp" android:inputType="number" android:hint="@string/Input_number_of_receive" android:ems="10" /> <EditText android:id="@+id/editText_content" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_above="@+id/button_send" android:layout_alignRight="@+id/editText_receive" android:layout_below="@id/editText_receive" android:ems="10" android:layout_marginTop="10dp" android:hint="@string/Input_content" android:gravity="top" android:inputType="textMultiLine" > <requestFocus /> </EditText> <Button android:id="@+id/button_send" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignRight="@+id/editText_content" android:layout_marginBottom="36dp" android:layout_marginRight="14dp" android:text="@string/send" /></RelativeLayout>在写完布局之后,我们进行Activity类的编写,主要代码如下所示:
public class MainActivity extends Activity implements OnClickListener {private Button button_send;private TextView textView_content,textView_receive; private AutoCompleteTextView autoCompleteTextView_number;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);button_send=(Button) findViewById(R.id.button_send); button_send.setOnClickListener(this);textView_content=(TextView) findViewById(R.id.editText_content);textView_receive=(TextView) findViewById(R.id.editText_receive); autoCompleteTextView_number=(AutoCompleteTextView) findViewById(R.id.editText_receive); ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,numbers); autoCompleteTextView_number.setAdapter(adapter);}//显示要提示的电话号码 private String[] numbers={"1880","150","1008611","10086","151","1234567890","9876543210","725610987678","226610"}; @Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {// Handle action bar item clicks here. The action bar will// automatically handle clicks on the Home/Up button, so long// as you specify a parent activity in AndroidManifest.xml.int id = item.getItemId();if (id == R.id.action_settings) {finish();return true;}return super.onOptionsItemSelected(item);}@Overridepublic void onClick(View view) {switch (view.getId()) {case R.id.button_send:String content=textView_content.getText().toString();String number=textView_receive.getText().toString();if(TextUtils.isEmpty(number)){Toast.makeText(MainActivity.this,"请输入电话号码...", Toast.LENGTH_SHORT).show(); return;}else{SmsManager smsManager=SmsManager.getDefault();ArrayList<String> contents=smsManager.divideMessage(content);for(String str:contents){smsManager.sendTextMessage(number,null, str, null, null); }Toast.makeText(this, "已发送", Toast.LENGTH_SHORT).show();}break;default:break;}}}
</pre><p></p><pre>现在,在进行配置文件,只需在配置文件中添加即可
<uses-permission android:name="android.permission.SEND_SMS"/>
以上就是Android中短信息发送功能的实现
1 0
- Android实现短信息发送
- GSM模块实现中文短信息发送
- android系统发送短信息代码
- 短信息发送
- 短信息发送
- 短信息发送
- Android SmsManager(短信管理器),发送短信息
- cmpp发送超长短信息
- cmpp发送超长短信息
- Visual C#发送短信息
- cmpp发送超长短信息
- cmpp发送超长短信息
- tc351i 发送短信息 代码
- cmpp发送超长短信息
- PDU格式发送短信息
- smsManager.sendTextMessage() 发送短信息
- Android 发送短息
- 使用J2ME发送手机短信息
- 【华为OJ】【046-成绩排序】
- 【华为OJ】【047-百钱买百鸡问题】
- 【华为OJ】【048-参数解析】
- HDU2141
- Iterator
- Android实现短信息发送
- 【华为OJ】【049-尼科彻斯定理】
- 【华为OJ】【050-整形数组合并】
- 第7周 C语言程序设计(新2版) 例题1.7 函数
- JSP标签库大全jsp常用的指令与标签
- FPGA:下一代机器人感知处理器
- Android视频播放器中的播放与暂停
- 欢迎使用CSDN-markdown编辑器
- hdu 2523 水