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

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

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

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

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

1 、 權(quán)限

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

2、具體實現(xiàn)

Uri smstoUri = Uri.parse("smsto:"); 
Intent intent = new Intent(Intent.ACTION_VIEW,smstoUri); 
intent.putExtra("address","電話號碼"); // 沒有電話號碼的話為默認(rèn)的,即顯示的時候是為空的 
intent.putExtra("sms_body","短信內(nèi)容"); // 設(shè)置發(fā)送的內(nèi)容 
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); // 沒有電話號碼的話為默認(rèn)的,即顯示的時候是為空的 
        intent.putExtra("sms_body",m); // 設(shè)置發(fā)送的內(nèi)容 
        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ā)送短信權(quán)限 --> 
  <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 調(diào)用短信的方法,如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

  • listview Button始終放在底部示例

    listview Button始終放在底部示例

    android實現(xiàn)底部布局往往使用RelativeLayout的布局方式,以下的例子就是實現(xiàn)三層布局的底部布局的功能,感興趣的朋友可以參考下哈,希望對大家有所幫助
    2013-07-07
  • Android應(yīng)用中利用ViewPager實現(xiàn)多頁面滑動切換效果示例

    Android應(yīng)用中利用ViewPager實現(xiàn)多頁面滑動切換效果示例

    這篇文章主要介紹了Android應(yīng)用中利用ViewPager實現(xiàn)多頁面滑動切換效果示例,配合了Fragment和PagerTabStrip,需要的朋友可以參考下
    2016-03-03
  • 教你一文搞懂Kotlin中的Jvm注解

    教你一文搞懂Kotlin中的Jvm注解

    這篇文章主要介紹了教你一文搞懂Kotlin中的Jvm注解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-10-10
  • Android查看電池電量的方法(基于BroadcastReceiver)

    Android查看電池電量的方法(基于BroadcastReceiver)

    這篇文章主要介紹了Android查看電池電量的方法,結(jié)合實例分析了Android使用BroadcastReceiver實現(xiàn)針對電池電量的查詢技巧,需要的朋友可以參考下
    2016-01-01
  • Android中buildToolVersion與CompileSdkVersion的區(qū)別

    Android中buildToolVersion與CompileSdkVersion的區(qū)別

    今天小編就為大家分享一篇關(guān)于Android中buildToolVersion與CompileSdkVersion的區(qū)別,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2018-12-12
  • android實現(xiàn)可上下回彈的scrollview

    android實現(xiàn)可上下回彈的scrollview

    這篇文章主要為大家詳細(xì)介紹了android實現(xiàn)可上下回彈的scrollview,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • Android使用WebView實現(xiàn)文件下載功能

    Android使用WebView實現(xiàn)文件下載功能

    這篇文章主要為大家詳細(xì)介紹了Android使用WebView實現(xiàn)文件下載功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • Android布局案例之人人android九宮格

    Android布局案例之人人android九宮格

    這篇文章主要為大家詳細(xì)介紹了Android布局案例之人人android九宮格,感興趣的小伙伴們可以參考一下
    2016-03-03
  • android編程實現(xiàn)的自定義注釋模板實例

    android編程實現(xiàn)的自定義注釋模板實例

    這篇文章主要介紹了android編程實現(xiàn)的自定義注釋模板,以完整實例形式分析了Android自定義魔板的定義及具體實現(xiàn)與使用技巧,需要的朋友可以參考下
    2015-11-11
  • Android開發(fā)中setContentView和inflate的區(qū)別分析

    Android開發(fā)中setContentView和inflate的區(qū)別分析

    這篇文章主要介紹了Android開發(fā)中setContentView和inflate的區(qū)別,較為詳細(xì)的分析了setContentView和inflate的功能、用法及二者的區(qū)別,需要的朋友可以參考下
    2016-07-07

最新評論