The idea behind this code is to find your misplaced phone. This can be achieved by just sending a text message to your phone through another phone. This text message sent should contain the term "RING" so that your can start ringing no matter where it is. All the conditions like when the phone is in silent and in vibration are taken into consideration by adding the if conditions. But this code is only working if the phone is in ringing condition. Does anyone know how to make the code work in silent as well as vibration condition? Reciever class
package com.example.myapp;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.MediaPlayer;
import android.nfc.Tag;
import android.os.Bundle;
import android.provider.Telephony;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.util.Log;
import android.widget.Toast;
public class MyRecevier extends BroadcastReceiver
{ MediaPlayer mp1;
@Override
public void onReceive(Context ctx, Intent intent)
{
Bundle bundle = intent.getExtras();
//mp1 = MediaPlayer.create(ctx, R.raw.jingle);
if(null != bundle)
{
Object[] pdus = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < messages.length; i++)
{
messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
if(messages[i].getDisplayMessageBody().equals("RING"))
{
//Play alarm sound
mp1 = MediaPlayer.create(ctx, R.raw.file);
mp1.setLooping(true); // Set looping
mp1.start();
Thread splashTread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
while(true && (waited < 5000)) {
sleep(100);
if(true) {
waited += 100;
}
}
} catch(InterruptedException e) {
// do nothing
} finally {
// finish();
//startActivity(new Intent("com.talktome.android.MyOne.MyOneActivity"));
stop();
}
}
};
splashTread.start();
}
}
}
}}
this code is in mainActivity.
AudioManager audioManager =
(AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
// Set the volume of played media to maximum.
audioManager.setStreamVolume (
AudioManager.STREAM_MUSIC,
audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC),
this is not working if the phone is in the silent mode. please help me with this.