導航:首頁 > 操作系統 > android後台發送簡訊

android後台發送簡訊

發布時間:2025-02-10 05:37:53

1. android 開發 一個通過服務端內容自動發送簡訊到指定號碼

調用系統的發送簡訊界面,只需向系統發送一個Intent,並附帶相關參數就可以了,下面以一個仿差demo說明。

類似下圖的界面


activity_main.xml


[html] view plain

<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" >

<Button

android:id="@+id/btn_send"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:layout_marginRight="@dimen/padding_small"

android:gravity="center"

android:paddingLeft="@dimen/padding_small"

android:paddingRight="@dimen/padding_small"

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

<EditText

android:id="@+id/edit_phone_number"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_alignBottom="@id/btn_send"

android:layout_marginLeft="@dimen/padding_small"友悔

android:layout_marginRight="@dimen/padding_small"

android:layout_toLeftOf="@id/btn_send"

android:hint="@string/edittext_hint"

android:inputType="phone"

android:paddingLeft="@dimen/padding_small" />

</RelativeLayout>


然後在MainActivity中編寫相應的java代碼就可以了,操作很簡單,在EditText中輸入號碼,然後點擊Send,就跳到系統發備告皮送簡訊界面,並且接收人一欄里填入號碼。相關的代碼如下:


獲取控制項,響應Button的點擊事件:


[java] view plain

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

mEditText = (EditText) findViewById(R.id.edit_phone_number);

mButton = (Button) findViewById(R.id.btn_send);

mButton.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String phoneNumber = mEditText.getText().toString();

if (!TextUtils.isEmpty(phoneNumber)) {

sendSmsWithNumber(MainActivity.this, phoneNumber);

}

}

});

}


向指定號碼發送簡訊:

[java] view plain

/**

* 調用系統界面,給指定的號碼發送簡訊

*

* @param context

* @param number

*/

public void sendSmsWithNumber(Context context, String number) {

Intent sendIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + number));

context.startActivity(sendIntent);

}

這樣點擊Send後,就會跳轉到系統簡訊界面了,並且接收人一欄里就是剛才你填寫的號碼。


同理,要想調用系統發送簡訊界面後附加簡訊內容和以上是類似的,只需在Intent中附帶相關的參數就可以了。

[java] view plain

/**

* 調用系統界面,給指定的號碼發送簡訊,並附帶簡訊內容

*

* @param context

* @param number

* @param body

*/

public void sendSmsWithBody(Context context, String number, String body) {

Intent sendIntent = new Intent(Intent.ACTION_SENDTO);

sendIntent.setData(Uri.parse("smsto:" + number));

sendIntent.putExtra("sms_body", body);

context.startActivity(sendIntent);

}

2. 如何屏蔽簡訊界面,在後台發簡訊

要實現這個功能,在後台發送簡訊,這個功能用戶無法感知,是一個不好的東東,但是如果加上界面上的提示的話,也還是可行的。
1.第一種很簡單,就是使用intent跳轉到系統自帶發簡訊的界面,然後由用戶點擊Send。
2.第二種方法就是本文所說的,其實很簡單,使用SmsManager這個類就可以簡單實現。

3. Android開發,各位大神誰知道怎麼在後台發Email或發簡訊,不用跳轉到系統界面,感激不盡!

郵件可以使用java mail api, 發簡訊就直接調用Android api SmsManager.sendMessage()就行

閱讀全文

與android後台發送簡訊相關的資料

熱點內容
java的equals用法 瀏覽:843
奧維雲伺服器怎麼開通 瀏覽:167
js取得伺服器地址 瀏覽:810
起點中文網小說緩存在哪個文件夾 瀏覽:214
java瘋狂講義pdf 瀏覽:296
推有錢app在哪裡 瀏覽:739
寧波鮑斯壓縮機 瀏覽:93
新建文件夾電影2完整版演員表 瀏覽:988
空調壓縮機為什麼不能放到冷庫用 瀏覽:89
江西雲伺服器節點虛擬主機 瀏覽:997
新氧app如何測試臉型 瀏覽:688
個稅app如何查詢社保 瀏覽:495
安卓設備快充什麼時候開啟的 瀏覽:13
ipad怎麼用安卓手機傳文件 瀏覽:584
編輯程序員視頻 瀏覽:633
極光app的雲助手在哪裡 瀏覽:777
信合有什麼ApP 瀏覽:958
android絕對位置 瀏覽:79
阿里巴巴校招程序員在哪個園區 瀏覽:905
呼吸的科學pdf 瀏覽:820