欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android開發(fā)實現(xiàn)撥打電話與發(fā)送信息的方法分析

 更新時間:2017年12月05日 10:42:45   作者:xxiaowen  
這篇文章主要介紹了Android開發(fā)實現(xiàn)撥打電話與發(fā)送信息的方法,結(jié)合實例形式分析了Android撥打電話及發(fā)送信息相關(guān)布局、功能實現(xiàn)及權(quán)限控制操作技巧,需要的朋友可以參考下

本文實例講述了Android開發(fā)實現(xiàn)撥打電話與發(fā)送信息的方法。分享給大家供大家參考,具體如下:

xml布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical" >
  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="電話號碼" />
    <EditText
      android:id="@+id/edit_main_number"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:hint="請輸入電話號碼"/>
   </LinearLayout>
   <LinearLayout
     android:layout_width="match_parent"
     android:layout_height="wrap_content">
     <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="短信內(nèi)容"/>
     <EditText
       android:id="@+id/edit_main_content"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:hint="請輸入短信內(nèi)容"/>
   </LinearLayout>
   <LinearLayout
     android:layout_width="match_parent"
     android:layout_height="wrap_content">
     <Button
       android:id="@+id/btn_call"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="撥打電話"/>
     <Button
        android:id="@+id/btn_send"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="發(fā)送信息"/>
   </LinearLayout>
</LinearLayout>

java代碼:

package com.wenzhi.interndemo;
import java.net.URL;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.app.Activity;
import android.content.Intent;
/**
 * 撥打電話與發(fā)送信息
 * @author xiaowen
 * @2016-1-5 下午10:48:53
 */
public class ThreeActivity extends Activity implements OnLongClickListener {
  private EditText edit_main_number;
  private EditText edit_main_content;
  private Button btn_call;
  private Button btn_send;
  private OnClickListener listener=new OnClickListener() {
    @Override
    public void onClick(View v) {
      if(v==btn_call){
        //點擊撥打電話 創(chuàng)建一個Intent(隱式)
        //String action=Intent.ACTION_DIAL;
        //Intent intent=new Intent(action);
        Intent intent=new Intent(Intent.ACTION_DIAL);
        //攜帶數(shù)據(jù)
        String number=edit_main_number.getText().toString();
        intent.setData(Uri.parse("tel:"+number));
        //啟動Activity
        startActivity(intent);
      }else if(v==btn_send){
        //點擊發(fā)送信息  創(chuàng)建一個Intent(隱式)
        Intent intent=new Intent(Intent.ACTION_SENDTO);
        //攜帶數(shù)據(jù)
        String number=edit_main_number.getText().toString();
        String content=edit_main_content.getText().toString();
        intent.setData(Uri.parse("smsto:"+number));
        intent.putExtra("sms_body", content);
        startActivity(intent);
      }
    }
  };
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_three);
    edit_main_number=(EditText) findViewById(R.id.edit_main_number);
    edit_main_content=(EditText) findViewById(R.id.edit_main_content);
    btn_call=(Button) findViewById(R.id.btn_call);
    btn_send=(Button) findViewById(R.id.btn_send);
    //給視圖對象設置點擊監(jiān)聽
    btn_call.setOnClickListener(listener);
    btn_send.setOnClickListener(listener);
    //給視圖對象設置長按監(jiān)聽
    btn_call.setOnLongClickListener(this);
    btn_send.setOnLongClickListener(this);
  }
  @Override
  public boolean onLongClick(View v) {
    if(v==btn_call){
     //長按撥打電話 創(chuàng)建一個Intent(隱式),必須在AndroidManifest.xml加入權(quán)限配置
     Intent intent=new Intent(Intent.ACTION_CALL);
     //攜帶數(shù)據(jù)
     String number =edit_main_number.getText().toString();
     intent.setData(Uri.parse("tel:"+number));
     //啟動Activity
     startActivity(intent);
    }else if(v==btn_send){
      //得到SmsManager的對象
      SmsManager smsManager=SmsManager.getDefault();
      //發(fā)送文本信息(短信)
      String number=edit_main_number.getText().toString();
      String content=edit_main_content.getText().toString();
      smsManager.sendTextMessage(number, null, content, null, null);
    }
    return true;
  }
}

