最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android 調用發(fā)送短信的方法

 更新時間:2017年09月01日 15:05:24   作者:1140566087  
這篇文章主要介紹了Android 調用發(fā)送短信的方法的相關資料,主要實現Android 調用短信的使用,希望通過本文能幫助到大家,需要的朋友可以參考下

Android 調用發(fā)送短信的方法

功能:調用發(fā)送短信功能

1 、 權限

<uses-permission android:name="android.permission.SEND_SMS"/> 

2、具體實現

Uri smstoUri = Uri.parse("smsto:"); 
Intent intent = new Intent(Intent.ACTION_VIEW,smstoUri); 
intent.putExtra("address","電話號碼"); // 沒有電話號碼的話為默認的,即顯示的時候是為空的 
intent.putExtra("sms_body","短信內容"); // 設置發(fā)送的內容 
intent.setType("vnd.android-dir/mms-sms"); 
startActivity(intent); 

Activity 代碼:

public class MainActivity extends Activity { 
 
  private EditText phone ,message; 
  private Button sendbtn; 
  protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
     
    phone = (EditText) findViewById(R.id.phone); 
    message = (EditText) findViewById(R.id.message); 
    sendbtn = (Button) findViewById(R.id.sendbtn); 
     
    //點擊發(fā)送短信 
    sendbtn.setOnClickListener(new OnClickListener() { 
       
      public void onClick(View v) { 
        String p = phone.getText().toString(); 
        String m = message.getText().toString(); 
        Uri smstoUri = Uri.parse("smsto:"); // 解析地址 
        Intent intent = new Intent(Intent.ACTION_VIEW,smstoUri); 
        intent.putExtra("address",p); // 沒有電話號碼的話為默認的,即顯示的時候是為空的 
        intent.putExtra("sms_body",m); // 設置發(fā)送的內容 
        intent.setType("vnd.android-dir/mms-sms"); 
        startActivity(intent); 
      } 
    }); 
  } 
} 

 Mainfest.xml 配置文件:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
  package="com.example.message" 
  android:versionCode="1" 
  android:versionName="1.0" > 
 
  <uses-sdk 
    android:minSdkVersion="10" 
    android:targetSdkVersion="10" /> 
 
  <application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
      android:name="com.example.message.MainActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
        <action android:name="android.intent.action.MAIN" /> 
 
        <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
    </activity> 
  </application> 
 
  <!-- 發(fā)送短信權限 --> 
  <uses-permission android:name="android.permission.SEND_SMS" /> 
 
</manifest> 

布局示意圖:



<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=".MainActivity" > 
 
  <EditText 
    android:id="@+id/phone" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:ems="10" 
    android:inputType="number" > 
 
    <requestFocus /> 
  </EditText> 
 
  <Button 
    android:id="@+id/sendbtn" 
    style="?android:attr/buttonStyleSmall" 
    android:layout_width="150dp" 
    android:layout_height="50dp" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginBottom="28dp" 
    android:text="Send" /> 
 
  <EditText 
    android:id="@+id/message" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/sendbtn" 
    android:layout_alignLeft="@+id/phone" 
    android:layout_marginBottom="48dp" 
    android:ems="10" /> 
 
</RelativeLayout> 

 以上就是Android 調用短信的方法,如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關文章

  • Android Jetpack組件之ViewModel使用詳解

    Android Jetpack組件之ViewModel使用詳解

    Android中的ViewModel是一個可以用來存儲UI相關的數據的類。ViewModel的生命周期會比創(chuàng)建它的Activity、Fragment的生命周期長,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習吧
    2023-04-04
  • Android中AlertDialog四種對話框的最科學編寫用法(實例代碼)

    Android中AlertDialog四種對話框的最科學編寫用法(實例代碼)

    這篇文章主要介紹了Android中AlertDialog四種對話框的最科學編寫用法,本文通過代碼講解的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-11-11
  • Android遠程服務編寫和調用教程

    Android遠程服務編寫和調用教程

    這篇文章主要介紹了Android遠程服務編寫和調用教程,本文教大家如何編寫或者調用Android的遠程服務,感興趣的小伙伴們可以參考一下
    2016-02-02
  • Android使用CountDownTimer類實現倒計時鬧鐘

    Android使用CountDownTimer類實現倒計時鬧鐘

    這篇文章主要為大家詳細介紹了Android使用CountDownTimer類實現倒計時鬧鐘,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-01-01
  • android自定義加減按鈕

    android自定義加減按鈕

    這篇文章主要為大家詳細介紹了android自定義加減按鈕,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • 9個非常棒的Android代碼編輯器 移動開發(fā)者的最愛

    9個非常棒的Android代碼編輯器 移動開發(fā)者的最愛

    這篇文章主要為大家分享了9個非常棒的Android代碼編輯器,據說這可是移動開發(fā)者的最愛,知道是哪九個Android代碼編輯器
    2015-12-12
  • Android開發(fā)實現布局中為控件添加選擇器的方法

    Android開發(fā)實現布局中為控件添加選擇器的方法

    這篇文章主要介紹了Android開發(fā)實現布局中為控件添加選擇器的方法,涉及Android開發(fā)中布局設置的相關操作技巧,需要的朋友可以參考下
    2017-10-10
  • 詳解Android端與JavaWeb傳輸加密(DES+RSA)

    詳解Android端與JavaWeb傳輸加密(DES+RSA)

    這篇文章主要介紹了詳解Android端與JavaWeb傳輸加密(DES+RSA),小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-11-11
  • 全面解析Android應用開發(fā)中Activity類的用法

    全面解析Android應用開發(fā)中Activity類的用法

    這篇文章主要介紹了Android應用開發(fā)中Activity類的用法,包括Activity間的數據傳遞以及Activity的創(chuàng)建方式等,需要的朋友可以參考下
    2016-02-02
  • Flutter實現切換應用時隱藏應用預覽

    Flutter實現切換應用時隱藏應用預覽

    如果您要顯示敏感數據,例如錢包金額,或者只是當登錄表單顯示插入的密碼清晰時,當您不在應用程序中時,您必須隱藏敏感數據。本文將利用Flutter實現切換應用時隱藏應用預覽,需要的可以參考一下
    2022-06-06

最新評論

沐川县| 岫岩| 饶阳县| 长春市| 邛崃市| 岱山县| 禹州市| 马公市| 东乌珠穆沁旗| 百色市| 常宁市| 徐水县| 天津市| 内黄县| 县级市| 沿河| 九台市| 芮城县| 东乡| 白银市| 霍州市| 赞皇县| 德惠市| 托克逊县| 香港 | 永济市| 平湖市| 文登市| 平武县| 旬阳县| 炉霍县| 南安市| 石嘴山市| 财经| 嘉义县| 临泽县| 云霄县| 阜康市| 浦城县| 玛沁县| 安宁市|