Send SMS in Android

package com.example.tutorialspoint; import android.net.Uri; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.util.Log; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button startBtn = (Button) findViewById(R.id.button); startBtn.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { sendSMS(); } }); } protected void sendSMS() { Log.i("Send SMS", ""); Intent smsIntent = new Intent(Intent.ACTION_VIEW); smsIntent.setData(Uri.parse("smsto:")); smsIntent.setType("vnd.android-dir/mms-sms"); smsIntent.putExtra("address" , new String ("01234")); smsIntent.putExtra("sms_body" , "Test "); try { startActivity(smsIntent); finish(); Log.i("Finished sending SMS...", ""); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(MainActivity.this, "SMS faild, please try again later.", Toast.LENGTH_SHORT).show(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
In Android, you can use SmsManager API or devices Built-in SMS application to send SMS's.

Full solution can be found at: "Android - Sending SMS"
Source: https://www.tutorialspoint.com/android/android_sending_sms.htm

#android #sms #smsManager #tutorial

#cesarnog

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.