package com.example.sendsmsdemoApp;

import android.net.Uri;
import android.os.Bundle;

import com.example.sendsmsdemoApp.R;

import android.R.string;
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.TextView;
import android.widget.Toast;

public class SendSMSActivity extends Activity {

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

	 @Override
	   protected void onStart()
	   {
	   super.onStart();
	   Intent i = getIntent();
	   final String recipient = i.getStringExtra("Recipient");
	   TextView txtView = (TextView) findViewById(R.id.emailText);  
       txtView.setText("An meesage will be sent to" + recipient);
	   Button startBtn = (Button) findViewById(R.id.sendSMS);
	   startBtn.setOnClickListener(new View.OnClickListener() {
	   public void onClick(View view) {
		sendSMS(recipient);
		}}); } 
	protected void sendSMS(String recipient) {
		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" ,recipient );
		smsIntent.putExtra("sms_body" , "The PassWord-Code is : 104-45-23 ");
		 TextView txtView = (TextView) findViewById(R.id.emailText);  
	       txtView.setText("An meesage will be sent to" + "  "+ recipient + " "+"with this text: The PassWord-Code is : 104-45-23");
		try {
			
		startActivity(smsIntent);
		sendBroadcast(smsIntent);
		finish();
		Log.i("Finished sending SMS...", "");
		} catch (android.content.ActivityNotFoundException ex) {
		Toast.makeText(SendSMSActivity.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;
	}

}