注意:在AndroidManifest.xml加入權(quán)限配置

<uses-permission android:name="android.permission.CALL_PHONE"/><!-- 打電話的權(quán)限 -->
<uses-permission android:name="android.permission.SEND_SMS"/><!-- 發(fā)短信的權(quán)限 -->

另,關(guān)于Android權(quán)限設置可參考Android Manifest功能與權(quán)限描述大全

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進階教程》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android數(shù)據(jù)庫操作技巧總結(jié)》、《Android文件操作技巧匯總》、《Android資源操作技巧匯總》及《Android控件用法總結(jié)

希望本文所述對大家Android程序設計有所幫助。

相關(guān)文章

  • Android Notification實現(xiàn)動態(tài)顯示通話時間

    Android Notification實現(xiàn)動態(tài)顯示通話時間

    這篇文章主要為大家詳細介紹了Android Notification實現(xiàn)動態(tài)顯示通話時間,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Android?Java?crash?處理流程詳解

    Android?Java?crash?處理流程詳解

    這篇文章主要為大家介紹了Android?Java?crash?處理流程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-10-10
  • Android獲取當前手機網(wǎng)絡類型(2g、3g、4g、wifi)以及手機型號、版本號代碼

    Android獲取當前手機網(wǎng)絡類型(2g、3g、4g、wifi)以及手機型號、版本號代碼

    這篇文章主要介紹了Android獲取當前手機網(wǎng)絡類型(2g、3g、4g、wifi)以及手機型號、版本號的相關(guān)資料,需要的朋友可以參考下
    2016-03-03
  • Android實現(xiàn)手勢滑動多點觸摸放大縮小圖片效果

    Android實現(xiàn)手勢滑動多點觸摸放大縮小圖片效果

    這篇文章主要介紹了Android實現(xiàn)手勢滑動多點觸摸放大縮小圖片效果的相關(guān)資料,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-02-02
  • Android RecyclerView加載兩種布局的方法

    Android RecyclerView加載兩種布局的方法

    這篇文章主要為大家詳細介紹了Android RecyclerView加載兩種布局的方法,Adapter加載多套布局,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • 深入解析Android App的LayoutInflate布局

    深入解析Android App的LayoutInflate布局

    這篇文章主要介紹了Android App的LayoutInflate布局,對LayoutInflate編寫中經(jīng)常被無解及產(chǎn)生錯誤的地方進行了深入說明,需要的朋友可以參考下
    2016-04-04
  • Android實現(xiàn)水波紋特效

    Android實現(xiàn)水波紋特效

    這篇文章主要為大家詳細介紹了Android實現(xiàn)水波紋特效,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-01-01
  • flutter簡單使用案例

    flutter簡單使用案例

    這篇文章主要介紹了使用Flutter短視頻上滑翻頁效果,本篇介紹了?Flutter的翻頁組件PageView的使用,通過?PageView可以輕松實現(xiàn)類似短視頻的縱向上滑翻頁的效果,也可以實現(xiàn)橫向翻頁效果(如閱讀類軟件),需要的朋友可以參考下
    2023-05-05
  • 分享Android中ExpandableListView控件使用教程

    分享Android中ExpandableListView控件使用教程

    這篇文章主要介紹了Android中ExpandableListView控件使用教程,可以實現(xiàn)二級列表展示效果,需要的朋友可以參考下
    2015-12-12
  • Android 設置顏色的方法總結(jié)

    Android 設置顏色的方法總結(jié)

    這篇文章主要介紹了Android 設置顏色的方法總結(jié)的相關(guān)資料,希望通過本文能幫助到大家,讓大家掌握設置顏色的方法,需要的朋友可以參考下
    2017-09-09

最新評論