欧美日韩不卡一区二区三区,www.蜜臀.com,高清国产一区二区三区四区五区,欧美日韩三级视频,欧美性综合,精品国产91久久久久久,99a精品视频在线观看

短信

Android實(shí)現(xiàn)發(fā)短信和彩信功能

時(shí)間:2021-07-31 10:12:04 短信 我要投稿

Android實(shí)現(xiàn)發(fā)短信和彩信功能

  首先 activity_main.xml 布局:

  <RelativeLayout xmlns:android="/apk/res/android"

  xmlns:tools="/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=".SmsActivity" >

  <TextView

  android:id="@+id/phone_lable"

  android:layout_width="wrap_content"

  android:layout_height="wrap_content"

  android:layout_alignParentTop="true"

  android:layout_marginTop="23dp"

  android:text="@string/phon_lable" />

  <EditText

  android:id="@+id/edit_phone"

  android:layout_width="match_parent"

  android:layout_height="wrap_content"

  android:layout_below="@+id/phone_lable"

  android:layout_centerHorizontal="true"

  android:ems="10"

  android:inputType="phone" >

  

  <TextView

  android:id="@+id/sms_lable"

  android:layout_width="wrap_content"

  android:layout_height="wrap_content"

  android:layout_alignLeft="@+id/edit_phone"

  android:layout_below="@+id/edit_phone"

  android:layout_marginTop="22dp"

  android:text="@string/sms_lable" />

  <Button

  android:id="@+id/But_sms"

  android:layout_width="wrap_content"

  android:layout_height="wrap_content"

  android:layout_alignLeft="@+id/edit_sms"

  android:layout_alignParentBottom="true"

  android:layout_marginBottom="14dp"

  android:text="@string/But_sms" />

  <EditText

  android:id="@+id/edit_sms"

  android:layout_width="match_parent"

  android:layout_height="wrap_content"

  android:layout_above="@+id/But_sms"

  android:layout_alignLeft="@+id/sms_lable"

  android:ems="10"

  android:inputType="textMultiLine" />

  

  然后在AndroidManifest.xml 中添加 發(fā)送短信的權(quán)限:

  

  接下來就是SmsActivity 中 主要代碼 的實(shí)現(xiàn) 其功能 :

  public class SmsActivity extends Activity {

  // 聲明控件對(duì)象

  private Button butten_sms;

  private EditText edit_phone;

  private EditText edit_sms;

  @Override

  protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  //設(shè)置顯示視圖

  setContentView(yout.activity_sms);

  //獲取按鈕組件

  butten_sms=(Button) findViewById(R.id.But_sms);

  //獲取輸入框組件

  edit_phone = (EditText) findViewById(R.id.edit_phone);

  edit_sms = (EditText) findViewById(R.id.edit_sms);

  //注冊(cè)按鈕事件

  butten_sms.setOnClickListener(new View.OnClickListener() {

  @Override

  public void onClick(View arg0) {

  /**

  * 發(fā)彩信

  */

  //獲取電話號(hào)

  String phone_num = edit_phone.getText().toString();

  //創(chuàng)建意圖對(duì)象

  Intent intent = new Intent(Intent.ACTION_SEND);

  intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/a.jpg"));

  intent.putExtra("address", phone_num);

  intent.putExtra("exit_on_sent", true);

  intent.putExtra("subject", "subject:I love you");

  intent.putExtra("sms_body", "content ::XXXX");

  intent.setType("image/jpeg");

  startActivity(intent);

  /*// 獲取短信管理器對(duì)象

  SmsManager smsManager = SmsManager.getDefault();

  // 意圖對(duì)象

  PendingIntent pendingIntent = PendingIntent.getBroadcast(

  SmsActivity.this, 0, new Intent(), 0);*/

  }

  });

  }

  //發(fā)短信 功能

  public void send(){

  //獲取號(hào)碼

  String phone_Num = edit_phone.getText().toString();

  //獲取發(fā)送的.短信

  String phone_sms = edit_sms.getText().toString();

  //獲取信息管理器對(duì)象

  SmsManager smsmanager = SmsManager.getDefault();

  //意圖對(duì)象

  PendingIntent pendingIntent = PendingIntent.getBroadcast(SmsActivity.this, 0, new Intent(), 0);

  //判斷 信息長(zhǎng)度 大于 70則分兩條發(fā)送。。默認(rèn)是70

  ArrayListcontents = smsmanager

  .divideMessage(phone_sms);

  for (String c : contents) {

  // 發(fā)送信息的操作

  smsmanager.sendTextMessage(phone_Num, null, c,

  pendingIntent, null);

  }

  /*//發(fā)送信息操作

  smsmanager.sendTextMessage(phone_Num, null, phone_sms, pendingIntent, null);*/

  //吐司的效果

  Toast.makeText(SmsActivity.this, "短信發(fā)送成功",Toast.LENGTH_LONG).show();

  }

  @Override

  public boolean onCreateOptionsMenu(Menu menu) {

  // Inflate the menu; this adds items to the action bar if it is present.

  getMenuInflater().inflate(R.menu.sms, menu);

  return true;

  }

  }

【Android實(shí)現(xiàn)發(fā)短信和彩信功能】相關(guān)文章:

thinkPHP實(shí)現(xiàn)的聯(lián)動(dòng)菜單功能08-06

利用python實(shí)現(xiàn)簡(jiǎn)單爬蟲功能10-03

php實(shí)現(xiàn)圖片縮放功能類11-15

android SDk中常用的java包功能介紹11-27

java實(shí)現(xiàn)后臺(tái)自動(dòng)發(fā)郵件功能10-18

php中實(shí)現(xiàn)回刪功能實(shí)例11-11

PHP實(shí)現(xiàn)搜索查詢功能的方法技巧08-14

php中怎么實(shí)現(xiàn)回刪功能11-09

php實(shí)現(xiàn)文件上傳及頭像預(yù)覽功能08-09