Friday, March 11, 2011

Android SMS Send and Receive.

Android SMS Send And Receive Application.

DOWNLOAD SOURCE CODE 



you can check this sms send receive local emulator.

just create two emulator .

where you give  phone no that place you have pass that receiving emulator no:5556

ex:
first emulator no:5554(sms sent)

second emulator no:5556(receive sms) .

source code
serbt.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                EditText no=(EditText)findViewById(R.id.no);
                EditText name=(EditText)findViewById(R.id.name);
                EditText author=(EditText)findViewById(R.id.author);
                EditText version=(EditText)findViewById(R.id.version);
                data.insertData(no.getText().toString(), name.getText().toString(), author.getText().toString(), version.getText().toString());
               
                String phoneNo = "5556";
                String message = "Books Succesfully  Details Added!!!!"+","+no.getText().toString()+","+name.getText().toString()+","+author.getText().toString()+","+version.getText().toString();                
                if (phoneNo.length()>0 && message.length()>0)               
                    sendSMS(phoneNo, message);               
                else
                    Toast.makeText(getBaseContext(),
                        "Please enter both phone number and message.",
                        Toast.LENGTH_SHORT).show();              
                Intent in=new Intent(AddBooksActivity.this,AddBooksActivity.class);
                in.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(in);
                // ArrayList<String> getData = data.getAllData();                          
            }
          });
       
        Screen Shot First Emulator:5554

             

Second Emulator 5556



               





Source Code:
for receving purpose

@Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
         //---get the SMS message passed in---
        Bundle bundle = intent.getExtras();       
        SmsMessage[] msgs = null;
        String str = "";           
        if (bundle != null)
        {
            //---retrieve the SMS message received---
            Object[] pdus = (Object[]) bundle.get("pdus");
            msgs = new SmsMessage[pdus.length];           
            for (int i=0; i<msgs.length; i++){
                msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);               
                str += "SMS from " + msgs[i].getOriginatingAddress();                    
                str += " :";
                str += msgs[i].getMessageBody().toString();
                str += "\n";       
            }
            //---display the new SMS message---
            Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
        }                        
    }





Check out this may be help you

Related Posts Plugin for WordPress, Blogger...