Android i Java, jak wyciągnąć numer telefonu, dostarczonego SMSa?

0

Witam!
pisze aplikacje na androida, która ma za zadanie wysyłać sms i przypisywać status wysłania do danego smsa.
Teraz mam pytanie, zrobiłem taką funkcje:

    private void sendSMS(String phoneNumber, String message)
    {        
            String wyslany = "SMS_SENT";
            String dostarczony = "SMS_DELIVERED";
            PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(wyslany), 0);
            PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(dostarczony), 0);
            
            registerReceiver(new BroadcastReceiver()
            {
                public void onReceive(Context arg0, Intent arg1)
                {
                    switch (getResultCode())
                    {
                        case Activity.RESULT_OK:
                            Toast.makeText(getBaseContext(), "SMS Wysłany", Toast.LENGTH_SHORT).show();
                            break;
                        case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                            Toast.makeText(getBaseContext(), "Błąd wysyłu!", Toast.LENGTH_SHORT).show();
                            break;
                        case SmsManager.RESULT_ERROR_NO_SERVICE:
                            Toast.makeText(getBaseContext(), "Brak sieci", Toast.LENGTH_SHORT).show();
                            break;
                        case SmsManager.RESULT_ERROR_NULL_PDU:
                            Toast.makeText(getBaseContext(), "Błąd PDU", Toast.LENGTH_SHORT).show();
                            break;
                        case SmsManager.RESULT_ERROR_RADIO_OFF:
                            Toast.makeText(getBaseContext(), "Brak zasięgu", Toast.LENGTH_SHORT).show();
                            break;
                    }
                }
            }, new IntentFilter(wyslany));

            registerReceiver(new BroadcastReceiver()
            {
                @Override
                public void onReceive(Context arg0, Intent arg1) 
                {
                    switch (getResultCode())
                    {
                        case Activity.RESULT_OK:
                            Toast.makeText(getBaseContext(), "SMS dostarczony", Toast.LENGTH_SHORT).show();
                            break;
                        case Activity.RESULT_CANCELED:
                            Toast.makeText(getBaseContext(), "SMS nie dostarczony", Toast.LENGTH_SHORT).show();
                            break;                        
                    }
                }
            }, new IntentFilter(dostarczony));        

            SmsManager sms = SmsManager.getDefault();
            sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);        
    } 

I chciał bym teraz - jako że takich SMSów będę wysyłał np 5 na raz - otrzymać napis SMS dostarczony na nr 631XXXXXX, proszę o podpowiedź jak wyciągnąć numer na który wysyłam?

0

Niestety nie o to mi chodziło. Mi chodziło jak pobrać numer telefonu albo jakąkolwiek informacje identyfikującą (z raportu doręczenia) - jaki sms dotarł do użytkownika?
A Ty podałeś mi jak pobrać numer telefonu z przychodzącego smsa.

czyli chodzi mi o to który sms został już dostarczony, a który nie?
Przecież w androidzie musi być jakaś opcja do tego służąca. Skoro w podstawowej aplikacji (do wysyłania sms) po włączeniu raportów pokazuje - sms wysłany lub dostarczony itp?

EDIT:

Ok! Poszedłem już o krok dalej, dowiedziałem się, że muszę zapisać jakiś identyfikator w intencie wysyłającym i potem mogę go odczytać w BroadcastReceiver.
Problem polega na tym, że nie wiem za bardzo jak się do tego zabrać:
Tzn zrobiłem coś takiego:

	private void sendSMS(final String phoneNumber, String message)
    {        
            String wyslany = "SMS_SENT";
            String dostarczony = "SMS_DELIVERED";
            PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(wyslany), 0);
            PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(dostarczony), 0);
            Calendar c = Calendar.getInstance(); 
            StringBuilder sb = new StringBuilder();
            sb.append(c.get(Calendar.YEAR));
            sb.append(c.get(Calendar.DAY_OF_YEAR));
            sb.append(c.get(Calendar.HOUR_OF_DAY));
            sb.append(c.get(Calendar.MINUTE));
            sb.append(c.get(Calendar.SECOND));
            final String time = sb.toString();
            //---when the SMS has been sent---

            Intent sentIntent = new Intent(wyslany);
        	sentIntent.putExtra("createdTime", time);
        	
        	Intent deliveryIntent = new Intent(dostarczony);
        	deliveryIntent.putExtra("createdTime", time);
        	
            registerReceiver(new BroadcastReceiver()
            {
                public void onReceive(Context arg0, Intent arg1)
                {
                	String smsDateTimeAsID = arg1.getStringExtra("createdTime");
                    switch (getResultCode())
                    {
                        case Activity.RESULT_OK:
                            //Toast.makeText(getBaseContext(), "SMS Wysłany"+phoneNumber, Toast.LENGTH_SHORT).show();
                            //Toast.makeText(getApplicationContext(), "received", Toast.LENGTH_SHORT).show();
                            Log.d("info",  "SMS Wysłany "+phoneNumber+" o: "+smsDateTimeAsID);
                            break;
                        case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                            Toast.makeText(getBaseContext(), "Błąd wysyłu!", Toast.LENGTH_SHORT).show();
                            break;
                        case SmsManager.RESULT_ERROR_NO_SERVICE:
                            Toast.makeText(getBaseContext(), "Brak sieci", Toast.LENGTH_SHORT).show();
                            break;
                        case SmsManager.RESULT_ERROR_NULL_PDU:
                            Toast.makeText(getBaseContext(), "Błąd PDU", Toast.LENGTH_SHORT).show();
                            break;
                        case SmsManager.RESULT_ERROR_RADIO_OFF:
                            Toast.makeText(getBaseContext(), "Brak zasięgu", Toast.LENGTH_SHORT).show();
                            break;
                    }
                }
            }, new IntentFilter(wyslany));

            registerReceiver(new BroadcastReceiver()
            {
                @Override
                public void onReceive(Context arg0, Intent arg1) 
                {
                   // Intent deliveryIntent = new Intent(Cons.SMS_SENT);
                   // deliveryIntent.putExtra("createdTime", createdTime);
                	String smsDateTimeAsID = arg1.getStringExtra("createdTime");
                	switch (getResultCode())
                    {
                        case Activity.RESULT_OK:
                            //Toast.makeText(getBaseContext(),"SMS dostarczony"+phoneNumber, Toast.LENGTH_SHORT).show();
                        	Log.d("info",  "SMS dostarczony"+phoneNumber+" o: "+smsDateTimeAsID);
                        	break;
                        case Activity.RESULT_CANCELED:
                            Toast.makeText(getBaseContext(), "SMS nie dostarczony", Toast.LENGTH_SHORT).show();
                            break;                        
                    }
                }
            }, new IntentFilter(dostarczony));        

            SmsManager sms = SmsManager.getDefault();
            sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);        
    }}

Przypuszczam, że robię coś źle, więc poproszę Was o radę, jak poprawić kod. ewentualnie w jaki sposób korzystać z BrodcastRecivera w tym wypadku?

1 użytkowników online, w tym zalogowanych: 0, gości: 1