尝试发送文本消息超过100次,有没有办法覆盖SMSDispatcher文本限制?
这是错误:
08-02 03:34:07.927: WARN/dalvikvm(1199): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-02 03:34:07.927: ERROR/AndroidRuntime(1199): FATAL EXCEPTION: main
08-02 03:34:07.927: ERROR/AndroidRuntime(1199): java.lang.NullPointerException
08-02 03:34:07.927: ERROR/AndroidRuntime(1199): at com.android.internal.telephony.SMSDispatcher.handleReachSentLimit(SMSDispatcher.java:809)
08-02 03:34:07.927: ERROR/AndroidRuntime(1199): at com.android.internal.telephony.SMSDispatcher.handleMessage(SMSDispatcher.java:339)
08-02 03:34:07.927: ERROR/AndroidRuntime(1199): at android.os.Handler.dispatchMessage(Handler.java:99)
08-02 03:34:07.927: ERROR/AndroidRuntime(1199): at android.os.Looper.loop(Looper.java:123)
08-02 03:34:07.927: ERROR/AndroidRuntime(1199): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-02 03:34:07.927: ERROR/AndroidRuntime(1199): at java.lang.reflect.Method.invokeNative(Native Method)
08-02 03:34:07.927: ERROR/AndroidRuntime(1199): at java.lang.reflect.Method.invoke(Method.java:521)
08-02 03:34:07.927: ERROR/AndroidRuntime(1199): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-02 03:34:07.927: ERROR/AndroidRuntime(1199): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-02 03:34:07.927: ERROR/AndroidRuntime(1199): at dalvik.system.NativeStart.main(Native Method)
这是我的代码 - 更新:
import java.util.Random;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
EditText PhNumber, Message, TxtCount;
Button btnSendSMS;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//create text box to enter phone number
PhNumber=(EditText) findViewById(R.id.PhNumber);
//create text box to enter message
Message=(EditText) findViewById(R.id.Message);
//create text box to see how many times the user wants to send message
TxtCount=(EditText) findViewById(R.id.TxtCount);
//create button to send text message
btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
//create listener for button
btnSendSMS.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
//variable for count.
int count = 1;
//variable for text message
String msg = Message.getText().toString();
//create string array of the alphabet
String[] mArray = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "r", "x", "y", "z"};
//create variable to hold random number
final Random r = new Random();
//variable for phone number
String num = PhNumber.getText().toString();
//create array of the phone number to get the number of numbers entered.
char[] nArray = num.toCharArray();
//variable for the amount of text messages to send.
String max1 = TxtCount.getText().toString();
//variable to watch button and hide keyboard
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
//test to see if number has a value
if (num.equals("") || (nArray.length < 10))
{
Toast.makeText(getApplicationContext(), "Enter 10 digit phone number!", Toast.LENGTH_SHORT).show();
return;
}
//test to see if msg has a value
if (msg.equals(""))
{
Toast.makeText(getApplicationContext(), "Enter a message!", Toast.LENGTH_SHORT).show();
return;
}
//test to see if there's a number of times to text
if (max1.equals("") || (Integer.parseInt(TxtCount.getText().toString()) <= 0))
{
Toast.makeText(getApplicationContext(), "Enter a number more than zero to nuke!", Toast.LENGTH_SHORT).show();
return;
}
//if all fields have valid data -- send text message until count = max
int max = Integer.parseInt(TxtCount.getText().toString());
while (count <= max) {
//create variable to hold random letter of the alphabet
String rLetter = mArray[r.nextInt(25)];
String rLetter2 = mArray[r.nextInt(25)];
String rLetter3 = mArray[r.nextInt(25)];
String rLetter4 = mArray[r.nextInt(25)];
final Random i = new Random();
sendSMS(num, (rLetter3 + i.nextInt(100) + rLetter4 + " " + msg + " " + rLetter + i.nextInt(100) +rLetter2));
count++;
};
//hide the keyboard
mgr.hideSoftInputFromWindow(TxtCount.getWindowToken(), 0);
mgr.hideSoftInputFromWindow(PhNumber.getWindowToken(), 0);
mgr.hideSoftInputFromWindow(Message.getWindowToken(), 0);
//set phone number to ""
PhNumber.setText("");
//set message to ""
Message.setText("");
//set count to ""
TxtCount.setText("");
//refocus on phone number
PhNumber.requestFocus();
}
});
}
//sends a sms message to another device
private void sendSMS(String phoneNumber, String message)
{
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, null, null);
}
}
答案 0 :(得分:0)
您无法将字符串与==进行比较 试试这个
if (TxtCount.getText().toString().equals(""))
{
Toast.makeText(getApplicationContext(), "Please enter a number of times to nuke!", Toast.LENGTH_SHORT).show();
}
else if (num.queals(""))
{
Toast.makeText(getApplicationContext(), "Please enter a phone number to nuke!", Toast.LENGTH_SHORT).show();
}
else if (msg.equals(""))
{
Toast.makeText(getApplicationContext(), "Please enter a message!", Toast.LENGTH_SHORT).show();
}
while (count <= max)
{
sendSMS(""+num,""+ msg);
count++;
};
喜欢这个
else if (num.equals(""))
{
Toast.makeText(getApplicationContext(), "Please enter a phone number to nuke!", Toast.LENGTH_SHORT).show();
return;
}