2013-02-25 4 views
3

Я пишу приложение, в котором я пытаюсь отправить отправку СМС получателю, но всякий раз, когда я нажимаю «Отправить», получаю сообщение: - Сброс SMS, повторите попытку позже!Отправить SMS получателю

Пожалуйста, смотрите ниже скриншоте, как вы можете видеть, здесь я пытаюсь отправить сообщение Рахул ...

Manifest.xml:

<uses-permission android:name="android.permission.SEND_SMS" /> 

Пожалуйста, проверьте код ниже:

 private TextView name; 
private ListView list; 
private Database db; 
private Contact contact; 
Button buttonSend; 
EditText textSMS; 

private Map<String, AuthenticatorDescription> map = new LinkedHashMap<String, AuthenticatorDescription>(); 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.editor); 

    // bind GUI components 
    this.name = (TextView) findViewById(R.id.editor_name); 
    this.list = (ListView) findViewById(R.id.editor_list); 

    // check if contact id is valid 
    this.db = new Database(getContentResolver()); 
    int contactId = getIntent().getIntExtra(CONTACT_ID, NO_CONTACT_ID); 
    this.contact = this.db.getContact(contactId); 
    if (this.contact == null) { 
     finish(); 
    } 
    this.name.setText(this.contact.getName()); 

    // pre-load information about all account types 
    AuthenticatorDescription[] authTypes = AccountManager.get(this).getAuthenticatorTypes(); 
    for (AuthenticatorDescription authDesc : authTypes) { 
     this.map.put(authDesc.type, authDesc); 
    } 

    // bind list events 
    this.list.setOnItemClickListener(this); 
    this.list.setOnCreateContextMenuListener(this); 

    // create the GUI 
    updateView(); 



    saveGreeting = (ImageButton) findViewById(R.id.greeting); 
    saveGreeting.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      customGreeting(v); 
     } 
    }); 
    buttonSend = (Button) findViewById(R.id.buttonSend); 
    textSMS = (EditText) findViewById(R.id.editTextSMS); 
    buttonSend.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 

      String recepient = name.getText().toString(); 
      String sms = textSMS.getText().toString(); 

      try { 
      SmsManager smsManager = SmsManager.getDefault(); 
      smsManager.sendTextMessage(recepient, null, sms, null, null); 
      Toast.makeText(getApplicationContext(), "SMS Sent!", 
         Toast.LENGTH_LONG).show(); 
      } catch (Exception e) { 
      Toast.makeText(getApplicationContext(), 
       "SMS faild, please try again later!", 
       Toast.LENGTH_LONG).show(); 
      e.printStackTrace(); 
      } 

     } 
    }); 
} 
+2

так, что в вашем трассировки стека? – John3136

+0

@ John3136 Я не могу отправить сообщение Rahul и получить сообщение: Сбой с ошибкой, повторите попытку позже! ... – ASMUIRTI

+0

Это ваше сообщение об ошибке, которое вы написали. Не трассировка стека. – John3136

ответ

0

Амит

Расскажите меня, где ru chec король это в эмуляторе смс оленья кожа отправить

Это посылается только на самом устройстве

Plz проверить ниже указанные ссылки

Сво правильно

1 рабочий) http://mobiforge.com/developing/story/sms-messaging-android

2) http://katharnavas.wordpress.com/2009/10/07/how-to-send-sms-from-android-programatically/

3) http://saga-androidapplication.blogspot.in/2011/06/how-to-send-and-receive-message-using.html

4) http://www.java-samples.com/showtutorial.php?tutorialid=1540

5) http://codeoncloud.blogspot.in/2012/06/send-sms-from-android-application.html

Позвольте мне сказать, если вы все еще сталкиваются с какой-либо вопрос

3

образцы Android API имеют очень хороший пример того, что, почему бы вам не дать ему попробовать

он расположен по адресу:

...\sdk\samples\android-17\ApiDemos\src\com\example\android\apis\os\SmsMessagingDemo.java 

Оклейка из образца:

 SmsManager sms = SmsManager.getDefault(); 

     List<String> messages = sms.divideMessage(contentTextEdit.getText().toString()); 

     String recipient = recipientTextEdit.getText().toString(); 
     for (String message : messages) { 
      sms.sendTextMessage(recipient, null, message, PendingIntent.getBroadcast(
          SmsMessagingDemo.this, 0, new Intent(ACTION_SMS_SENT), 0), null); 
     } 

Регистрация вещательные приемники для SMS, отправляемые и доставленные намерения

registerReceiver(new BroadcastReceiver() { 
      @Override 
      public void onReceive(Context context, Intent intent) { 
       String message = null; 
       boolean error = true; 
       switch (getResultCode()) { 
       case Activity.RESULT_OK: 
        message = "Message sent!"; 
        error = false; 
        break; 
       case SmsManager.RESULT_ERROR_GENERIC_FAILURE: 
        message = "Error."; 
        break; 
       case SmsManager.RESULT_ERROR_NO_SERVICE: 
        message = "Error: No service."; 
        break; 
       case SmsManager.RESULT_ERROR_NULL_PDU: 
        message = "Error: Null PDU."; 
        break; 
       case SmsManager.RESULT_ERROR_RADIO_OFF: 
        message = "Error: Radio off."; 
        break; 
       } 
.... 
1

Регистрация BroadcastReceiver для отправки и поставляется как следовать

недействительные SendSMS (String phoneNumber, String message) {
/* PendingIntent pi = PendingIntent.getActivity (это 0, новое намерение (это, test.class), 0);
SmsManager sms = SmsManager.getDefault(); смс.sendTextMessage (номер телефона, null, сообщение, pi, null);
*/

 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--- 
     first = new BroadcastReceiver(){ 
      @Override 
      public void onReceive(Context arg0, Intent arg1) { 
       boolean status = false; 
       switch (getResultCode()) 
       { 
        case Activity.RESULT_OK: 
         status = true; 
         /* 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; 
       } 
       if(!status) 
       { 
        Toast.makeText(getBaseContext(), "SMS Send Failed", 
          Toast.LENGTH_SHORT).show(); 
        unregisterReceiver(this); 
       } 
      } 
     }; 
     registerReceiver(first,new IntentFilter(SENT)); 

     //---when the SMS has been delivered--- 
     second =new BroadcastReceiver(){ 
      @Override 
      public void onReceive(Context arg0, Intent arg1) { 
       switch (getResultCode()) 
       { 
        case Activity.RESULT_OK: 
         smsReply(true); 
         /*Toast.makeText(getBaseContext(), "SMS delivered", 
           Toast.LENGTH_SHORT).show();*/ 
         break; 
        case Activity.RESULT_CANCELED: 
         smsReply(false); 
         /* Toast.makeText(getBaseContext(), "SMS not delivered", 
           Toast.LENGTH_SHORT).show();*/ 
         break;      
       } 
       unregisterReceiver(this); 
      } 
     }; 
     registerReceiver(second, new IntentFilter(DELIVERED));   


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

После регистрации BroadcastReceiver не забудьте отменить BroadcastReceiver в OnStop() метод.

if(first!=null) 

unregisterReceiver(first); if(second!=null) unregisterReceiver(second);