我正在尝试发送短信。该代码运行,但不发送任何SMS。没有错误。请指导必须出问题的地方。
package com.example.smsbomber;
import android.app.Activity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sendSMS();
}
@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;
}
public void sendSMS() {
String phoneNumber = "00923002228885";
String message = "Hello World!";
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNumber, null, message, null, null);
}
}
最佳答案
请尝试以下代码:
SmsManager sms = SmsManager.getDefault();
PendingIntent sentPI;
String SENT = "SMS_SENT";
sentPI = PendingIntent.getBroadcast(this, 0,new Intent(SENT), 0);
sms.sendTextMessage(phoneNumber, null, message, sentPI, null);
取自here.
关于java - 代码运行但不发送短信,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16679635/