2013-03-01 2 views
3

저는 수신자에게 SMS를 보내려고하는 앱을 작성하고 있지만, 보내기를 클릭 할 때마다 메시지를 받고 있습니다 : - SMS 실패, 나중에 다시 시도하십시오! 당신은 스크린 샷 아래에서 볼 수있는 것처럼 어느 내가 에뮬레이터 또는 안드로이드 장치를 사용하고안드로이드 장치를 통해 SMS를 보냈습니다.

....

, 여기에 내가 내 전화 번호부 연락처에 저장됩니다 Pratik에 메시지를 보내려고하고 있어요,하지만 때마다 나는 당신이 볼 수있는 것처럼 Pratik

에 메시지를 보낼 수 Pratik에 메시지에 노력하고 할 수없는 ... 여기 내가 라훌 메시지를 보내려고하고, 스크린 샷 아래

Manifest.xml를 참조하십시오

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

코드 아래에 확인하시기 바랍니다 :

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

    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 = (ImageButton) findViewById(R.id.buttonSend); 
    textSMS = (EditText) findViewById(R.id.editTextSMS); 
    buttonSend.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 

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

      try { 
      SmsManager smsManager = SmsManager.getDefault(); 
      smsManager.sendTextMessage(CONTACT_ID, 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(); 
      } 

     } 
    }); 
} 
+0

'recepient = name.getText()'어떻게 작동합니까? – njzk2

답변

2

메시지를 보낼받는 사람 이름을 사용하지 마십시오, 메시지를 보내 휴대 전화 번호를 사용합니다.

연락처 목록에서 연락처 번호를 가져 와서 sendTextMessage 함수에서 이름 대신 해당 연락처 번호를 사용하십시오.

+0

친구가 선택한 친구에게 메시지를 보낼 수 없습니까? – ASMUIRTI

+0

가능하지만 이름 대신 번호를 설정해야합니다. 사용자에게 세부 정보를 표시하려면 이름을보기로 설정해야하지만 메시지를 보내려면 기능에서 번호를 전달해야합니다. –

+0

먼저 연락처 목록에서 연락처 번호를 가져 와서 한 문자열에 저장하고 해당 문자열을 메시지 보내기 기능에 전달하십시오. –

관련 문제