安卓發簡訊的程式,但是沒效果。

來源:互聯網
上載者:User

標籤:android   style   color   io   os   ar   使用   java   sp   

============問題描述============


這個代碼是Activity裡面的布局的我就不貼了,我設定的Toast都報出來了但是簡訊還是發不出來。

package com.example.message;import android.app.Activity;import android.app.PendingIntent;import android.content.Intent;import android.os.Bundle;import android.telephony.SmsManager;import android.util.Log;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;public class MainActivity extends Activity {public Button send;public EditText number,message;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);send = (Button)this.findViewById(R.id.send);number = (EditText)this.findViewById(R.id.number);message = (EditText)this.findViewById(R.id.msg);send.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubsendMessage();}});}public void sendMessage(){String pnumber = number.getText().toString().trim();String msg = message.getText().toString().trim();  PendingIntent sentIntent = PendingIntent.getBroadcast(this, 0, new Intent(), 0);if("".equals(msg)||"".equals(pnumber)){Toast.makeText(this, "需要填寫號碼,切簡訊內容不可為空", Toast.LENGTH_LONG).show();}else{Log.i("message", "接收者:"+pnumber+"  資訊:"+msg);SmsManager sms = SmsManager.getDefault();sms.sendTextMessage(pnumber, "13652179825", msg, sentIntent, null); Toast.makeText(this, "發送成功!", Toast.LENGTH_LONG).show();}}@Overridepublic 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.permission.SEND_SMS還把別的有關簡訊和多媒體訊息的許可權都加上了,可是LOG裡面提示有permission denied,由於我的虛擬機器有問題我的測試使用真機做的。鄙人在安卓方面學識短淺,還請大神們看看咋回事兒行嗎?

============解決方案1============


sms.sendTextMessage(這個是收件者的地址, null, msg, send, null); 你這樣試試第二個參數是簡訊服務中心的電話  你寫錯了應該為null

============解決方案2============


你debug看一下,它執行的時候出現啥logcat,第二個參數是服務中心,

============解決方案3============


你的手機是不是裝了360這樣的管理軟體,所以屏蔽了你發短訊息的動作

安卓發簡訊的程式,但是沒效果。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.