Payday Loan Payday Loan

Archive for the ‘Telephony’ Category

Hi, this is a simple and efficient working example of how you can know when device received a message.
So in your launch activity put the code:

registerReceiver(new BroadcastReceiver() {
	        @Override
	        public void onReceive(Context context, Intent intent) {
	           Log.d("MyTag", "You have received a message");
	        }
	    }, new IntentFilter("android.provider.Telephony.SMS_RECEIVED"));

And in your manifest put the permission:

<uses-permission android:name="android.permission.RECEIVE_SMS" >
||||| 0 I Like It! |||||

How to send sms programatticaly in android

Here is a very simple way to send sms messages from your own application.
You can either opt in to open the default sms application and to send desired phone number and text like in this code:

Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( "sms:" + phoneNumber ) );
intent.putExtra( "sms_body", message ); 
startActivity( intent );

If you want to make a sms application you will need to do the following:
Let s say you will have two edit texts. One for the phone number, and one for the message.

class MySMSApplication extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
  editTextPhone = (EditText) findViewById(R.id.phoneNumber);
  editTextMessage = (EditText) findViewById(R.id.message);
  sendBtn  = (Button)findViewById(R.id.send);
 
sendBtn.setonclickListener(new OnClickListener(){
public void Onclick(){
 sendSMS(editTextPhone.getText().toString(), editTextPhone.getText().toString());
}
});
 
}
 
    private void sendSMS(String phoneNumber, String message)
    {        
        PendingIntent pi = PendingIntent.getActivity(this, 0,
            new Intent(this, Object.class), 0);                
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, pi, null);        
    }    
 
}

For using this you will need to add the following permission:

 <uses-permission android:name="android.permission.SEND_SMS">
||||| 0 I Like It! |||||

This is some code that helps you to programatically set the Android device mode to vibrate, silent or normal.

AudioManager am;
am= (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
 
//For Normal mode
am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
 
//For Silent mode
am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
 
//For Vibrate mode
am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
||||| 0 I Like It! |||||

How to detect an waiting call on Android

I will show you in the following lines how to detect an waiting call.
This code is taken from the blog anddev.org.

package org.anddev.android.reactonincomingcall;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.telephony.Phone;
import android.telephony.PhoneStateIntentReceiver;
import android.util.Log;
public class ReactOnIncomingCall extends Activity {
   /** Used to recognize Messages from the
  * myPhoneStateChangedHandler. */
   final int PHONECALLSTATE_RECONGNIZE_ID = 0x539;
   /** Will notify us on changes to the PhoneState*/
   PhoneStateIntentReceiver myPsir = null;
  /** This Handler will react on the messages the
   * we made our PhoneStateIntentReceiver myPsir
   * notify us on. */
  Handler myPhoneStateChangedHandler = new Handler(){
    @Override
    public void handleMessage(Message msg) {
     // Recognize the Message by its what-ID
     if(msg.what == PHONECALLSTATE_RECONGNIZE_ID){
        /* Our PhoneStateIntentReceiver myPsir
       * now contains some recent data, we can grab. */
        Phone.State myState = myPsir.getPhoneState();
        // Put the Info to the logger for debugging
        Log.d("PhoneCallStateNotified", myState.toString());
        if(myState == Phone.State.RINGING){
         // Celebrate =D
        }
     }
    }
  };
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle icicle) {
   // Set some simple layout
    super.onCreate(icicle);
    setContentView(R.layout.main);
    /* Create a new PhoneStateIntentReceiver
   * that will pass messages to the handler h
   * as it receives Intents we make it notify
   * us below*/
    this.myPsir = new PhoneStateIntentReceiver(this,
      myPhoneStateChangedHandler);
    /* As we want to get notified on changes
   * to the Phones-State we tell our
   * PhoneStateIntentReceiver myPsir,
   * that we wan to get notified with the ID
   * (PHONECALLSTATE_RECONGNIZE_ID) we pass to him
   */
    this.myPsir.notifyPhoneCallState(PHONECALLSTATE_RECONGNIZE_ID);
    /* Register the Intent with the system. */
    this.myPsir.registerIntent();
  }
}
||||| 0 I Like It! |||||

Search

Popular

Sponsors