Android 폰에서 Java로 SMS 메시지를 보내면 한 번에 하나씩 처리 할 수 있습니까?Android 폰에서 Java로 SMS 메시지를 보내면 한 번에 하나씩 처리 할 수 있습니까?
휴대 전화에서 여러 개의 SMS 메시지를 보내려면이 애플리케이션을 만들었지 만 한 번에 하나씩 보내도록 변경하려면 어떻게해야합니까?
내가 응답 코드는 다음 중 하나를 보내기 전에 돌아 가야하는이 SMS 메시지를 보내고 기다릴 수 있도록 노력하고 다음 sendSms (에서
import android.telephony.gsm.SmsManager;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.util.Log;
import android.widget.Button;
import java.io.*;
import android.util.LogPrinter;
import java.io.*;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.widget.TextView;
import android.os.*;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import java.io.*;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class JSSMS extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.Button01);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(JSSMS.this, "Starting SMS", Toast.LENGTH_LONG)
.show();
String message = "Hello This Is John, Please save my new number";
String number;
try {
BufferedReader buffreader = new BufferedReader(
new FileReader(Environment
.getExternalStorageDirectory().toString()
+ "/numbers.txt"));
int i = 0;
while ((number = buffreader.readLine()) != null) {
Toast.makeText(JSSMS.this, "Sending text to:" + number,
Toast.LENGTH_SHORT).show();
sendSMS(number, message);
}
buffreader.close();
} catch (java.io.FileNotFoundException e) {
Toast.makeText(JSSMS.this, e.toString(), Toast.LENGTH_SHORT)
.show();
} catch (Exception e) {
Toast.makeText(JSSMS.this, e.toString(), Toast.LENGTH_SHORT)
.show();
}
Toast.makeText(JSSMS.this, "DONE!!", Toast.LENGTH_LONG).show();
}
});
}
// ---Sends an SMS message to another device.---
private void sendSMS(String phoneNumber, String message) {
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(
SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
new Intent(DELIVERED), 0);
// ---When the SMS has been sent---
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS sent",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getBaseContext(), "Generic failure",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getBaseContext(), "No service",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(), "Null PDU",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getBaseContext(), "Radio off",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(SENT));
// ---When the SMS has been delivered---
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS delivered",
Toast.LENGTH_SHORT).show();
break;
case Activity.RESULT_CANCELED:
Toast.makeText(getBaseContext(), "SMS not delivered",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(DELIVERED));
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
}
}
에 오신 것을 환영있어. 첫 번째 질문과 함께 몇 개의 downvotes를 가져 왔다니 유감입니다. 귀하의 질문은 합리적이라고 생각하지만 때로는 사람들이 "XXX 할 코드를 보여주십시오"라는 정보 외에도 약간의 정보를 제공하는 질문에 반응합니다. 그러나 코드를 제공 했으므로 인내심이 조금이라도있는 사람이라면 몇 가지 정보를 얻을 수 있습니다. 너를 돕는 사람들을 upvote하는 것을 잊지 마라! –