99偷拍视频精品区一区二,口述久久久久久久久久久久,国产精品夫妇激情啪发布,成人永久免费网站在线观看,国产精品高清免费在线,青青草在线观看视频观看,久久久久久国产一区,天天婷婷久久18禁,日韩动漫av在线播放直播

android手機短信發送-創新互聯

剛學android不久,最近衛衛發給我了一個視頻,是怎樣制作android手機上的×××,一方面我感覺很有意思,另一方可以陪著她一起,今天弄完了,特來總結一下,雖然說比較簡單吧,但還是有總結的必要的。

站在用戶的角度思考問題,與客戶深入溝通,找到濟水街道網站設計與濟水街道網站推廣的解決方案,憑借多年的經驗,讓設計與互聯網技術結合,創造個性化、用戶體驗好的作品,建站類型包括:成都做網站、網站設計、企業官網、英文網站、手機端網站、網站推廣、申請域名、虛擬空間、企業郵箱。業務覆蓋濟水街道地區。

×××主要是用于android下的短信發送的,其主要的界面就是輸入發送母的人的號碼和要發的信息的內容,主要界面有兩個TextView和兩個EditText還有一個Button(在import android.widget.*),下面是布局文件(layout):

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

  xmlns:android="http://schemas.android.com/apk/res/android"

  android:layout_width="fill_parent"

  android:layout_height="fill_parent"

 android:orientation="vertical" >

  <TextView

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:text="@string/number"

    />

  <EditText

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:id="@+id/number"

    />

  <TextView

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:text="@string/content"

    />

  <EditText

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:minLines="3"

    android:id="@+id/context"

    />

  <Button

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:text="@string/button"

    android:id="@+id/button"

   />

</LinearLayout>

以上布局文件使用的string的值需要在value/string.xml進行設置,主要的代碼如下:

<?xml version="1.0" encoding="utf-8"?>

<resources>

  <string name="app_name">smsTest</string>

  <string name="action_settings">Settings</string>

  <string name="content">請輸入短信內容</string>

  <string name="number">請輸入手機號</string>

  <string name="button">發送信息</string>

 <string name="success">發送成功</string>

</resources>

以上就是布局,可以到AVD中試試是否成功,但是我們要完成這個×××還需要在主程序.java寫上相應的處理。

package com.example.smstest;

import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

import android.telephony.gsm.SmsManager;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast ;

import java.util.ArrayList;//以上是需要的包

@SuppressWarnings( "deprecation" )

public class MainActivity extends Activity {

 private EditText numberText ;//這個變量時用來接受布局中輸入的號碼

 private EditText contentText ;//這個變量時用來接受布局中輸入的信息

 @Override

 protected void onCreate(Bundle savedInstanceState) {//此類程序會從這歌開始在執行

 super.onCreate(savedInstanceState);//調用父類Activity中的onCreate方法

 setContentView(R.layout.activity_main);//執行布局文件

 numberText = (EditText) this.findViewById( R.id.number ) ; //接受布局中輸入框中的號碼

 contentText = (EditText) this.findViewById(R.id.context) ;//接受布局中輸入框中的信息

 Button button = (Button) this.findViewById(R.id.button) ;//使用Button

 button.setOnClickListener( new ButtonClick() ) ;//設置Button響應的內容

 }

 private final class ButtonClick implements View.OnClickListener

 {

 @Override

 public void onClick( View arg0 ) {

  String number = numberText.getText().toString() ;//接受布局中輸入框中的號碼

  String content = contentText.getText().toString();

  SmsManager manger = SmsManager.getDefault();//建立短信管理對象

  ArrayList<String> texts=manger.divideMessage(content) ;//如果短信過長超過一條短信的大值那么分為多條短信發送

  for ( String text : texts ) {

  manger.sendTextMessage(number, null, text, null, null) ;//發送消息(第一個是目的號碼,第三個是消息內容)

  }

  Toast.makeText(getApplicationContext(), R.string.success, Toast.LENGTH_LONG ).show() ;

  //使用Toast提示短信發送成功

 }

 }

 @Override

 public 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;

 }

}

這樣就可以了,可以在兩個模擬器中發送(漢字會亂碼但手機不會)android手機短信發送

但是這樣仍然不能再手機中使用,因為手機中的使用的話是要有使用權限的比如允許其扣除話費,那么獲得權限就需要修改/smsTest/AndroidManifest.xml中加一個權限的代碼

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

  package="com.example.smstest"

  android:versionCode="1"

  android:versionName="1.0" >

  <uses-sdk

    android:minSdkVersion="6"

    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.smstest.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>

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

</manifest>

紅體字是加上去的,其余是自動生成的,到此×××OK了。

2014/04/03 14:44

另外有需要云服務器可以了解下創新互聯scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業上云的綜合解決方案,具有“安全穩定、簡單易用、服務可用性高、性價比高”等特點與優勢,專為企業上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

新聞名稱:android手機短信發送-創新互聯
網站地址:http://www.yijiale78.com/article28/dpjpcp.html

成都網站建設公司_創新互聯,為您提供網站內鏈、靜態網站、網站制作、網站維護、關鍵詞優化、云服務器

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

手機網站建設