package com.example.crypton;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts;
import android.provider.Contacts.People;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
import android.provider.ContactsContract.Data;
import android.telephony.SmsManager;
import android.util.Log;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.app.PendingIntent;

public class CREATEMESSAGE extends Activity {

    final static int REQ_CODE=1;

    Intent i;
    EditText textphoneno;
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.createmessage);
        textphoneno=(EditText)findViewById(R.id.editTextPhoneNo);
        final EditText textsms=(EditText)findViewById(R.id.editTextSMS);
        Button encrypt=(Button)findViewById(R.id.bencrypt);
        Button send=(Button)findViewById(R.id.buttonSend);




        encrypt.setOnClickListener(new View.OnClickListener()
        {
             public void onClick(View v)
             {                
                 try
                 {
                     Intent i = new Intent(CREATEMESSAGE.this,Encrypt.class); 
                     String phoneno=textphoneno.getText().toString();
                     String sms=textsms.getText().toString();  
                     Bundle bundle=new Bundle();
                     bundle.putString("sms",sms);
                     bundle.putString("phoneno",phoneno);
                     i.putExtras(bundle);
                     CREATEMESSAGE.this.startActivity(i);
                 }catch(Exception e)
                 {
                     e.printStackTrace();
                 }
             }
       });



       send.setOnClickListener(new View.OnClickListener()
       {
           public void onClick(View v)
           {                
               String phoneno=textphoneno.getText().toString();
               String sms=textsms.getText().toString();          
               if (phoneno.length()>0 && sms.length()>0)                
               {
                   SmsManager s = SmsManager.getDefault();
                   s.sendTextMessage(phoneno, null, sms, null, null);  
                   Toast.makeText(getApplicationContext(),"SMS SENT!!!",Toast.LENGTH_LONG).show();

               }
               else
                   Toast.makeText(getBaseContext(),
                           "Please enter both phone number and message.",
                           Toast.LENGTH_SHORT).show();
           }
       }); 

    }

    @Override
    public boolean onCreateOptionsMenu(android.view.Menu menu) {
        // TODO Auto-generated method stub
         super.onCreateOptionsMenu(menu);
         MenuInflater blowup=getMenuInflater();
         blowup.inflate(R.menu.contactmenu,menu);
         return true;
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch(item.getItemId())
        {
        case R.id.contacts:

             i = new Intent();
             i.setAction(Intent.ACTION_PICK);
             //i.setAction(Intent.ACTION_VIEW);
             i.setData(Uri.parse("content://contacts/people/"));
             startActivityForResult(i,REQ_CODE);

            break;
        }
        return false;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);

        switch (requestCode) {
        case (REQ_CODE) :
          if (resultCode == Activity.RESULT_OK) {
              Uri contactData = data.getData();
               Cursor c =  managedQuery(contactData, null, null, null, null);
                startManagingCursor(c);
                if (c.moveToFirst()) {
                   String name = c.getString(c.getColumnIndexOrThrow(People.NAME));  
                   String number = c.getString(c.getColumnIndex("1"));



                  textphoneno.setText(number);
                  Toast.makeText(this,  name + " has number " + number, Toast.LENGTH_LONG).show();

          }  
}
    }
    }
}

So, you provide 142 lines of Java code, yet don't indicate where your problem occurs... :-( Please be more specic as to where the problem occurs, and why YOU think it may be happening. I'll teach you to fish, but I won't do your fishing for you!

i have solved it...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.