Create an app which can change Ringer mode through SMS

Its been a common problem for all people, specially the young generation to locate their mobile when it’s in Silent ringer mode. This app let you change your mobiles ringer mode through a SMS from some other mobile. Yes, you can trigger to general mode by just sending a HOT WORD from any mobile to your number. This app reads all your message and scans for that HOT WORD when found, performs operation with the AudioManager of your Android Smartphone.

In this post, you will be guided how to create such application, not only that you can also extend its features by adding extra hot words. Basically all you need to know is about android Intent, which will be available soon on dProBuk. Well lets see some ScrrenShots.

Checking The Current Mode Of The SmartPhone.

No Background App Running, When received sms Vibrate, Changed to Vibrate mode

Confrmed That Ringer Mode has changed !

Now Lets have a glance on the Important Sections of the Application:

Code Snippet which detects the current Ringer Mode

public void mode(View view){
int mod = myAudioManager.getRingerMode();
if(mod == AudioManager.RINGER_MODE_NORMAL){
Status.setText("Current Status: Ring");
}
else if(mod == AudioManager.RINGER_MODE_SILENT){
Status.setText("Current Status: Silent");
}
else if(mod == AudioManager.RINGER_MODE_VIBRATE){
Status.setText("Current Status: Vibrate");
}
else{
Status.setText("Unable To Fetch !");
}
}

Now Create a class, ReceiveSMS which extends BroadcastReceiver, in it onReceive method:

Bundle intentExtras = intent.getExtras();
if (intentExtras != null) {
Object[] sms = (Object[]) intentExtras.get(SMS_BUNDLE);
for (int i = 0; i < sms.length; ++i) {
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]);

String smsBody = smsMessage.getMessageBody().toString();
if (smsBody.contains("silent") || smsBody.contains("SILENT"))
{
AudioManager am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}
else if (smsBody.contains("ring") || smsBody.contains("RING"))
{
AudioManager am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
}
else if (smsBody.contains("vibrate") || smsBody.contains("VIBRATE"))
{
AudioManager am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
}
Toast.makeText(context, smsBody, Toast.LENGTH_SHORT).show();
}
}

Now Adding permissions and registering ReceiveSMS as a Receiver in AndroidManifest

<!--add the below after </activity> and before </application> -->
<receiver android:name=".RecieveSMS">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"></action>
</intent-filter>
</receiver>
<!--add the below after </application> -->
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>

Alternatively you can download the whole project here.
Found any bugs, feel free to report them, we will be glad to fix them! 🙂

Related posts

Leave a Comment