sendmultiparttextmessage как установить время ожидания для отправки
Я пишу простое приложение для отправки смс, извлеченных из базы данных.
Я прочитал этот вопрос:
Все работает хорошо, хорошо, но я нашел проблему. В MainActivity у меня есть две кнопки "войти" и "отправить".
Я проверил и после нажатия "логин" я включил режим полета. И я попытался отправить. ProgresDialog появился у меня и приложение остановилось.
Как я могу это исправить? Mayby установить время для отправки, но как?
Мой код doInBackground:
protected ArrayList<Klient> doInBackground(String... params) {
if(type.equals("login"))
{
// DB conection and do ArrayList<Klient>
return Klienci
}
else if(type.equals("send"))
{
if(Klienci.size()>0){
for(Klient x : Klienci)
{
Log.e("licznik ", String.valueOf(licznik));
publishProgress(licznik);
licznik++;
//there send
sendSms(x.getNumer(), x.getDescryption());
//there send
publishProgress(licznik);
switch (confirmation)
{
case 0:
{
x.setStatus("nie wysłano");//SMS not sent
break;
}
case 1:
{
x.setStatus("wysłano");//SMS sent
break;
}
case 2:
{
x.setStatus("wysłano");//General fail
break;
}
case 3:
{
x.setStatus("Brak zasięgu");//No service
break;
}
case 4:
{
x.setStatus("Brak danych");//null PDU
break;
}
case 5:
{
x.setStatus("Radio off");//Radio off
break;
}
default:
{
x.setStatus("Nie znany błąd");
break;
}
}
x.setData(getkalendarz()) ;
//start try ==============================
//end try ------------------------------
}
Log.e("data: ", getkalendarz());
return Klienci;
}
}
return null;
}
И есть СМС:
private void sendSms(String phoneNumber, String mm){
SmsManager smsManager = SmsManager.getDefault();
fragmenty=smsManager.divideMessage(mm);
int ct = fragmenty.size();
final ArrayList<PendingIntent> sentPis = new ArrayList<PendingIntent>(ct);
final ArrayList<PendingIntent> delPis = new ArrayList<PendingIntent>(ct);
for (int i = 0; i < ct; i++) {
final PendingIntent piSent =
PendingIntent.getBroadcast(context,
i,
new Intent(SENT),
0);
final PendingIntent piDel =
PendingIntent.getBroadcast(context,
i,
new Intent(DELIVERED),
0);
sentPis.add(piSent);
delPis.add(piDel);
}
smsManager.sendMultipartTextMessage(phoneNumber, null, fragmenty, sentPis, delPis);
confirmation=0;
while(0==confirmation) {
confirmation();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Log.e("confirmation x :", String.valueOf(confirmation));
}
enter code here
Последнее получение:
public void confirmation()
{
smsSentReciver =new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
switch (getResultCode())
{
case Activity.RESULT_OK:
{
confirmation=1;//SMS sent
break;
}
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
{
confirmation = 2;//General fail
break;
}
case SmsManager.RESULT_ERROR_NO_SERVICE:
{
confirmation = 3;//No service
break;
}
case SmsManager.RESULT_ERROR_NULL_PDU:
{
confirmation = 4;//null PDU
break;
}
case SmsManager.RESULT_ERROR_RADIO_OFF:
{
confirmation = 5;//Radio off
break;
}
default:
{
confirmation = 6;//ERROR
break;
}
}
}
};
context.registerReceiver(smsSentReciver, new IntentFilter(SENT));
}