This is works for me.
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
btnSendSMS.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
sendSMS("5556", "Hi You got a message!");
/*here i can send message to emulator 5556. In Real device
you can change number */
}
});
}
//---sends an SMS message to another device---
private void sendSMS(String phoneNumber, String message)
{
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, null, null);
}
}
You can add this line in AndroidManifest.xml
<uses-permission android:name="android.permission.SEND_SMS"/>
Take a look at this
This may helpful for you.
沒有留言:
張貼留言